Skip to content

Commit

Permalink
Adriver ID system: fix spurious test failure (#8978)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Sep 9, 2022
1 parent b04c132 commit a47403a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions test/spec/modules/adriverIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ describe('AdriverIdSystem', function () {
let request = server.requests[0];
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ adrcid: response.adrcid }));

let now = new Date();
now.setTime(now.getTime() + 86400 * 1825 * 1000);
let expectedExpiration = new Date();
expectedExpiration.setTime(expectedExpiration.getTime() + 86400 * 1825 * 1000);
const minimalDate = new Date(0).toString();

function dateStringFor(date, maxDeltaMs = 2000) {
return sinon.match((val) => Math.abs(date.getTime() - new Date(val).getTime()) <= maxDeltaMs)
}

if (response.adrcid) {
expect(setCookieStub.calledWith('adrcid', response.adrcid, now.toUTCString())).to.be.true;
expect(setCookieStub.calledWith('adrcid', response.adrcid, dateStringFor(expectedExpiration))).to.be.true;
expect(setLocalStorageStub.calledWith('adrcid', response.adrcid)).to.be.true;
} else {
expect(setCookieStub.calledWith('adrcid', '', minimalDate)).to.be.false;
Expand Down

0 comments on commit a47403a

Please sign in to comment.