Skip to content

Commit 6e72726

Browse files
committed
remove extra calls
1 parent a1f873f commit 6e72726

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ describe('GlobalWritesStore Store', function () {
176176
const store = createStore({
177177
hasShardKey: Sinon.fake(() => mockShardKey),
178178
});
179-
await store.dispatch(fetchClusterShardingData());
180-
expect(store.getState().status).to.equal('UNSHARDED');
181-
expect(store.getState().managedNamespace).to.equal(undefined);
179+
await waitFor(() => {
180+
expect(store.getState().status).to.equal('UNSHARDED');
181+
expect(store.getState().managedNamespace).to.equal(undefined);
182+
});
182183

183184
// user requests sharding
184185
const promise = store.dispatch(createShardKey(shardKeyData));
@@ -200,9 +201,10 @@ describe('GlobalWritesStore Store', function () {
200201
const store = createStore({
201202
hasShardingError: Sinon.fake(() => mockFailure),
202203
});
203-
await store.dispatch(fetchClusterShardingData());
204-
expect(store.getState().status).to.equal('UNSHARDED');
205-
expect(store.getState().managedNamespace).to.equal(undefined);
204+
await waitFor(() => {
205+
expect(store.getState().status).to.equal('UNSHARDED');
206+
expect(store.getState().managedNamespace).to.equal(undefined);
207+
});
206208

207209
// user requests sharding
208210
const promise = store.dispatch(createShardKey(shardKeyData));
@@ -219,13 +221,16 @@ describe('GlobalWritesStore Store', function () {
219221
});
220222

221223
it('not managed -> not managed (failed sharding request)', async function () {
224+
// initial state === not managed
222225
const store = createStore({
223226
failsOnShardingRequest: () => true,
224227
});
225-
await store.dispatch(fetchClusterShardingData());
226-
expect(store.getState().status).to.equal('UNSHARDED');
227-
expect(store.getState().managedNamespace).to.equal(undefined);
228+
await waitFor(() => {
229+
expect(store.getState().status).to.equal('UNSHARDED');
230+
expect(store.getState().managedNamespace).to.equal(undefined);
231+
});
228232

233+
// user tries to submit for sharding, but the request fails
229234
const promise = store.dispatch(createShardKey(shardKeyData));
230235
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
231236
await promise;
@@ -239,7 +244,6 @@ describe('GlobalWritesStore Store', function () {
239244
isNamespaceManaged: () => true,
240245
hasShardKey: Sinon.fake(() => mockShardKey),
241246
});
242-
await store.dispatch(fetchClusterShardingData());
243247
await waitFor(() => {
244248
expect(store.getState().status).to.equal('SHARDING');
245249
expect(store.getState().managedNamespace).to.equal(managedNamespace);
@@ -260,7 +264,6 @@ describe('GlobalWritesStore Store', function () {
260264
const store = createStore({
261265
isNamespaceManaged: Sinon.fake(() => mockManagedNamespace),
262266
});
263-
await store.dispatch(fetchClusterShardingData());
264267
await waitFor(() => {
265268
expect(store.getState().status).to.equal('SHARDING');
266269
expect(store.getState().pollingTimeout).not.to.be.undefined;
@@ -281,21 +284,18 @@ describe('GlobalWritesStore Store', function () {
281284
isNamespaceManaged: () => true,
282285
hasShardKey: () => true,
283286
});
284-
await store.dispatch(fetchClusterShardingData());
285287
await waitFor(() => {
286288
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
287289
expect(store.getState().managedNamespace).to.equal(managedNamespace);
288290
});
289291
});
290292

291293
it('valid shard key -> not managed', async function () {
294+
// initial state === shard key correct
292295
const store = createStore({
293296
isNamespaceManaged: () => true,
294297
hasShardKey: () => true,
295298
});
296-
297-
// initial state === shard key correct
298-
await store.dispatch(fetchClusterShardingData());
299299
await waitFor(() => {
300300
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
301301
expect(store.getState().managedNamespace).to.equal(managedNamespace);
@@ -309,15 +309,14 @@ describe('GlobalWritesStore Store', function () {
309309
});
310310

311311
it('valid shard key -> valid shard key (failed unmanage attempt)', async function () {
312+
// initial state === shard key correct
312313
let mockFailure = false;
313314
const store = createStore({
314315
isNamespaceManaged: () => true,
315316
hasShardKey: () => true,
316317
failsOnShardingRequest: Sinon.fake(() => mockFailure),
317318
});
318319

319-
// initial state === shard key correct
320-
await store.dispatch(fetchClusterShardingData());
321320
await waitFor(() => {
322321
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
323322
expect(store.getState().managedNamespace).to.equal(managedNamespace);
@@ -336,7 +335,6 @@ describe('GlobalWritesStore Store', function () {
336335
isNamespaceManaged: () => true,
337336
hasShardingError: () => true,
338337
});
339-
await store.dispatch(fetchClusterShardingData());
340338
await waitFor(() => {
341339
expect(store.getState().status).to.equal('SHARDING_ERROR');
342340
expect(store.getState().managedNamespace).to.equal(managedNamespace);

0 commit comments

Comments
 (0)