Skip to content

Commit

Permalink
delete unnecessary tests from AMX ID adapter + fix formatting, possib…
Browse files Browse the repository at this point in the history
…le flakey test
  • Loading branch information
nickjacob committed Apr 4, 2023
1 parent 77f38f8 commit f1a55bc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 56 deletions.
2 changes: 1 addition & 1 deletion modules/amxIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {submodule} from '../src/hook.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {deepAccess, logError} from '../src/utils.js';
import {getStorageManager} from '../src/storageManager.js';
import { domainOverrideToRootDomain } from '../libraries/domainOverrideToRootDomain/index.js';
import {domainOverrideToRootDomain} from '../libraries/domainOverrideToRootDomain/index.js';

const NAME = 'amxId';
const GVL_ID = 737;
Expand Down
6 changes: 3 additions & 3 deletions modules/sharedIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* @requires module:modules/userId
*/

import { parseUrl, buildUrl, triggerPixel, logInfo, hasDeviceAccess, generateUUID } from '../src/utils.js';
import {parseUrl, buildUrl, triggerPixel, logInfo, hasDeviceAccess, generateUUID} from '../src/utils.js';
import {submodule} from '../src/hook.js';
import { coppaDataHandler } from '../src/adapterManager.js';
import {coppaDataHandler} from '../src/adapterManager.js';
import {getStorageManager} from '../src/storageManager.js';
import {VENDORLESS_GVLID} from '../src/consentHandler.js';
import { domainOverrideToRootDomain } from '../libraries/domainOverrideToRootDomain/index.js';
import {domainOverrideToRootDomain} from '../libraries/domainOverrideToRootDomain/index.js';

export const storage = getStorageManager({moduleName: 'pubCommonId', gvlid: VENDORLESS_GVLID});
const COOKIE = 'cookie';
Expand Down
3 changes: 3 additions & 0 deletions test/spec/libraries/domainOverrideToRootDomain/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ describe('domainOverride', () => {
domain = 'greatpublisher.com'
rejectCookiesFor = 'greatpublisher.com'

// stub Date.now() to return a constant value
sandbox.stub(Date, 'now').returns(1234567890)

const randomName = `adapterV${(Math.random() * 1e8).toString(16)}`
const localDomainOverride = domainOverrideToRootDomain(storage, randomName)

Expand Down
52 changes: 0 additions & 52 deletions test/spec/modules/amxIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,58 +38,6 @@ describe('decode', () => {
});
});

describe('domainOverride', () => {
let sandbox, domain, cookies, rejectCookiesFor;
beforeEach(() => {
sandbox = sinon.createSandbox();
sandbox.stub(document, 'domain').get(() => domain);
cookies = {};
sandbox.stub(storage, 'getCookie').callsFake((key) => cookies[key]);
rejectCookiesFor = null;
sandbox.stub(storage, 'setCookie').callsFake((key, value, expires, sameSite, domain) => {
if (domain !== rejectCookiesFor) {
if (expires != null) {
expires = new Date(expires);
}
if (expires == null || expires > Date.now()) {
cookies[key] = value;
} else {
delete cookies[key];
}
}
});
});

afterEach(() => sandbox.restore())

it('will return the root domain when given a subdomain', () => {
const test_domains = [
'deeply.nested.subdomain.for.greatpublisher.com',
'greatpublisher.com',
'subdomain.greatpublisher.com',
'a-subdomain.greatpublisher.com',
];

test_domains.forEach((testDomain) => {
domain = testDomain
rejectCookiesFor = 'com'
expect(amxIdSubmodule.domainOverride()).to.equal('greatpublisher.com');
});
});

it(`If we can't set cookies on the root domain, we'll return the subdomain`, () => {
domain = 'subdomain.greatpublisher.com'
rejectCookiesFor = 'greatpublisher.com'
expect(amxIdSubmodule.domainOverride()).to.equal('subdomain.greatpublisher.com');
});

it('Will return undefined if we can\'t set cookies on the root domain or the subdomain', () => {
domain = 'subdomain.greatpublisher.com'
rejectCookiesFor = 'subdomain.greatpublisher.com'
expect(amxIdSubmodule.domainOverride()).to.equal(undefined);
});
});

describe('validateConfig', () => {
let logErrorSpy;

Expand Down

0 comments on commit f1a55bc

Please sign in to comment.