From a3c1ce8519e83182a38e94278c7152978c96a709 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Thu, 31 Oct 2024 11:44:52 -0400 Subject: [PATCH] Update accountSummaries fetch reducer to handle none returned. --- .../js/modules/analytics-4/datastore/accounts.js | 11 ++++------- .../analytics-4/datastore/accounts.test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/assets/js/modules/analytics-4/datastore/accounts.js b/assets/js/modules/analytics-4/datastore/accounts.js index 26b72437391..473dd06b076 100644 --- a/assets/js/modules/analytics-4/datastore/accounts.js +++ b/assets/js/modules/analytics-4/datastore/accounts.js @@ -69,15 +69,12 @@ const fetchGetAccountSummariesStore = createFetchStore( { return { pageToken }; }, reducerCallback( state, response ) { - const { accountSummaries: newAccountSummaries } = response; - const mergedAccountSummaries = [ - ...( state.accountSummaries || [] ), - ...newAccountSummaries, - ]; - return { ...state, - accountSummaries: mergedAccountSummaries, + accountSummaries: [ + ...( state.accountSummaries || [] ), + ...( response.accountSummaries || [] ), + ], }; }, } ); diff --git a/assets/js/modules/analytics-4/datastore/accounts.test.js b/assets/js/modules/analytics-4/datastore/accounts.test.js index fcb23f5ab0a..7dfbab7e239 100644 --- a/assets/js/modules/analytics-4/datastore/accounts.test.js +++ b/assets/js/modules/analytics-4/datastore/accounts.test.js @@ -244,6 +244,21 @@ describe( 'modules/analytics-4 accounts', () => { } ); } ); + describe( 'fetchGetAccountSummaries', () => { + it( 'supports when no account summaries returned', async () => { + fetchMock.get( accountSummariesEndpoint, { + body: { nextPageToken: null }, + status: 200, + } ); + const { fetchGetAccountSummaries } = + registry.dispatch( MODULES_ANALYTICS_4 ); + + await fetchGetAccountSummaries(); + + expect( store.getState().accountSummaries ).toEqual( [] ); + } ); + } ); + describe( 'transformAndSortAccountSummaries', () => { it( 'should create an action to transform and sort account summaries', async () => { registry