Skip to content

Commit

Permalink
Update accountSummaries fetch reducer to handle none returned.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaemnnosttv committed Oct 31, 2024
1 parent 135c0bc commit a3c1ce8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 4 additions & 7 deletions assets/js/modules/analytics-4/datastore/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [] ),
],
};
},
} );
Expand Down
15 changes: 15 additions & 0 deletions assets/js/modules/analytics-4/datastore/accounts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a3c1ce8

Please sign in to comment.