Skip to content

Commit

Permalink
add smake test
Browse files Browse the repository at this point in the history
  • Loading branch information
raed667 committed Jul 19, 2023
1 parent 3216296 commit bb251cc
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions packages/recommend/src/__tests__/getRecommendations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ import { TestSuite } from '../../../client-common/src/__tests__/TestSuite';

const recommend = new TestSuite('recommend').recommend;

function createMockedClient() {
function createMockedClient<TObject>() {
const client = recommend('appId', 'apiKey');
jest.spyOn(client.transporter, 'read').mockImplementation(() => Promise.resolve());
jest.spyOn(client.transporter, 'read').mockImplementation(() =>
Promise.resolve({
results: [
{
hits: [
{
objectID: '1',
},
],
},
],
})
);

return client;
}
Expand Down Expand Up @@ -197,4 +209,25 @@ describe('getRecommendations', () => {
{}
);
});

test('returns recommendations results', async () => {
const client = createMockedClient();

const recommendations = await client.getRecommendations<any>(
[
{
model: 'bought-together',
indexName: 'products',
objectID: 'B018APC4LE',
},
],
{}
);

expect(recommendations.results[0].hits).toEqual([
{
objectID: '1',
},
]);
});
});

0 comments on commit bb251cc

Please sign in to comment.