diff --git a/package.json b/package.json index 8b0bace..1db7611 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,6 @@ }, "dependencies": { "@babel/preset-env": "^7.10.4", - "moment": "^2.24.0", "uuid": "^3.3.3" }, "devDependencies": { diff --git a/src/js/common/browserInfoHelper.js b/src/js/common/browserInfoHelper.js index b513160..da57e14 100644 --- a/src/js/common/browserInfoHelper.js +++ b/src/js/common/browserInfoHelper.js @@ -1,4 +1,3 @@ -import moment from "moment"; import globalsUtil from "./globalsUtil"; const ICE_CANDIDATE_IP_INDEX = 4; @@ -68,7 +67,18 @@ const validateAndGetScreenDetail = (value) => { } }; -export const getTimezone = () => `UTC${moment().format("Z")}`; +const getFormattedOffset = () => { + // Date().toString() is in format like "Wed Sep 30 2020 23:11:02 GMT+0100 (British Summer Time)" + // To format the offset, we split on "GMT" + // and then pick the relevant characters based on their position and reformat with a ":" + const offset = new Date().toString().split("GMT")[1]; + const hourOffset = `${offset[0]}${offset[1]}${offset[2]}`; + const minuteOffset = `${offset[3]}${offset[4]}`; + const formattedUTC = `${hourOffset}:${minuteOffset}`; + return formattedUTC; +} + +export const getTimezone = () => `UTC${getFormattedOffset()}`; export const getScreenWidth = () => validateAndGetScreenDetail(globalsUtil.getScreen().width); export const getScreenHeight = () => diff --git a/tests/unit/common/browserInfoHelper.test.js b/tests/unit/common/browserInfoHelper.test.js index 0187f8a..94ed56b 100644 --- a/tests/unit/common/browserInfoHelper.test.js +++ b/tests/unit/common/browserInfoHelper.test.js @@ -20,7 +20,6 @@ import { getTimezone, resetDeviceIpString, } from "../../../src/js/common/browserInfoHelper"; -import moment from "moment"; describe("BrowserInfoHelper", () => { afterEach(() => { @@ -198,7 +197,7 @@ describe("BrowserInfoHelper", () => { it("RTCPeerConnection valid", async () => { webRtcConnectionStub.mockReturnValue(MockRTCPeerConnection); expect(await getDeviceLocalIPAsString()).toEqual("127.0.0.1"); - //Calling the function to return an already calculated deviceIpString + // Calling the function to return an already calculated deviceIpString expect(await getDeviceLocalIPAsString()).toEqual("127.0.0.1"); }); @@ -227,7 +226,15 @@ describe("BrowserInfoHelper", () => { height: 1021, colorDepth: 17, }); - expect(getTimezone()).toEqual(`UTC${moment().format("Z")}`); + global.Date = class DateMock { + constructor() { + } + toString() { + return "Tue May 14 2019 12:01:58 GMT+0100 (British Summer Time)"; + } + }; + + expect(getTimezone()).toEqual(`UTC+01:00`); expect(getScreenWidth()).toEqual(1019); expect(getScreenHeight()).toEqual(1021); expect(getScreenScalingFactor()).toEqual(2); diff --git a/tests/unit/hmrc/mtdFraudPrevention.test.js b/tests/unit/hmrc/mtdFraudPrevention.test.js index e88f432..85fff21 100644 --- a/tests/unit/hmrc/mtdFraudPrevention.test.js +++ b/tests/unit/hmrc/mtdFraudPrevention.test.js @@ -8,7 +8,6 @@ import { import globalsUtil from "../../../src/js/common/globalsUtil"; import * as browserInfoHelper from "../../../src/js/common/browserInfoHelper"; import { resetDeviceIpString } from "../../../src/js/common/browserInfoHelper"; -import moment from "moment"; describe("FraudPreventionHeaders", () => { resetDeviceIpString(); @@ -36,13 +35,18 @@ describe("FraudPreventionHeaders", () => { height: 1021, colorDepth: 17, }); + global.Date = class DateMock { + constructor() { + } + toString() { + return "Tue May 14 2019 12:01:58 GMT+0100 (British Summer Time)"; + } + }; const {headers, errors} = await getFraudPreventionHeaders(); expect(headers.size).toBe(6); expect(errors.length).toBe(0); - expect(headers.get("Gov-Client-Timezone")).toBe( - `UTC${moment().format("Z")}` - ); + expect(headers.get("Gov-Client-Timezone")).toBe(`UTC+01:00`); expect(headers.get("Gov-Client-Screens")).toBe( "width=1019&height=1021&scaling-factor=2&colour-depth=17" ); @@ -77,9 +81,7 @@ describe("FraudPreventionHeaders", () => { const {headers, errors} = await getFraudPreventionHeaders(); expect(headers.size).toBe(5); expect(errors.length).toBe(1); - expect(headers.get("Gov-Client-Timezone")).toBe( - `UTC${moment().format("Z")}` - ); + expect(headers.get("Gov-Client-Timezone")).toBe(`UTC+01:00`); expect(headers.get("Gov-Client-Screens")).toBe( "width=1019&height=1021&scaling-factor=2&colour-depth=17" ); diff --git a/yarn.lock b/yarn.lock index bfdd94b..5eeb415 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1990,11 +1990,6 @@ arr-union@^3.1.0: resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4" integrity sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ= -array-from@^2.1.1: - version "2.1.1" - resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/array-from/-/array-from-2.1.1.tgz#cfe9d8c26628b9dc5aecc62a9f5d8f1f352c1195" - integrity sha1-z+nYwmYoudxa7MYqn12PHzUsEZU= - array-ify@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-ify/-/array-ify-1.0.0.tgz#9e528762b4a9066ad163a6962a364418e9626ece" @@ -5592,11 +5587,6 @@ mkdirp@^0.5.1, mkdirp@^0.5.3: dependencies: minimist "^1.2.5" -moment@^2.24.0: - version "2.26.0" - resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/moment/-/moment-2.26.0.tgz#5e1f82c6bafca6e83e808b30c8705eed0dcbd39a" - integrity sha1-Xh+Cxrr8pug+gIswyHBe7Q3L05o= - move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.intuit.com:443/artifactory/api/npm/npm-intuit/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"