@@ -72,20 +72,29 @@ function createStore({
7272 hasShardingError = ( ) => false ,
7373 hasShardKey = ( ) => false ,
7474 failsOnShardingRequest = ( ) => false ,
75+ failsToFetchClusterDetails = ( ) => false ,
76+ failsToFetchDeploymentStatus = ( ) => false ,
77+ failsToFetchShardKey = ( ) => false ,
7578 authenticatedFetchStub,
7679} :
7780 | {
7881 isNamespaceManaged ?: ( ) => boolean ;
7982 hasShardingError ?: ( ) => boolean ;
8083 hasShardKey ?: ( ) => boolean | AtlasShardKey ;
8184 failsOnShardingRequest ?: ( ) => boolean ;
85+ failsToFetchClusterDetails ?: ( ) => boolean ;
86+ failsToFetchDeploymentStatus ?: ( ) => boolean ;
87+ failsToFetchShardKey ?: ( ) => boolean ;
8288 authenticatedFetchStub ?: never ;
8389 }
8490 | {
8591 isNamespaceManaged ?: never ;
8692 hasShardingError ?: never ;
8793 hasShardKey ?: ( ) => boolean | ShardKey ;
8894 failsOnShardingRequest ?: never ;
95+ failsToFetchClusterDetails ?: never ;
96+ failsToFetchDeploymentStatus ?: never ;
97+ failsToFetchShardKey ?: ( ) => boolean ;
8998 authenticatedFetchStub ?: ( ) => void ;
9099 } = { } ) : GlobalWritesStore {
91100 const atlasService = {
@@ -95,6 +104,9 @@ function createStore({
95104 }
96105
97106 if ( uri . includes ( '/clusters/' ) ) {
107+ if ( failsToFetchClusterDetails ( ) ) {
108+ return Promise . reject ( new Error ( 'Failed to fetch cluster details' ) ) ;
109+ }
98110 return createAuthFetchResponse ( {
99111 ...clusterDetails ,
100112 geoSharding : {
@@ -105,6 +117,9 @@ function createStore({
105117 }
106118
107119 if ( uri . includes ( '/deploymentStatus/' ) ) {
120+ if ( failsToFetchDeploymentStatus ( ) ) {
121+ return Promise . reject ( new Error ( 'Failed to fetch deployment status' ) ) ;
122+ }
108123 return createAuthFetchResponse ( {
109124 automationStatus : {
110125 processes : hasShardingError ( ) ? [ failedShardingProcess ] : [ ] ,
@@ -120,6 +135,10 @@ function createStore({
120135 } ) ,
121136 automationAgentAwait : ( _meta : unknown , type : string ) => {
122137 if ( type === 'getShardKey' ) {
138+ if ( failsToFetchShardKey ( ) ) {
139+ return Promise . reject ( new Error ( 'Failed to fetch shardKey' ) ) ;
140+ }
141+
123142 const shardKey = hasShardKey ( ) ;
124143 return {
125144 response :
@@ -178,6 +197,35 @@ describe('GlobalWritesStore Store', function () {
178197 } ) ;
179198
180199 context ( 'scenarios' , function ( ) {
200+ context ( 'initial load fail' , function ( ) {
201+ it ( 'fails to fetch cluster details' , async function ( ) {
202+ const store = createStore ( {
203+ failsToFetchClusterDetails : ( ) => true ,
204+ } ) ;
205+ await waitFor ( ( ) => {
206+ expect ( store . getState ( ) . status ) . to . equal ( 'LOADING_ERROR' ) ;
207+ } ) ;
208+ } ) ;
209+
210+ it ( 'fails to fetch shard key' , async function ( ) {
211+ const store = createStore ( {
212+ failsToFetchShardKey : ( ) => true ,
213+ } ) ;
214+ await waitFor ( ( ) => {
215+ expect ( store . getState ( ) . status ) . to . equal ( 'LOADING_ERROR' ) ;
216+ } ) ;
217+ } ) ;
218+
219+ it ( 'fails to fetch deployment status' , async function ( ) {
220+ const store = createStore ( {
221+ failsToFetchDeploymentStatus : ( ) => true ,
222+ } ) ;
223+ await waitFor ( ( ) => {
224+ expect ( store . getState ( ) . status ) . to . equal ( 'LOADING_ERROR' ) ;
225+ } ) ;
226+ } ) ;
227+ } ) ;
228+
181229 it ( 'not managed -> sharding -> valid shard key' , async function ( ) {
182230 let mockShardKey = false ;
183231 let mockManagedNamespace = false ;
@@ -280,6 +328,52 @@ describe('GlobalWritesStore Store', function () {
280328 } ) ;
281329 } ) ;
282330
331+ context ( 'pulling fail' , function ( ) {
332+ it ( 'sharding -> error (failed to fetch shard key)' , async function ( ) {
333+ let mockFailure = false ;
334+ // initial state === sharding
335+ clock = sinon . useFakeTimers ( {
336+ shouldAdvanceTime : true ,
337+ } ) ;
338+ const store = createStore ( {
339+ isNamespaceManaged : ( ) => true ,
340+ failsToFetchShardKey : Sinon . fake ( ( ) => mockFailure ) ,
341+ } ) ;
342+ await waitFor ( ( ) => {
343+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING' ) ;
344+ } ) ;
345+
346+ // sharding ends with a request failure
347+ mockFailure = true ;
348+ clock . tick ( POLLING_INTERVAL ) ;
349+ await waitFor ( ( ) => {
350+ expect ( store . getState ( ) . status ) . to . equal ( 'LOADING_ERROR' ) ;
351+ } ) ;
352+ } ) ;
353+
354+ it ( 'sharding -> error (failed to fetch deployment status)' , async function ( ) {
355+ let mockFailure = false ;
356+ // initial state === sharding
357+ clock = sinon . useFakeTimers ( {
358+ shouldAdvanceTime : true ,
359+ } ) ;
360+ const store = createStore ( {
361+ isNamespaceManaged : ( ) => true ,
362+ failsToFetchDeploymentStatus : Sinon . fake ( ( ) => mockFailure ) ,
363+ } ) ;
364+ await waitFor ( ( ) => {
365+ expect ( store . getState ( ) . status ) . to . equal ( 'SHARDING' ) ;
366+ } ) ;
367+
368+ // sharding ends with a request failure
369+ mockFailure = true ;
370+ clock . tick ( POLLING_INTERVAL ) ;
371+ await waitFor ( ( ) => {
372+ expect ( store . getState ( ) . status ) . to . equal ( 'LOADING_ERROR' ) ;
373+ } ) ;
374+ } ) ;
375+ } ) ;
376+
283377 it ( 'sharding -> cancelling request -> not managed' , async function ( ) {
284378 let mockManagedNamespace = true ;
285379 confirmationStub . resolves ( true ) ;
0 commit comments