Skip to content

Commit

Permalink
Fixed jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Mar 4, 2020
1 parent 6cf9acc commit 02ae1b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('reindexService', () => {

await service.createReindexOperation('myIndex');

expect(actions.createReindexOp).toHaveBeenCalledWith('myIndex');
expect(actions.createReindexOp).toHaveBeenCalledWith('myIndex', undefined);
});

it('fails if index does not exist', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('reindex API', () => {
);

// It called create correctly
expect(mockReindexService.createReindexOperation).toHaveBeenCalledWith('theIndex');
expect(mockReindexService.createReindexOperation).toHaveBeenCalledWith('theIndex', undefined);

// It returned the right results
expect(resp.status).toEqual(200);
Expand Down Expand Up @@ -261,6 +261,9 @@ describe('reindex API', () => {
});

describe('POST /api/upgrade_assistant/reindex/batch', () => {
const queueSettingsArg = {
queueSettings: { queuedAt: expect.any(Number) },
};
it('creates a collection of index operations', async () => {
mockReindexService.createReindexOperation
.mockResolvedValueOnce({
Expand All @@ -283,16 +286,28 @@ describe('reindex API', () => {
);

// It called create correctly
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(1, 'theIndex1');
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(2, 'theIndex2');
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(3, 'theIndex3');
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(
1,
'theIndex1',
queueSettingsArg
);
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(
2,
'theIndex2',
queueSettingsArg
);
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(
3,
'theIndex3',
queueSettingsArg
);

// It returned the right results
expect(resp.status).toEqual(200);
const data = resp.payload;
expect(data).toEqual({
errors: [],
started: [
enqueued: [
{ indexName: 'theIndex1' },
{ indexName: 'theIndex2' },
{ indexName: 'theIndex3' },
Expand Down Expand Up @@ -323,8 +338,16 @@ describe('reindex API', () => {

// It called create correctly
expect(mockReindexService.createReindexOperation).toHaveBeenCalledTimes(2);
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(1, 'theIndex1');
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(2, 'theIndex3');
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(
1,
'theIndex1',
queueSettingsArg
);
expect(mockReindexService.createReindexOperation).toHaveBeenNthCalledWith(
2,
'theIndex3',
queueSettingsArg
);

// It returned the right results
expect(resp.status).toEqual(200);
Expand All @@ -337,7 +360,7 @@ describe('reindex API', () => {
},
{ indexName: 'theIndex3', message: 'oops!' },
],
started: [{ indexName: 'theIndex1' }],
enqueued: [{ indexName: 'theIndex1' }],
});
});
});
Expand Down

0 comments on commit 02ae1b2

Please sign in to comment.