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

Instantiator Fix #1185

Merged
merged 1 commit into from
Oct 25, 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 @@ -289,7 +289,32 @@ describe('RecommendationInstantiator', () => {
expect(clientSpy).toHaveBeenCalledTimes(1);
});

it('makes the context found on the target available', async () => {
it('supports legacy script type with config context', async () => {
const profile = 'legacy';
document.body.innerHTML = `<script type="searchspring/personalized-recommendations" profile="${profile}"></script>`;

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

const newConfig = {
...baseConfig,
context: {
testing: 'things',
},
};

const recommendationInstantiator = new RecommendationInstantiator(newConfig, { client });
await wait();
expect(Object.keys(recommendationInstantiator.controller).length).toBe(1);
expect(recommendationInstantiator.controller['recommend_legacy_0']).toBeDefined();
expect(recommendationInstantiator.controller['recommend_legacy_0'].context).toStrictEqual({
profile,
...newConfig.context,
});
expect(clientSpy).toHaveBeenCalledTimes(1);
});

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' };
product = 'sku1';
Expand Down Expand Up @@ -319,7 +344,14 @@ describe('RecommendationInstantiator', () => {
const client = new MockClient(baseConfig.client!.globals, {});
const clientSpy = jest.spyOn(client, 'recommend');

const recommendationInstantiator = new RecommendationInstantiator(baseConfig, { client });
const newConfig = {
...baseConfig,
context: {
testing: 'things',
},
};

const recommendationInstantiator = new RecommendationInstantiator(newConfig, { client });
await wait();
expect(Object.keys(recommendationInstantiator.controller).length).toBe(1);
Object.keys(recommendationInstantiator.controller).forEach((controllerId) => {
Expand Down Expand Up @@ -350,6 +382,7 @@ describe('RecommendationInstantiator', () => {
limit: 5,
siteId: 'abc123',
},
...newConfig.context,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class RecommendationInstantiator {
}),
};

readyTheController(this, elem, elemContext, profileCount, originalElem, profileRequestGlobals);
readyTheController(this, elem, deepmerge(this.context, elemContext), profileCount, originalElem, profileRequestGlobals);
}
}
);
Expand Down
Loading