@@ -205,7 +205,7 @@ describe('GlobalWritesStore Store', function () {
205205 } ) ;
206206 } ) ;
207207
208- it . only ( 'not managed -> sharding -> sharding error' , async function ( ) {
208+ it ( 'not managed -> sharding -> sharding error' , async function ( ) {
209209 let mockFailure = false ;
210210 // initial state === unsharded
211211 const store = createStore ( {
@@ -445,15 +445,61 @@ describe('GlobalWritesStore Store', function () {
445445 } ) ;
446446 } ) ;
447447
448- it ( 'sharding error' , async function ( ) {
448+ it ( 'sharding error -> cancelling request -> not managed' , async function ( ) {
449+ // initial state === sharding error
450+ let mockManagedNamespace = true ;
451+ let mockShardingError = true ;
452+ clock = sinon . useFakeTimers ( {
453+ shouldAdvanceTime : true ,
454+ } ) ;
455+ const store = createStore ( {
456+ isNamespaceManaged : Sinon . fake ( ( ) => mockManagedNamespace ) ,
457+ hasShardingError : Sinon . fake ( ( ) => mockShardingError ) ,
458+ } ) ;
459+ await waitFor ( ( ) => {
460+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING_ERROR' ) ;
461+ expect ( store . getState ( ) . managedNamespace ) . to . equal ( managedNamespace ) ;
462+ } ) ;
463+
464+ // user triggers a cancellation
465+ const promise = store . dispatch ( cancelSharding ( ) ) ;
466+ mockManagedNamespace = false ;
467+ mockShardingError = false ;
468+ await promise ;
469+ expect ( store . getState ( ) . status ) . to . equal ( 'UNSHARDED' ) ;
470+ expect ( confirmationStub ) . to . have . been . called ;
471+ } ) ;
472+
473+ it ( 'sharding error -> submitting form -> sharding -> sharded' , async function ( ) {
474+ // initial state === sharding error=
475+ let mockShardingError = true ;
476+ let mockShardKey = false ;
477+ clock = sinon . useFakeTimers ( {
478+ shouldAdvanceTime : true ,
479+ } ) ;
449480 const store = createStore ( {
450481 isNamespaceManaged : ( ) => true ,
451- hasShardingError : ( ) => true ,
482+ hasShardingError : Sinon . fake ( ( ) => mockShardingError ) ,
483+ hasShardKey : Sinon . fake ( ( ) => mockShardKey ) ,
452484 } ) ;
453485 await waitFor ( ( ) => {
454486 expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING_ERROR' ) ;
455487 expect ( store . getState ( ) . managedNamespace ) . to . equal ( managedNamespace ) ;
456488 } ) ;
489+
490+ // user submits the form
491+ const promise = store . dispatch ( createShardKey ( shardKeyData ) ) ;
492+ mockShardingError = false ;
493+ expect ( store . getState ( ) . status ) . to . equal ( 'SUBMITTING_FOR_SHARDING_ERROR' ) ;
494+ await promise ;
495+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING' ) ;
496+
497+ // the key is created
498+ mockShardKey = true ;
499+ clock . tick ( POLLING_INTERVAL ) ;
500+ await waitFor ( ( ) => {
501+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARD_KEY_CORRECT' ) ;
502+ } ) ;
457503 } ) ;
458504
459505 it ( 'sends correct data to the server when creating a shard key' , async function ( ) {
0 commit comments