Skip to content

Commit

Permalink
Merge pull request #185 from digi-trust/candidate
Browse files Browse the repository at this point in the history
Candidate
  • Loading branch information
SupahNickie committed Oct 25, 2018
2 parents 27dae86 + 25a1743 commit d6565e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
13 changes: 1 addition & 12 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@
"da",
"et",
"fi",
"fr",
"fr-be",
"fr-fr",
"fr-lu",
"fr-mc",
"fr-ch",
"de",
"de-at",
"de-de",
"de-li",
Expand All @@ -74,44 +72,35 @@
"nl",
"nl-be",
"pl",
"pt",
"rm",
"ro",
"ro-mo",
"sk",
"sl",
"es",
"es-es",
"cy",
"sv",
"sv-fi",
"sv-sv",
"en-gb",
"en-ie",
"mo",
"ru-mo",
"eu",
"ca",
"co",
"fo",
"fy",
"fur",
"gd",
"gl",
"is",
"la",
"no",
"nb",
"nn",
"oc",
"sc",
"sb",
"hsb",
"vo",
"wa",
"ar",
"ast",
"br",
"eo"
"br"
]
}
1 change: 1 addition & 0 deletions src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaultConfig = {
someConsentGiven: 30,
noConsentGiven: 30,
},
useGeolocationOnly: false,
geoIPVendor: 'https://cmp.digitru.st/1/geoip.json',
digitrustRedirectUrl: metadata.digitrustRedirectLocation,
testingMode: 'normal',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//jshint esversion: 6
import 'whatwg-fetch';
import Promise from 'promise-polyfill';
import config from './config';

export {
checkReprompt,
Expand Down Expand Up @@ -91,6 +92,7 @@ function checkIfGDPRApplies(geoVendor, callback) {
}

function checkIfLanguageLocaleApplies(languages) {
if (config.useGeolocationOnly) return false;
for (let i = 0; i < languages.length; i++) {
if (EU_LANGUAGE_CODES.has(languages[i].toLowerCase())) {
return true;
Expand Down
14 changes: 12 additions & 2 deletions src/lib/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('utils', () => {
});

describe('checkIfGDPRApplies', () => {
const returnValues = [ [ 'en-GB' ], ['fr-BE'], 'lt', 'en-US' ];
const returnValues = [ [ 'en-GB' ], ['de'], ['fr-BE'], 'lt', 'en-US' ];

beforeEach(() => {
window.fetch = jest.fn().mockImplementation(() => Promise.resolve({ headers: new Map([]) }));
Expand All @@ -161,6 +161,16 @@ describe('utils', () => {
});
});

it('skips the language check if the config is set to use only geoIP', (done) => {
config.useGeolocationOnly = true;
checkIfGDPRApplies('url', (res) => {
expect(res).eq(false);
expect(window.fetch.mock.calls.length).to.equal(1);
config.useGeolocationOnly = false;
done();
});
});

it('handles Internet Explorer navigator implementation', (done) => {
checkIfGDPRApplies('url', (res) => {
expect(res.applies).eq(true);
Expand All @@ -171,7 +181,7 @@ describe('utils', () => {
});
});

it('fallbacks to ip resolution', (done) => {
it('falls back to IP resolution', (done) => {
checkIfGDPRApplies('url', (res) => {

expect(res).eq(false);
Expand Down

0 comments on commit d6565e9

Please sign in to comment.