Skip to content

Commit 867a2ef

Browse files
authored
fix(atlas-service): dont signin twice in tests COMPASS-8837 (#6624)
* dont call signin twice * only one signin * no only * wait so that sign-in is triggered * ensure that stub is called and only once
1 parent a2b319e commit 867a2ef

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

packages/atlas-service/src/store/atlas-signin-reducer.spec.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,31 @@ describe('atlasSignInReducer', function () {
159159
});
160160

161161
it('should cancel sign in if sign in is in progress', async function () {
162-
const mockAtlasService = {
163-
isAuthenticated: sandbox
164-
.stub()
165-
.callsFake(({ signal }: { signal: AbortSignal }) => {
166-
return new Promise((resolve, reject) => {
167-
signal.addEventListener('abort', () => {
168-
reject(signal.reason);
169-
});
162+
const isAuthenticatedStub = sandbox
163+
.stub()
164+
.callsFake(({ signal }: { signal: AbortSignal }) => {
165+
return new Promise((resolve, reject) => {
166+
signal.addEventListener('abort', () => {
167+
reject(signal.reason);
170168
});
171-
}),
169+
});
170+
});
171+
const mockAtlasService = {
172+
isAuthenticated: isAuthenticatedStub,
172173
};
173174
const store = configureStore({
174175
atlasAuthService: mockAtlasService as any,
175176
});
176177

177178
void store.dispatch(performSignInAttempt()).catch(() => {});
178179

179-
await Promise.all([
180-
store.dispatch(signIn()),
181-
store.dispatch(cancelSignIn()),
182-
]);
180+
// Give it some time for start the sign in attempt. It will be waiting
181+
// at isAuthenticated, which never resolves.
182+
await new Promise((resolve) => setTimeout(resolve, 100));
183+
store.dispatch(cancelSignIn());
183184
expect(store.getState()).to.have.nested.property('state', 'canceled');
185+
186+
expect(isAuthenticatedStub).to.have.been.calledOnce;
184187
});
185188
});
186189

0 commit comments

Comments
 (0)