Skip to content

Commit

Permalink
Id5 id system: attempt to fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Aug 18, 2022
1 parent 4e9ccd5 commit d80b6ca
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions test/spec/modules/id5IdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as utils from 'src/utils.js';
import 'src/prebid.js';
import {hook} from '../../../src/hook.js';
import {mockGdprConsent} from '../../helpers/consentData.js';
import {GreedyPromise} from '../../../src/utils/promise.js';

let expect = require('chai').expect;

Expand Down Expand Up @@ -436,28 +437,26 @@ describe('ID5 ID System', function() {
setSubmoduleRegistry([id5IdSubmodule]);
config.setConfig(id5Config);

return new Promise((resolve) => {
requestBidsHook(() => {
resolve()
}, {adUnits});
}).then(() => {
expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(2);
expect(server.requests).to.be.empty;
events.emit(CONSTANTS.EVENTS.AUCTION_END, {});
return new Promise((resolve) => setTimeout(resolve))
}).then(() => {
let request = server.requests[0];
let requestBody = JSON.parse(request.requestBody);
expect(request.url).to.contain(ID5_ENDPOINT);
expect(requestBody.s).to.eq(ID5_STORED_SIGNATURE);
expect(requestBody.nbPage).to.eq(2);

const responseHeader = { 'Content-Type': 'application/json' };
request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));

expect(decodeURIComponent(getFromLocalStorage(ID5_STORAGE_NAME))).to.be.eq(JSON.stringify(ID5_JSON_RESPONSE));
expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(0);
})
let hookRan = false;

requestBidsHook(() => {
hookRan = true;
}, {});
expect(hookRan).to.be.true;
expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(2);
expect(server.requests).to.be.empty;
events.emit(CONSTANTS.EVENTS.AUCTION_END, {});
let request = server.requests[0];
let requestBody = JSON.parse(request.requestBody);
expect(request.url).to.contain(ID5_ENDPOINT);
expect(requestBody.s).to.eq(ID5_STORED_SIGNATURE);
expect(requestBody.nbPage).to.eq(2);

const responseHeader = { 'Content-Type': 'application/json' };
request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE));

expect(decodeURIComponent(getFromLocalStorage(ID5_STORAGE_NAME))).to.be.eq(JSON.stringify(ID5_JSON_RESPONSE));
expect(getNbFromCache(ID5_TEST_PARTNER_ID)).to.be.eq(0);
});
});

Expand Down

0 comments on commit d80b6ca

Please sign in to comment.