From 162f5b9210470d24c8adffc1af08ed43094d6145 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Thu, 12 Dec 2024 14:09:12 -0700 Subject: [PATCH] keep disconnect tests --- src/integrationTests/async.spec.ts | 15 +++++++++++ src/integrationTests/basic.test.ts | 41 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/integrationTests/async.spec.ts b/src/integrationTests/async.spec.ts index 5855f7c..9b896b7 100644 --- a/src/integrationTests/async.spec.ts +++ b/src/integrationTests/async.spec.ts @@ -207,6 +207,14 @@ testCookieAndLocalStorage(() => { return expect(uid2.getAdvertisingTokenAsync()).rejects.toBeInstanceOf(Error); }); }); + + describe('when disconnect() has been called', () => { + test('it should reject promise', () => { + uid2.init({ identity: makeIdentity(), useCookie: useCookie }); + uid2.disconnect(); + return expect(uid2.getAdvertisingTokenAsync()).rejects.toBeInstanceOf(Error); + }); + }); }); describe('when getAdvertisingTokenAsync is called before refresh on init completes', () => { @@ -216,6 +224,13 @@ testCookieAndLocalStorage(() => { beforeEach(() => { uid2.init({ identity: originalIdentity, useCookie: useCookie }); }); + + describe('when promise obtained after disconnect', () => { + test('it should reject promise', () => { + uid2.disconnect(); + return expect(uid2.getAdvertisingTokenAsync()).rejects.toBeInstanceOf(Error); + }); + }); }); describe('when window.__uid2.init is called on SdkLoaded from a callback', () => { diff --git a/src/integrationTests/basic.test.ts b/src/integrationTests/basic.test.ts index db32948..9a303aa 100644 --- a/src/integrationTests/basic.test.ts +++ b/src/integrationTests/basic.test.ts @@ -954,6 +954,47 @@ testCookieAndLocalStorage(() => { expect(xhrMock.abort).toHaveBeenCalledTimes(1); }); }); + + describe('disconnect()', () => { + test('should clear cookie', () => { + setUid2(makeIdentityV2(), useCookie); + uid2.disconnect(); + expect(getUid2(useCookie)).toBeNull(); + }); + test('should abort refresh timer', () => { + uid2.init({ + callback: callback, + identity: makeIdentityV2(), + useCookie: useCookie, + }); + expect(setTimeout).toHaveBeenCalledTimes(1); + expect(clearTimeout).not.toHaveBeenCalled(); + uid2.disconnect(); + expect(setTimeout).toHaveBeenCalledTimes(1); + expect(clearTimeout).toHaveBeenCalledTimes(1); + }); + test('should abort refresh token request', () => { + uid2.init({ + callback: callback, + identity: makeIdentityV2({ refresh_from: Date.now() - 100000 }), + useCookie: useCookie, + }); + expect(xhrMock.send).toHaveBeenCalledTimes(1); + expect(xhrMock.abort).not.toHaveBeenCalled(); + uid2.disconnect(); + expect(xhrMock.send).toHaveBeenCalledTimes(1); + expect(xhrMock.abort).toHaveBeenCalledTimes(1); + }); + test('should switch to unavailable state', () => { + uid2.init({ + callback: callback, + identity: makeIdentityV2(), + useCookie: useCookie, + }); + uid2.disconnect(); + (expect(uid2) as any).toBeInUnavailableState(); + }); + }); }); describe('Include sdk script multiple times', () => {