Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickaël Depardon committed Aug 26, 2024
1 parent a10ebae commit 26dd657
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions tests/strapi-algolia.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,11 @@ describe('strapi-algolia plugin', () => {
});

test('createOrDeleteObjects utils', async () => {
const algoliaIndex = {
const algoliaClient = {
deleteObjects: jest.fn(),
saveObjects: jest.fn(),
};
const indexName = 'index-name';

await algoliaService({ strapi }).createOrDeleteObjects(
[
Expand All @@ -196,29 +197,30 @@ describe('strapi-algolia plugin', () => {
{ id: 4, toto: null, tata: null },
],
['5', '6', '7', '8'],
algoliaIndex as any,
algoliaClient as any,
indexName,
['toto']
);

expect(algoliaIndex.deleteObjects).toHaveBeenCalledTimes(2);
expect(algoliaIndex.deleteObjects).toHaveBeenNthCalledWith(1, [
'5',
'6',
]);
expect(algoliaIndex.deleteObjects).toHaveBeenNthCalledWith(2, [
'7',
'8',
]);
expect(algoliaClient.deleteObjects).toHaveBeenCalledTimes(2);
expect(algoliaClient.deleteObjects).toHaveBeenNthCalledWith(1, {
indexName,
objectIDs: ['5', '6'],
});
expect(algoliaClient.deleteObjects).toHaveBeenNthCalledWith(2, {
objectIDs: ['7', '8'],
indexName,
});

expect(algoliaIndex.saveObjects).toHaveBeenCalledTimes(2);
expect(algoliaIndex.saveObjects).toHaveBeenNthCalledWith(1, [
{ id: 1 },
{ id: 2 },
]);
expect(algoliaIndex.saveObjects).toHaveBeenNthCalledWith(2, [
{ id: 3 },
{ id: 4, toto: false, tata: null },
]);
expect(algoliaClient.saveObjects).toHaveBeenCalledTimes(2);
expect(algoliaClient.saveObjects).toHaveBeenNthCalledWith(1, {
indexName,
objects: [{ id: 1 }, { id: 2 }],
});
expect(algoliaClient.saveObjects).toHaveBeenNthCalledWith(2, {
indexName,
objects: [{ id: 3 }, { id: 4, toto: false, tata: null }],
});
});
});

Expand Down

0 comments on commit 26dd657

Please sign in to comment.