Skip to content

Commit

Permalink
remove abort tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysmithTTD committed Dec 12, 2024
1 parent 162f5b9 commit 73a300c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
45 changes: 0 additions & 45 deletions src/integrationTests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -910,51 +910,6 @@ testCookieAndLocalStorage(() => {
});
});

describe('abort()', () => {
test('should not clear cookie', () => {
const identity = makeIdentityV2();
setUid2(identity, useCookie);
uid2.abort();
expect(getUid2(useCookie).advertising_token).toBe(identity.advertising_token);
});
test('should abort refresh timer', () => {
uid2.init({
callback: callback,
identity: makeIdentityV2(),
useCookie: useCookie,
});
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(clearTimeout).not.toHaveBeenCalled();
uid2.abort();
expect(setTimeout).toHaveBeenCalledTimes(1);
expect(clearTimeout).toHaveBeenCalledTimes(1);
});
test('should not abort refresh timer if not timer is set', () => {
uid2.init({
callback: callback,
identity: makeIdentityV2({ refresh_from: Date.now() - 100000 }),
useCookie: useCookie,
});
expect(setTimeout).not.toHaveBeenCalled();
expect(clearTimeout).not.toHaveBeenCalled();
uid2.abort();
expect(setTimeout).not.toHaveBeenCalled();
expect(clearTimeout).not.toHaveBeenCalled();
});
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.abort();
expect(xhrMock.send).toHaveBeenCalledTimes(1);
expect(xhrMock.abort).toHaveBeenCalledTimes(1);
});
});

describe('disconnect()', () => {
test('should clear cookie', () => {
setUid2(makeIdentityV2(), useCookie);
Expand Down
12 changes: 8 additions & 4 deletions src/sdkBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ export abstract class SdkBase {
}

public disconnect() {
this.abort(`${this._product.name} SDK disconnected.`);
this._tokenPromiseHandler.rejectAllPromises(new Error(`${this._product.name} SDK aborted.`));
if (this._refreshTimerId) {
clearTimeout(this._refreshTimerId);
this._refreshTimerId = null;
}
if (this._apiClient) this._apiClient.abortActiveRequests();
// Note: This silently fails to clear the cookie if init hasn't been called and a cookieDomain is used!
if (this._storageManager) this._storageManager.removeValues();
else
Expand All @@ -216,7 +221,7 @@ export abstract class SdkBase {

// Note: This doesn't invoke callbacks. It's a hard, silent reset.
/**
* @deprecated abort() should no longer be used for anything
* @deprecated abort() is deprecated in version 3.10.0. Will be removed in June 2025. Use disconnect() instead
*/
public abort(reason?: string) {
this._tokenPromiseHandler.rejectAllPromises(
Expand Down Expand Up @@ -406,8 +411,7 @@ export abstract class SdkBase {
} else if (validity.status === IdentityStatus.OPTOUT || status === IdentityStatus.OPTOUT) {
this._storageManager.setOptout();
} else {
this.abort();
this._storageManager.removeValues();
this.disconnect();
}

this._identity = this._storageManager.loadIdentity();
Expand Down

0 comments on commit 73a300c

Please sign in to comment.