mirror of
https://github.com/gosticks/web.git
synced 2026-10-06 22:57:01 +00:00
Add tests for paramsToString and timeRangeToParams
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
@@ -11,11 +11,15 @@
|
||||
import HttpClient, {
|
||||
checkForErrors,
|
||||
checkIfLoggedOut,
|
||||
convertJSON
|
||||
convertJSON,
|
||||
paramsToString,
|
||||
timeRangeToParams
|
||||
} from "../http";
|
||||
import api from "../api";
|
||||
import { Config } from "../../config";
|
||||
import { CanceledError } from "../CancelablePromise";
|
||||
import { TimeRange } from "../../components/common/context/TimeRangeContext";
|
||||
import moment from "moment";
|
||||
|
||||
const originalReload = window.location.reload;
|
||||
|
||||
@@ -142,3 +146,29 @@ describe("checkForErrors", () => {
|
||||
await expect(checkForErrors(data)).rejects.toEqual(data.error);
|
||||
});
|
||||
});
|
||||
|
||||
describe("paramsToString", () => {
|
||||
it("converts an object into parameters", () => {
|
||||
const object = {
|
||||
test1: "1",
|
||||
test2: "two",
|
||||
test3: 3
|
||||
};
|
||||
const expectedParams = "test1=1&test2=two&test3=3";
|
||||
|
||||
expect(paramsToString(object)).toEqual(expectedParams);
|
||||
});
|
||||
});
|
||||
|
||||
describe("timeRangeToParams", () => {
|
||||
it("converts a time range into parameters", () => {
|
||||
const range: TimeRange = {
|
||||
name: "Test time range",
|
||||
from: moment("2019-04-12T01:03:17+00:00"),
|
||||
until: moment("2019-04-13T01:03:17+00:00")
|
||||
};
|
||||
const expectedParams = "from=1555030997&until=1555117397";
|
||||
|
||||
expect(timeRangeToParams(range)).toEqual(expectedParams);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user