@@ -90,7 +90,7 @@ function createStore({
9090 } = { } ) : GlobalWritesStore {
9191 const atlasService = {
9292 authenticatedFetch : ( uri : string ) => {
93- if ( uri . includes ( `/geoSharding` ) && failsOnShardingRequest ( ) ) {
93+ if ( uri . endsWith ( `/geoSharding` ) && failsOnShardingRequest ( ) ) {
9494 return Promise . reject ( new Error ( 'Failed to shard' ) ) ;
9595 }
9696
@@ -313,7 +313,7 @@ describe('GlobalWritesStore Store', function () {
313313 } ) ;
314314 } ) ;
315315
316- it ( 'incomplete setup -> shard key correct' , async function ( ) {
316+ it ( 'incomplete setup -> sharding -> shard key correct' , async function ( ) {
317317 // initial state -> incomplete shardingSetup
318318 clock = sinon . useFakeTimers ( {
319319 shouldAdvanceTime : true ,
@@ -335,12 +335,78 @@ describe('GlobalWritesStore Store', function () {
335335 'SUBMITTING_FOR_SHARDING_INCOMPLETE'
336336 ) ;
337337 await promise ;
338+
339+ // sharding
340+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING' ) ;
341+
342+ // done
338343 clock . tick ( POLLING_INTERVAL ) ;
339344 await waitFor ( ( ) => {
340345 expect ( store . getState ( ) . status ) . to . equal ( 'SHARD_KEY_CORRECT' ) ;
341346 } ) ;
342347 } ) ;
343348
349+ it ( 'incomplete setup -> sharding -> incomplete setup (request was cancelled)' , async function ( ) {
350+ // initial state -> incomplete shardingSetup
351+ clock = sinon . useFakeTimers ( {
352+ shouldAdvanceTime : true ,
353+ } ) ;
354+ const store = createStore ( {
355+ isNamespaceManaged : ( ) => false ,
356+ hasShardKey : ( ) => true ,
357+ } ) ;
358+ await waitFor ( ( ) => {
359+ expect ( store . getState ( ) . status ) . to . equal ( 'INCOMPLETE_SHARDING_SETUP' ) ;
360+ expect ( store . getState ( ) . managedNamespace ) . to . be . undefined ;
361+ } ) ;
362+
363+ // user asks to resume geosharding
364+ const promise = store . dispatch ( resumeManagedNamespace ( ) ) ;
365+ expect ( store . getState ( ) . status ) . to . equal (
366+ 'SUBMITTING_FOR_SHARDING_INCOMPLETE'
367+ ) ;
368+ await promise ;
369+
370+ // sharding
371+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING' ) ;
372+
373+ // user cancels the request - we go back to incomplete
374+ const promise2 = store . dispatch ( cancelSharding ( ) ) ;
375+ await promise2 ;
376+ clock . tick ( POLLING_INTERVAL ) ;
377+ await waitFor ( ( ) => {
378+ expect ( store . getState ( ) . status ) . to . equal ( 'INCOMPLETE_SHARDING_SETUP' ) ;
379+ } ) ;
380+ } ) ;
381+
382+ it ( 'incomplete setup -> incomplete setup (failed manage attempt)' , async function ( ) {
383+ // initial state -> incomplete shardingSetup
384+ clock = sinon . useFakeTimers ( {
385+ shouldAdvanceTime : true ,
386+ } ) ;
387+ const store = createStore ( {
388+ isNamespaceManaged : ( ) => false ,
389+ hasShardKey : ( ) => true ,
390+ failsOnShardingRequest : ( ) => true ,
391+ } ) ;
392+ await waitFor ( ( ) => {
393+ expect ( store . getState ( ) . status ) . to . equal ( 'INCOMPLETE_SHARDING_SETUP' ) ;
394+ expect ( store . getState ( ) . managedNamespace ) . to . be . undefined ;
395+ } ) ;
396+
397+ // user asks to resume geosharding
398+ const promise = store . dispatch ( resumeManagedNamespace ( ) ) ;
399+ expect ( store . getState ( ) . status ) . to . equal (
400+ 'SUBMITTING_FOR_SHARDING_INCOMPLETE'
401+ ) ;
402+ await promise ;
403+
404+ // it failed
405+ await waitFor ( ( ) => {
406+ expect ( store . getState ( ) . status ) . to . equal ( 'INCOMPLETE_SHARDING_SETUP' ) ;
407+ } ) ;
408+ } ) ;
409+
344410 it ( 'valid shard key -> incomplete' , async function ( ) {
345411 // initial state === shard key correct
346412 const store = createStore ( {
0 commit comments