-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(headless SSR): fetchStaticState should only accept solutiontype-…
…specific controllers (#4769) This is a complex one. It introduces type changes only to ensure that props for solution type-specific controllers are only required in their respective engine definitions. ### Key changes: Recommendation props are now only required in recommendationEngineDefinition. The same logic is applied to other solution type-specific controllers. Additionally, unit tests have been added to verify that type inference and conditional prop types function correctly. https://coveord.atlassian.net/browse/KIT-3787 --------- Co-authored-by: Frederic Beaudoin <[email protected]>
- Loading branch information
1 parent
96cc465
commit f961cb2
Showing
14 changed files
with
411 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/headless/src/app/commerce-engine/commerce-engine.ssr.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import {defineCart} from '../../controllers/commerce/context/cart/headless-cart.ssr.js'; | ||
import {defineParameterManager} from '../../controllers/commerce/core/parameter-manager/headless-core-parameter-manager.ssr.js'; | ||
import {defineSummary} from '../../controllers/commerce/core/summary/headless-core-summary.ssr.js'; | ||
import {defineRecommendations} from '../../controllers/commerce/recommendations/headless-recommendations.ssr.js'; | ||
import {defineDidYouMean} from '../../controllers/commerce/search/did-you-mean/headless-did-you-mean.ssr.js'; | ||
import {getSampleCommerceEngineConfiguration} from './commerce-engine-configuration.js'; | ||
import {defineCommerceEngine} from './commerce-engine.ssr.js'; | ||
|
||
describe('Commerce Engine SSR', () => { | ||
const { | ||
listingEngineDefinition, | ||
recommendationEngineDefinition, | ||
searchEngineDefinition, | ||
standaloneEngineDefinition, | ||
} = defineCommerceEngine({ | ||
configuration: { | ||
...getSampleCommerceEngineConfiguration(), | ||
}, | ||
controllers: { | ||
summary: defineSummary(), | ||
didYouMean: defineDidYouMean(), | ||
paramManager: defineParameterManager({listing: false}), | ||
cart: defineCart(), | ||
popularViewed: defineRecommendations({ | ||
options: { | ||
slotId: 'd73afbd2-8521-4ee6-a9b8-31f064721e73', | ||
}, | ||
}), | ||
}, | ||
}); | ||
|
||
it('should only require cart options for standaloneEngineDefinition', () => { | ||
expect(() => | ||
standaloneEngineDefinition.fetchStaticState({ | ||
controllers: { | ||
cart: {initialState: {items: []}}, | ||
}, | ||
}) | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should only require cart options for listingEngineDefinition', () => { | ||
expect(() => | ||
listingEngineDefinition.fetchStaticState({ | ||
controllers: { | ||
cart: {initialState: {items: []}}, | ||
}, | ||
}) | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should only require cart and paramManager options for searchEngineDefinition', () => { | ||
expect(() => | ||
searchEngineDefinition.fetchStaticState({ | ||
controllers: { | ||
cart: {initialState: {items: []}}, | ||
paramManager: {initialState: {parameters: {}}}, | ||
}, | ||
}) | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should only require cart options for recommendationEngineDefinition', () => { | ||
expect(() => | ||
recommendationEngineDefinition.fetchStaticState({ | ||
controllers: { | ||
cart: {initialState: {items: []}}, | ||
}, | ||
}) | ||
).not.toThrow(); | ||
}); | ||
|
||
it('should allow optional recommendation controller options for recommendationEngineDefinition', () => { | ||
expect(() => | ||
recommendationEngineDefinition.fetchStaticState({ | ||
controllers: { | ||
cart: {initialState: {items: []}}, | ||
popularViewed: {enabled: true, productId: 'some-product-id'}, | ||
}, | ||
}) | ||
).not.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.