Skip to content

Commit 9534064

Browse files
committed
remove extra calls
1 parent a1f873f commit 9534064

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

packages/compass-global-writes/src/store/index.spec.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect } from 'chai';
22
import { type GlobalWritesStore } from '.';
33
import { setupStore } from '../../tests/create-store';
44
import {
5-
fetchClusterShardingData,
65
createShardKey,
76
type CreateShardKeyData,
87
TEST_POLLING_INTERVAL,
@@ -176,9 +175,10 @@ describe('GlobalWritesStore Store', function () {
176175
const store = createStore({
177176
hasShardKey: Sinon.fake(() => mockShardKey),
178177
});
179-
await store.dispatch(fetchClusterShardingData());
180-
expect(store.getState().status).to.equal('UNSHARDED');
181-
expect(store.getState().managedNamespace).to.equal(undefined);
178+
await waitFor(() => {
179+
expect(store.getState().status).to.equal('UNSHARDED');
180+
expect(store.getState().managedNamespace).to.equal(undefined);
181+
});
182182

183183
// user requests sharding
184184
const promise = store.dispatch(createShardKey(shardKeyData));
@@ -200,9 +200,10 @@ describe('GlobalWritesStore Store', function () {
200200
const store = createStore({
201201
hasShardingError: Sinon.fake(() => mockFailure),
202202
});
203-
await store.dispatch(fetchClusterShardingData());
204-
expect(store.getState().status).to.equal('UNSHARDED');
205-
expect(store.getState().managedNamespace).to.equal(undefined);
203+
await waitFor(() => {
204+
expect(store.getState().status).to.equal('UNSHARDED');
205+
expect(store.getState().managedNamespace).to.equal(undefined);
206+
});
206207

207208
// user requests sharding
208209
const promise = store.dispatch(createShardKey(shardKeyData));
@@ -219,13 +220,16 @@ describe('GlobalWritesStore Store', function () {
219220
});
220221

221222
it('not managed -> not managed (failed sharding request)', async function () {
223+
// initial state === not managed
222224
const store = createStore({
223225
failsOnShardingRequest: () => true,
224226
});
225-
await store.dispatch(fetchClusterShardingData());
226-
expect(store.getState().status).to.equal('UNSHARDED');
227-
expect(store.getState().managedNamespace).to.equal(undefined);
227+
await waitFor(() => {
228+
expect(store.getState().status).to.equal('UNSHARDED');
229+
expect(store.getState().managedNamespace).to.equal(undefined);
230+
});
228231

232+
// user tries to submit for sharding, but the request fails
229233
const promise = store.dispatch(createShardKey(shardKeyData));
230234
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
231235
await promise;
@@ -239,7 +243,6 @@ describe('GlobalWritesStore Store', function () {
239243
isNamespaceManaged: () => true,
240244
hasShardKey: Sinon.fake(() => mockShardKey),
241245
});
242-
await store.dispatch(fetchClusterShardingData());
243246
await waitFor(() => {
244247
expect(store.getState().status).to.equal('SHARDING');
245248
expect(store.getState().managedNamespace).to.equal(managedNamespace);
@@ -260,7 +263,6 @@ describe('GlobalWritesStore Store', function () {
260263
const store = createStore({
261264
isNamespaceManaged: Sinon.fake(() => mockManagedNamespace),
262265
});
263-
await store.dispatch(fetchClusterShardingData());
264266
await waitFor(() => {
265267
expect(store.getState().status).to.equal('SHARDING');
266268
expect(store.getState().pollingTimeout).not.to.be.undefined;
@@ -281,21 +283,18 @@ describe('GlobalWritesStore Store', function () {
281283
isNamespaceManaged: () => true,
282284
hasShardKey: () => true,
283285
});
284-
await store.dispatch(fetchClusterShardingData());
285286
await waitFor(() => {
286287
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
287288
expect(store.getState().managedNamespace).to.equal(managedNamespace);
288289
});
289290
});
290291

291292
it('valid shard key -> not managed', async function () {
293+
// initial state === shard key correct
292294
const store = createStore({
293295
isNamespaceManaged: () => true,
294296
hasShardKey: () => true,
295297
});
296-
297-
// initial state === shard key correct
298-
await store.dispatch(fetchClusterShardingData());
299298
await waitFor(() => {
300299
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
301300
expect(store.getState().managedNamespace).to.equal(managedNamespace);
@@ -309,15 +308,14 @@ describe('GlobalWritesStore Store', function () {
309308
});
310309

311310
it('valid shard key -> valid shard key (failed unmanage attempt)', async function () {
311+
// initial state === shard key correct
312312
let mockFailure = false;
313313
const store = createStore({
314314
isNamespaceManaged: () => true,
315315
hasShardKey: () => true,
316316
failsOnShardingRequest: Sinon.fake(() => mockFailure),
317317
});
318318

319-
// initial state === shard key correct
320-
await store.dispatch(fetchClusterShardingData());
321319
await waitFor(() => {
322320
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
323321
expect(store.getState().managedNamespace).to.equal(managedNamespace);
@@ -336,7 +334,6 @@ describe('GlobalWritesStore Store', function () {
336334
isNamespaceManaged: () => true,
337335
hasShardingError: () => true,
338336
});
339-
await store.dispatch(fetchClusterShardingData());
340337
await waitFor(() => {
341338
expect(store.getState().status).to.equal('SHARDING_ERROR');
342339
expect(store.getState().managedNamespace).to.equal(managedNamespace);

0 commit comments

Comments
 (0)