Skip to content

Commit

Permalink
feat(hmrc #141): adding getGovClientBrowserDoNotTrackHeader function (#…
Browse files Browse the repository at this point in the history
…155)

* feat(hmrc): adding getGovClientBrowserDoNotTrackHeader function

* removed async/await and updated some linting fixes

* fix: removed extra lines

* fix: fixed test cases

* fix: updated import

* fix: updated test file

* fix: updated test file

* fix: updated test file

* fix: updated the test file

Co-authored-by: Simran Raj <[email protected]>
  • Loading branch information
SIMRAN88 and Simran Raj authored Oct 21, 2021
1 parent 28c41d6 commit 6942003
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const timezoneHeader = fraudHeaders.get(fraudPreventionHeadersEnum.TIMEZONE);
```

If you want only a specific header value, then you can use below functions that are available to get individual header values:

* To get Gov-Client-Browser_plugins HMRC Fraud prevention header:
```js
import getGovClientBrowserPluginsHeader from 'user-data-for-fraud-prevention';
Expand All @@ -39,4 +40,10 @@ const { headerValue, error } = getGovClientBrowserJSUserAgentHeader();
```js
import getGovClientDeviceID from 'user-data-for-fraud-prevention';
const {headerValue, error} = getGovClientDeviceID();
```
```

* To get Gov-Client-Browser-Do-Not-Track HMRC Fraud prevention header:
```js
import getGovClientBrowserDoNotTrackHeader from 'user-data-for-fraud-prevention';
const {headerValue, error} = getGovClientBrowserDoNotTrackHeader();
```
11 changes: 11 additions & 0 deletions src/js/hmrc/mtdFraudPrevention.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,14 @@ export const getGovClientBrowserPluginsHeader = () => {
return {error};
}
}

/**
* Returns the value for Gov-Client-Browser-Do-Not-Track HMRC Fraud prevention header.
*/
export const getGovClientBrowserDoNotTrackHeader = () => {
try {
return {headerValue: getBrowserDoNotTrackStatus()};
} catch (error) {
return {error};
}
}
3 changes: 3 additions & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
windowDetails,
getGovClientBrowserJSUserAgentHeader,
getGovClientBrowserPluginsHeader,
getGovClientBrowserDoNotTrackHeader,
getGovClientDeviceID
} from "./hmrc/mtdFraudPrevention";

exports.fraudPreventionHeadersEnum = fraudPreventionHeadersEnum;
exports.getFraudPreventionHeaders = getFraudPreventionHeaders;
exports.getGovClientBrowserPluginsHeader = getGovClientBrowserPluginsHeader;
exports.getGovClientBrowserDoNotTrackHeader = getGovClientBrowserDoNotTrackHeader;

exports.getGovClientDeviceID = getGovClientDeviceID;
exports.getScreenDetails = getScreenDetails;
exports.getGovClientBrowserJSUserAgentHeader = getGovClientBrowserJSUserAgentHeader;
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/hmrc/mtdFraudPrevention.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { resetDeviceIpString, resetDeviceIpTimeStamp } from "../../../src/js/com
import uuid from "uuid";
import {getGovClientBrowserPluginsHeader} from "../../../src/js/hmrc/mtdFraudPrevention";
import {getGovClientDeviceID} from "../../../src/js/hmrc/mtdFraudPrevention";
import {getGovClientBrowserDoNotTrackHeader} from "../../../src/js/hmrc/mtdFraudPrevention";

describe("FraudPreventionHeaders", () => {
resetDeviceIpString();
Expand Down Expand Up @@ -261,3 +262,20 @@ describe("getGovClientDeviceID", () => {
deviceIDMock.mockRestore();
});
});

describe("getGovClientBrowserDoNotTrackHeader", () => {
it("returns correct headerValue when there is no error", () => {
const browserDoNotTrackStatusMock = jest.spyOn(browserInfoHelper, "getBrowserDoNotTrackStatus").mockImplementation(() => "true");
const {headerValue, error} = getGovClientBrowserDoNotTrackHeader();
expect(headerValue).toBe("true");
expect(error).toBe(undefined);
browserDoNotTrackStatusMock.mockRestore();
})
it("returns error when there is an error", () => {
const browserDoNotTrackStatusMock = jest.spyOn(browserInfoHelper, "getBrowserDoNotTrackStatus").mockImplementation(() => { throw Error("Something went wrong.")});
const {headerValue, error} = getGovClientBrowserDoNotTrackHeader();
expect(headerValue).toBe(undefined);
expect(error).toEqual(Error("Something went wrong."));
browserDoNotTrackStatusMock.mockRestore();
});
});

0 comments on commit 6942003

Please sign in to comment.