Skip to content

Commit

Permalink
keep disconnect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysmithTTD committed Dec 12, 2024
1 parent a49200b commit 162f5b9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/integrationTests/async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down
41 changes: 41 additions & 0 deletions src/integrationTests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 162f5b9

Please sign in to comment.