diff --git a/packages/compass-global-writes/src/store/index.spec.ts b/packages/compass-global-writes/src/store/index.spec.ts index 11f5c3b4250..86b99fd574e 100644 --- a/packages/compass-global-writes/src/store/index.spec.ts +++ b/packages/compass-global-writes/src/store/index.spec.ts @@ -205,7 +205,7 @@ describe('GlobalWritesStore Store', function () { }); }); - it.only('not managed -> sharding -> sharding error', async function () { + it('not managed -> sharding -> sharding error', async function () { let mockFailure = false; // initial state === unsharded const store = createStore({ @@ -445,15 +445,61 @@ describe('GlobalWritesStore Store', function () { }); }); - it('sharding error', async function () { + it('sharding error -> cancelling request -> not managed', async function () { + // initial state === sharding error + let mockManagedNamespace = true; + let mockShardingError = true; + clock = sinon.useFakeTimers({ + shouldAdvanceTime: true, + }); + const store = createStore({ + isNamespaceManaged: Sinon.fake(() => mockManagedNamespace), + hasShardingError: Sinon.fake(() => mockShardingError), + }); + await waitFor(() => { + expect(store.getState().status).to.equal('SHARDING_ERROR'); + expect(store.getState().managedNamespace).to.equal(managedNamespace); + }); + + // user triggers a cancellation + const promise = store.dispatch(cancelSharding()); + mockManagedNamespace = false; + mockShardingError = false; + await promise; + expect(store.getState().status).to.equal('UNSHARDED'); + expect(confirmationStub).to.have.been.called; + }); + + it('sharding error -> submitting form -> sharding -> sharded', async function () { + // initial state === sharding error= + let mockShardingError = true; + let mockShardKey = false; + clock = sinon.useFakeTimers({ + shouldAdvanceTime: true, + }); const store = createStore({ isNamespaceManaged: () => true, - hasShardingError: () => true, + hasShardingError: Sinon.fake(() => mockShardingError), + hasShardKey: Sinon.fake(() => mockShardKey), }); await waitFor(() => { expect(store.getState().status).to.equal('SHARDING_ERROR'); expect(store.getState().managedNamespace).to.equal(managedNamespace); }); + + // user submits the form + const promise = store.dispatch(createShardKey(shardKeyData)); + mockShardingError = false; + expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING_ERROR'); + await promise; + expect(store.getState().status).to.equal('SHARDING'); + + // the key is created + mockShardKey = true; + clock.tick(POLLING_INTERVAL); + await waitFor(() => { + expect(store.getState().status).to.equal('SHARD_KEY_CORRECT'); + }); }); it('sends correct data to the server when creating a shard key', async function () { diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts index f9479c12f8d..fe473691090 100644 --- a/packages/compass-global-writes/src/store/reducer.ts +++ b/packages/compass-global-writes/src/store/reducer.ts @@ -442,7 +442,8 @@ const reducer: Reducer = (state = initialState, action) => { GlobalWritesActionTypes.CancellingShardingFinished ) && (state.status === ShardingStatuses.CANCELLING_SHARDING || - state.status === ShardingStatuses.SHARDING_ERROR) + state.status === ShardingStatuses.SHARDING_ERROR || + state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR) // the error might come before the cancel request was processed ) { return {