Skip to content

Commit 162f5b9

Browse files
keep disconnect tests
1 parent a49200b commit 162f5b9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/integrationTests/async.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ testCookieAndLocalStorage(() => {
207207
return expect(uid2.getAdvertisingTokenAsync()).rejects.toBeInstanceOf(Error);
208208
});
209209
});
210+
211+
describe('when disconnect() has been called', () => {
212+
test('it should reject promise', () => {
213+
uid2.init({ identity: makeIdentity(), useCookie: useCookie });
214+
uid2.disconnect();
215+
return expect(uid2.getAdvertisingTokenAsync()).rejects.toBeInstanceOf(Error);
216+
});
217+
});
210218
});
211219

212220
describe('when getAdvertisingTokenAsync is called before refresh on init completes', () => {
@@ -216,6 +224,13 @@ testCookieAndLocalStorage(() => {
216224
beforeEach(() => {
217225
uid2.init({ identity: originalIdentity, useCookie: useCookie });
218226
});
227+
228+
describe('when promise obtained after disconnect', () => {
229+
test('it should reject promise', () => {
230+
uid2.disconnect();
231+
return expect(uid2.getAdvertisingTokenAsync()).rejects.toBeInstanceOf(Error);
232+
});
233+
});
219234
});
220235

221236
describe('when window.__uid2.init is called on SdkLoaded from a callback', () => {

src/integrationTests/basic.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,47 @@ testCookieAndLocalStorage(() => {
954954
expect(xhrMock.abort).toHaveBeenCalledTimes(1);
955955
});
956956
});
957+
958+
describe('disconnect()', () => {
959+
test('should clear cookie', () => {
960+
setUid2(makeIdentityV2(), useCookie);
961+
uid2.disconnect();
962+
expect(getUid2(useCookie)).toBeNull();
963+
});
964+
test('should abort refresh timer', () => {
965+
uid2.init({
966+
callback: callback,
967+
identity: makeIdentityV2(),
968+
useCookie: useCookie,
969+
});
970+
expect(setTimeout).toHaveBeenCalledTimes(1);
971+
expect(clearTimeout).not.toHaveBeenCalled();
972+
uid2.disconnect();
973+
expect(setTimeout).toHaveBeenCalledTimes(1);
974+
expect(clearTimeout).toHaveBeenCalledTimes(1);
975+
});
976+
test('should abort refresh token request', () => {
977+
uid2.init({
978+
callback: callback,
979+
identity: makeIdentityV2({ refresh_from: Date.now() - 100000 }),
980+
useCookie: useCookie,
981+
});
982+
expect(xhrMock.send).toHaveBeenCalledTimes(1);
983+
expect(xhrMock.abort).not.toHaveBeenCalled();
984+
uid2.disconnect();
985+
expect(xhrMock.send).toHaveBeenCalledTimes(1);
986+
expect(xhrMock.abort).toHaveBeenCalledTimes(1);
987+
});
988+
test('should switch to unavailable state', () => {
989+
uid2.init({
990+
callback: callback,
991+
identity: makeIdentityV2(),
992+
useCookie: useCookie,
993+
});
994+
uid2.disconnect();
995+
(expect(uid2) as any).toBeInUnavailableState();
996+
});
997+
});
957998
});
958999

9591000
describe('Include sdk script multiple times', () => {

0 commit comments

Comments
 (0)