Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.61.5 #1200

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ describe('Recommendation Controller', () => {
*/

const result = controller.store.results[0];

//this tests we send the core data and not the display data
result.mask.set({ id: 'custom', mappings: { core: { name: 'custom name' } } });

const productEventReturn = controller.track.product.impression(result);

expect(trackfn).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class RecommendationController extends AbstractController {
product: {
id: result.id,
mappings: {
core: result.display.mappings.core,
core: result.mappings.core,
},
seed: getSeed(),
},
Expand Down Expand Up @@ -170,7 +170,7 @@ export class RecommendationController extends AbstractController {
product: {
id: result.id,
mappings: {
core: result.display.mappings.core,
core: result.mappings.core,
},
seed: getSeed(),
},
Expand Down Expand Up @@ -198,7 +198,7 @@ export class RecommendationController extends AbstractController {
product: {
id: result.id,
mappings: {
core: result.display.mappings.core,
core: result.mappings.core,
},
seed: getSeed(),
},
Expand Down Expand Up @@ -233,7 +233,7 @@ export class RecommendationController extends AbstractController {
product: {
id: result.id,
mappings: {
core: result.display.mappings.core,
core: result.mappings.core,
},
seed: getSeed(),
},
Expand Down Expand Up @@ -268,7 +268,7 @@ export class RecommendationController extends AbstractController {
product: {
id: result.id,
mappings: {
core: result.display.mappings.core,
core: result.mappings.core,
},
seed: getSeed(),
},
Expand Down Expand Up @@ -297,7 +297,7 @@ export class RecommendationController extends AbstractController {
products: results.map((result) => ({
id: result.id,
mappings: {
core: result.display.mappings.core,
core: result.mappings.core,
},
quantity: result.quantity,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,75 @@ describe('RecommendationInstantiator', () => {
expect(clientSpy).toHaveBeenCalledTimes(1);
});

it('supports legacy scripts with batching', async () => {
document.body.innerHTML = `

<script type="searchspring/personalized-recommendations" profile="legacy">
options = {
batched: true
};
products = ['prod1234', 'prod4567'];
</script>

<script type="searchspring/personalized-recommendations" profile="legacy">
options = {
batched: false
};
products = ['prod0'];
</script>

<script type="searchspring/personalized-recommendations" profile="legacy">
options = {
batched: true
};
products = ['prod789'];
</script>`;

const client = new MockClient(baseConfig.client!.globals, {});
const clientSpy = jest.spyOn(client, 'recommend');

const recommendationInstantiator = new RecommendationInstantiator(baseConfig, { client });
await wait();
expect(Object.keys(recommendationInstantiator.controller).length).toBe(3);
expect(recommendationInstantiator.controller['recommend_legacy_0']).toBeDefined();
expect(clientSpy).toHaveBeenCalledTimes(3);
expect(clientSpy).toHaveBeenNthCalledWith(1, {
batchId: undefined,
batched: true,
branch: 'production',
products: ['prod1234', 'prod4567'],
profile: {
batched: true,
},
siteId: '8uyt2m',
tag: 'legacy',
});

expect(clientSpy).toHaveBeenNthCalledWith(2, {
batchId: undefined,
batched: false,
branch: 'production',
products: ['prod0'],
profile: {
batched: false,
},
siteId: '8uyt2m',
tag: 'legacy',
});

expect(clientSpy).toHaveBeenNthCalledWith(3, {
batchId: undefined,
batched: true,
branch: 'production',
products: ['prod789'],
profile: {
batched: true,
},
siteId: '8uyt2m',
tag: 'legacy',
});
});

it('makes the context found on the target and in the config available', async () => {
document.body.innerHTML = `<script type="searchspring/recommend" profile="${DEFAULT_PROFILE}">
shopper = { id: 'snapdev' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ async function readyTheController(
controllerGlobals: Partial<RecommendRequestModel>
) {
const { profile, batchId, cart, tag } = controllerGlobals;
const batched = (profile?.batched || controllerGlobals.batched) ?? true;
const batched = profile?.batched ?? controllerGlobals.batched ?? true;

if (!tag) {
// FEEDBACK: change message depending on script integration type (profile vs. legacy)
Expand Down
Loading