fix: tests failed due to timezone issues
This commit is contained in:
@@ -44,3 +44,5 @@ GOOGLE_DYNAMIC_MAP_ID="test"
|
|||||||
HIDE_FOR_NEXT_RELEASE="true"
|
HIDE_FOR_NEXT_RELEASE="true"
|
||||||
SALESFORCE_PREFERENCE_BASE_URL="test"
|
SALESFORCE_PREFERENCE_BASE_URL="test"
|
||||||
USE_NEW_REWARDS_ENDPOINT="true"
|
USE_NEW_REWARDS_ENDPOINT="true"
|
||||||
|
|
||||||
|
TZ=UTC
|
||||||
|
|||||||
@@ -3,11 +3,22 @@ import { beforeAll, describe, expect, it } from "@jest/globals"
|
|||||||
import { getValidFromDate, getValidToDate } from "./getValidDates"
|
import { getValidFromDate, getValidToDate } from "./getValidDates"
|
||||||
|
|
||||||
const NOW = new Date("2020-10-01T00:00:00Z")
|
const NOW = new Date("2020-10-01T00:00:00Z")
|
||||||
|
let originalTz: string | undefined
|
||||||
|
|
||||||
describe("getValidFromDate", () => {
|
describe("getValidFromDate", () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
jest.useFakeTimers({ now: NOW })
|
jest.useFakeTimers({ now: NOW })
|
||||||
|
originalTz = process.env.TZ
|
||||||
|
console.log("originalTz", originalTz)
|
||||||
|
process.env.TZ = "UTC"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
process.env.TZ = originalTz
|
||||||
|
jest.useRealTimers()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("getValidFromDate", () => {
|
||||||
it("returns today when empty string is provided", () => {
|
it("returns today when empty string is provided", () => {
|
||||||
const actual = getValidFromDate("")
|
const actual = getValidFromDate("")
|
||||||
expect(actual.toISOString()).toBe("2020-10-01T00:00:00.000Z")
|
expect(actual.toISOString()).toBe("2020-10-01T00:00:00.000Z")
|
||||||
@@ -20,15 +31,11 @@ describe("getValidFromDate", () => {
|
|||||||
|
|
||||||
it("returns given date in utc", () => {
|
it("returns given date in utc", () => {
|
||||||
const actual = getValidFromDate("2024-01-01")
|
const actual = getValidFromDate("2024-01-01")
|
||||||
expect(actual.toISOString()).toBe("2023-12-31T23:00:00.000Z")
|
expect(actual.toISOString()).toBe("2024-01-01T00:00:00.000Z")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("getValidToDate", () => {
|
describe("getValidToDate", () => {
|
||||||
beforeAll(() => {
|
|
||||||
jest.useFakeTimers({ now: NOW })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns day after fromDate when empty string is provided", () => {
|
it("returns day after fromDate when empty string is provided", () => {
|
||||||
const actual = getValidToDate("", NOW)
|
const actual = getValidToDate("", NOW)
|
||||||
expect(actual.toISOString()).toBe("2020-10-02T00:00:00.000Z")
|
expect(actual.toISOString()).toBe("2020-10-02T00:00:00.000Z")
|
||||||
@@ -41,7 +48,7 @@ describe("getValidToDate", () => {
|
|||||||
|
|
||||||
it("returns given date in utc", () => {
|
it("returns given date in utc", () => {
|
||||||
const actual = getValidToDate("2024-01-01", NOW)
|
const actual = getValidToDate("2024-01-01", NOW)
|
||||||
expect(actual.toISOString()).toBe("2023-12-31T23:00:00.000Z")
|
expect(actual.toISOString()).toBe("2024-01-01T00:00:00.000Z")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("fallsback to day after fromDate when given date is before fromDate", () => {
|
it("fallsback to day after fromDate when given date is before fromDate", () => {
|
||||||
@@ -49,3 +56,4 @@ describe("getValidToDate", () => {
|
|||||||
expect(actual.toISOString()).toBe("2020-10-02T00:00:00.000Z")
|
expect(actual.toISOString()).toBe("2020-10-02T00:00:00.000Z")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user