Skip to content

Commit

Permalink
fix(headless commerce): handle action dispatched by renew access toke…
Browse files Browse the repository at this point in the history
…n middleware in commerce configuration slice (#4947)

https://coveord.atlassian.net/browse/KIT-3949

This is most likely what's causing issues in projects migrating from v2
to v3 that have a renewAccessToken function.
  • Loading branch information
fbeaudoincoveo authored Feb 10, 2025
1 parent ff21fd0 commit e1e1f71
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {updateBasicConfiguration} from '../../configuration/configuration-actions.js';
import {
disableAnalytics,
enableAnalytics,
updateAnalyticsConfiguration,
updateBasicConfiguration,
updateBasicConfiguration as updateBasicCommerceConfiguration,
updateProxyBaseUrl,
} from './configuration-actions.js';
import {configurationReducer} from './configuration-slice.js';
Expand Down Expand Up @@ -65,6 +66,44 @@ describe('commerce configuration slice', () => {
});
});

describe('updateBasicCommerceConfiguration', () => {
it('works on initial state', () => {
expect(
configurationReducer(
undefined,
updateBasicCommerceConfiguration({
accessToken: 'my-new-access-token',
environment: 'hipaa',
organizationId: 'my-new-org-id',
})
)
).toEqual({
...getConfigurationInitialState(),
accessToken: 'my-new-access-token',
environment: 'hipaa',
organizationId: 'my-new-org-id',
});
});

it('works on an existing state', () => {
expect(
configurationReducer(
existingState,
updateBasicCommerceConfiguration({
accessToken: 'my-new-access-token',
environment: 'hipaa',
organizationId: 'my-new-org-id',
})
)
).toEqual({
...existingState,
accessToken: 'my-new-access-token',
environment: 'hipaa',
organizationId: 'my-new-org-id',
});
});
});

describe('updateProxBaseUrl', () => {
it('works on initial state', () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {isNullOrUndefined} from '@coveo/bueno';
import {createReducer} from '@reduxjs/toolkit';
import {updateBasicConfiguration} from '../../configuration/configuration-actions.js';
import {
disableAnalytics,
enableAnalytics,
updateAnalyticsConfiguration,
UpdateAnalyticsConfigurationPayload,
updateBasicConfiguration,
updateBasicConfiguration as updateBasicCommerceConfiguration,
UpdateBasicConfigurationPayload,
updateProxyBaseUrl,
UpdateProxyBaseUrlPayload,
Expand All @@ -19,6 +20,10 @@ export const configurationReducer = createReducer(
getConfigurationInitialState(),
(builder) =>
builder
.addCase(updateBasicCommerceConfiguration, (state, action) => {
handleUpdateBasicConfiguration(state, action.payload);
})
// This is to handle the renew access token middleware
.addCase(updateBasicConfiguration, (state, action) => {
handleUpdateBasicConfiguration(state, action.payload);
})
Expand Down

0 comments on commit e1e1f71

Please sign in to comment.