Skip to content

Commit

Permalink
Fix login tests timing out
Browse files Browse the repository at this point in the history
Change operationsFromCache stub to remove promise as it is not an async function and finish running timers after each test
  • Loading branch information
shepherd-l committed Sep 23, 2024
1 parent 2e6e69f commit 8bb8c13
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions __test__/unit/user/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,13 @@ jest.mock('../../../src/shared/libraries/Log');
describe('Login tests', () => {
beforeEach(() => {
jest.useFakeTimers();
test.stub(
PropertiesExecutor.prototype,
'getOperationsFromCache',
Promise.resolve([]),
);
test.stub(
IdentityExecutor.prototype,
'getOperationsFromCache',
Promise.resolve([]),
);
test.stub(
SubscriptionExecutor.prototype,
'getOperationsFromCache',
Promise.resolve([]),
);
test.stub(PropertiesExecutor.prototype, 'getOperationsFromCache', []);
test.stub(IdentityExecutor.prototype, 'getOperationsFromCache', []);
test.stub(SubscriptionExecutor.prototype, 'getOperationsFromCache', []);
});

afterEach(() => {
jest.runOnlyPendingTimers();
jest.resetAllMocks();
});

Expand Down Expand Up @@ -92,10 +81,17 @@ describe('Login tests', () => {
const identifyOrUpsertUserSpy = test.stub(
LoginManager,
'identifyOrUpsertUser',
Promise.resolve({
identity: {
external_id: 'rodrigo2',
onesignal_id: '123456789',
},
}),
);

await LoginManager.login(DUMMY_EXTERNAL_ID);
await LoginManager.login('rodrigo2');
console.log(OneSignal.coreDirector.getIdentityModel());

expect(identifyOrUpsertUserSpy).toHaveBeenCalledTimes(2);
});
Expand All @@ -121,6 +117,7 @@ describe('Login tests', () => {
);

await LoginManager.login(external_id);
console.log(OneSignal.coreDirector.getIdentityModel());

// TO DO: test the order of operations (force process deltas should occur at beginning of login process)
expect(forceProcessSpy).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 8bb8c13

Please sign in to comment.