Skip to content

Commit

Permalink
fix: implified the exported interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanAludden authored and reubenae committed Oct 30, 2020
1 parent 5ef4a4f commit 6a5bb23
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 50 deletions.
39 changes: 16 additions & 23 deletions src/js/hmrc/mtdFraudPrevention.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,32 @@ export const fraudPreventionHeadersEnum = {
DEVICE_ID: "Gov-Client-Device-ID",
};

const getScreenDetails = () => {
const getScreenData = () => {
const screenDetails = `width=${getScreenWidth()}&height=${getScreenHeight()}&scaling-factor=${getScreenScalingFactor()}&colour-depth=${getScreenColourDepth()}`;
return encodeURI(screenDetails);
};

export const getScreenDetails = () => {
return {
width: getScreenWidth(),
height: getScreenHeight(),
colorDepth: getScreenColourDepth(),
scalingFactor: getScreenScalingFactor(),
};
}

const getWindowSize = () => {
const windowSize = `width=${getWindowWidth()}&height=${getWindowHeight()}`;
return encodeURI(windowSize);
};

export const screenWidth = () => {
return getScreenWidth();
}

export const screenHeight = () => {
return getScreenHeight();
}

export const screenColorDepth = () => {
return getScreenColourDepth();
export const windowDetails = () => {
return {
width: getWindowWidth(),
height: getWindowHeight(),
};
}

export const screenScalingFactor = () => {
return getScreenScalingFactor();
}

export const windowWidth = () => {
return getWindowWidth();
}

export const windowHeight = () => {
return getWindowHeight();
}
/**
* Returns Map of HMRC Fraud prevention headers.
* @returns {object} with two fields headers and errors - The headers are a Map object and the errors are an array. If there are no errors, the array is empty
Expand All @@ -72,7 +65,7 @@ export const getFraudPreventionHeaders = async () => {
{ header: fraudPreventionHeadersEnum.TIMEZONE, callback: getTimezone },
{
header: fraudPreventionHeadersEnum.SCREENS_DETAILS,
callback: getScreenDetails,
callback: getScreenData,
},
{ header: fraudPreventionHeadersEnum.WINDOW_SIZE, callback: getWindowSize },
{
Expand Down
17 changes: 4 additions & 13 deletions src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import {
fraudPreventionHeadersEnum,
getFraudPreventionHeaders,
screenWidth,
screenHeight,
screenColorDepth,
screenScalingFactor,
windowWidth,
windowHeight,
getScreenDetails,
windowDetails,
} from "./hmrc/mtdFraudPrevention";

exports.fraudPreventionHeadersEnum = fraudPreventionHeadersEnum;
exports.getFraudPreventionHeaders = getFraudPreventionHeaders;

exports.screenWidth = screenWidth;
exports.screenHeight = screenHeight;
exports.screenColorDepth = screenColorDepth;
exports.screenScalingFactor = screenScalingFactor;

exports.windowWidth = windowWidth;
exports.windowHeight = windowHeight;
exports.getScreenDetails = getScreenDetails;
exports.windowDetails = windowDetails;
24 changes: 10 additions & 14 deletions tests/unit/hmrc/mtdFraudPrevention.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import getMockBrowserPluginDetails from "../mock/MockData";
import {
getFraudPreventionHeaders,
screenWidth,
screenHeight,
screenColorDepth,
screenScalingFactor,
windowWidth,
windowHeight
import {
getFraudPreventionHeaders,
getScreenDetails,
windowDetails,
} from "../../../src/js";
import {
MockRTCPeerConnection,
Expand Down Expand Up @@ -136,10 +132,10 @@ describe("FraudPreventionHeaders", () => {
devicePixelRatio: 2,
}));
});
it("width", () => expect(screenWidth()).toBe(1019));
it("height", () => expect(screenHeight()).toBe(1021));
it("color depth", () => expect(screenColorDepth()).toBe(17));
it("scaling factor", () => expect(screenScalingFactor()).toBe(2));
it("width", () => expect(getScreenDetails().width).toBe(1019));
it("height", () => expect(getScreenDetails().height).toBe(1021));
it("color depth", () => expect(getScreenDetails().colorDepth).toBe(17));
it("scaling factor", () => expect(getScreenDetails().scalingFactor).toBe(2));
});
describe("window details", () => {
beforeEach(() => {
Expand All @@ -148,8 +144,8 @@ describe("FraudPreventionHeaders", () => {
innerHeight: 1013,
}));
});
it("width", () => expect(windowWidth()).toBe(1009));
it("height", () => expect(windowHeight()).toBe(1013));
it("width", () => expect(windowDetails().width).toBe(1009));
it("height", () => expect(windowDetails().height).toBe(1013));
});

});

0 comments on commit 6a5bb23

Please sign in to comment.