From a47403a6a0fe94637e6def0cd4ad1e7cd93dcb58 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Fri, 9 Sep 2022 10:15:07 -0600 Subject: [PATCH] Adriver ID system: fix spurious test failure (#8978) Fix Adriver ID system test failures (https://app.circleci.com/pipelines/github/prebid/Prebid.js/13137/workflows/5e686ed9-e57e-47b3-9c4e-8beea10be321/jobs/24200). This was already done in #8489, but #8768 undid it. --- test/spec/modules/adriverIdSystem_spec.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/spec/modules/adriverIdSystem_spec.js b/test/spec/modules/adriverIdSystem_spec.js index bc7d3f191d2..abc831b67f0 100644 --- a/test/spec/modules/adriverIdSystem_spec.js +++ b/test/spec/modules/adriverIdSystem_spec.js @@ -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;