@@ -3,6 +3,7 @@ import {connectIdSubmodule, storage} from 'modules/connectIdSystem.js';
33import { server } from '../../mocks/xhr' ;
44import { parseQS , parseUrl } from 'src/utils.js' ;
55import { uspDataHandler , gppDataHandler } from 'src/adapterManager.js' ;
6+ import * as refererDetection from '../../../src/refererDetection' ;
67
78const TEST_SERVER_URL = 'http://localhost:9876/' ;
89
@@ -288,6 +289,79 @@ describe('Yahoo ConnectID Submodule', () => {
288289 expect ( setCookieStub . firstCall . args [ 2 ] ) . to . equal ( expiryDelta . toUTCString ( ) ) ;
289290 } ) ;
290291
292+ it ( 'returns an object with the stored ID from cookies and syncs because of expired TTL' , ( ) => {
293+ const last2Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 2 ) ;
294+ const last21Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 21 ) ;
295+ const ttl = 10000 ;
296+ const cookieData = { connectId : 'foo' , he : 'email' , lastSynced : last2Days , puid : '9' , lastUsed : last21Days , ttl} ;
297+ getCookieStub . withArgs ( STORAGE_KEY ) . returns ( JSON . stringify ( cookieData ) ) ;
298+
299+ let result = invokeGetIdAPI ( {
300+ he : HASHED_EMAIL ,
301+ pixelId : PIXEL_ID
302+ } , consentData ) ;
303+
304+ expect ( result ) . to . be . an ( 'object' ) . that . has . all . keys ( 'id' , 'callback' ) ;
305+ expect ( result . id ) . to . deep . equal ( cookieData ) ;
306+ expect ( typeof result . callback ) . to . equal ( 'function' ) ;
307+ } ) ;
308+
309+ it ( 'returns an object with the stored ID from cookies and not syncs because of valid TTL' , ( ) => {
310+ const last2Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 2 ) ;
311+ const last21Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 21 ) ;
312+ const ttl = 60 * 60 * 24 * 1000 * 3 ;
313+ const cookieData = { connectId : 'foo' , he : HASHED_EMAIL , lastSynced : last2Days , puid : '9' , lastUsed : last21Days , ttl} ;
314+ getCookieStub . withArgs ( STORAGE_KEY ) . returns ( JSON . stringify ( cookieData ) ) ;
315+
316+ let result = invokeGetIdAPI ( {
317+ he : HASHED_EMAIL ,
318+ pixelId : PIXEL_ID
319+ } , consentData ) ;
320+
321+ expect ( result ) . to . be . an ( 'object' ) . that . has . all . keys ( 'id' ) ;
322+ cookieData . lastUsed = result . id . lastUsed ;
323+ expect ( result . id ) . to . deep . equal ( cookieData ) ;
324+ } ) ;
325+
326+ it ( 'returns an object with the stored ID from cookies and not syncs because of valid TTL with provided puid' , ( ) => {
327+ const last2Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 2 ) ;
328+ const last21Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 21 ) ;
329+ const ttl = 60 * 60 * 24 * 1000 * 3 ;
330+ const cookieData = { connectId : 'foo' , he : HASHED_EMAIL , lastSynced : last2Days , puid : '9' , lastUsed : last21Days , ttl} ;
331+ getCookieStub . withArgs ( STORAGE_KEY ) . returns ( JSON . stringify ( cookieData ) ) ;
332+
333+ let result = invokeGetIdAPI ( {
334+ he : HASHED_EMAIL ,
335+ pixelId : PIXEL_ID ,
336+ puid : '9'
337+ } , consentData ) ;
338+
339+ expect ( result ) . to . be . an ( 'object' ) . that . has . all . keys ( 'id' ) ;
340+ cookieData . lastUsed = result . id . lastUsed ;
341+ expect ( result . id ) . to . deep . equal ( cookieData ) ;
342+ } ) ;
343+
344+ it ( 'returns an object with the stored ID from cookies and syncs because is O&O traffic' , ( ) => {
345+ const last2Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 2 ) ;
346+ const last21Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 21 ) ;
347+ const ttl = 60 * 60 * 24 * 1000 * 3 ;
348+ const cookieData = { connectId : 'foo' , he : HASHED_EMAIL , lastSynced : last2Days , puid : '9' , lastUsed : last21Days , ttl} ;
349+ getCookieStub . withArgs ( STORAGE_KEY ) . returns ( JSON . stringify ( cookieData ) ) ;
350+ const getRefererInfoStub = sinon . stub ( refererDetection , 'getRefererInfo' ) ;
351+ getRefererInfoStub . returns ( {
352+ ref : 'https://dev.fc.yahoo.com?test'
353+ } ) ;
354+ let result = invokeGetIdAPI ( {
355+ he : HASHED_EMAIL ,
356+ pixelId : PIXEL_ID
357+ } , consentData ) ;
358+ getRefererInfoStub . restore ( ) ;
359+
360+ expect ( result ) . to . be . an ( 'object' ) . that . has . all . keys ( 'id' , 'callback' ) ;
361+ expect ( result . id ) . to . deep . equal ( cookieData ) ;
362+ expect ( typeof result . callback ) . to . equal ( 'function' ) ;
363+ } ) ;
364+
291365 it ( 'Makes an ajax GET request to the production API endpoint with stored puid when id is stale' , ( ) => {
292366 const last15Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 15 ) ;
293367 const last29Days = Date . now ( ) - ( 60 * 60 * 24 * 1000 * 29 ) ;
0 commit comments