Skip to content

Commit

Permalink
Fix false positives in query signals routes tests
Browse files Browse the repository at this point in the history
* Refactors mock expectations so that they're actually evaluated; they
can't go within a mockImplementation call as it's evaluated in the wrong
scope.
* Fixes duplicated test to use the proper assertions
  • Loading branch information
rylnd committed Feb 13, 2020
1 parent 668702b commit 56fc3f5
Showing 1 changed file with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,42 @@ describe('query for signal', () => {

describe('query and agg on signals index', () => {
test('returns 200 when using single query', async () => {
clients.clusterClient.callAsCurrentUser.mockImplementation((endpoint, params) => {
expect(params!.body).toMatchObject({ ...typicalSignalsQueryAggs() });
return Promise.resolve(true);
});
const { statusCode } = await server.inject(getSignalsAggsQueryRequest());
const { statusCode } = await server.inject(getSignalsQueryRequest());

expect(statusCode).toBe(200);
expect(clients.clusterClient.callAsCurrentUser).toHaveBeenCalledWith(
'search',
expect.objectContaining({ body: typicalSignalsQuery() })
);
expect(myUtils.getIndex).toHaveReturnedWith('fakeindex');
});

test('returns 200 when using single agg', async () => {
clients.clusterClient.callAsCurrentUser.mockImplementation((endpoint, params) => {
expect(params!.body).toMatchObject({ ...typicalSignalsQueryAggs() });
return Promise.resolve(true);
});
const { statusCode } = await server.inject(getSignalsAggsQueryRequest());

expect(statusCode).toBe(200);
expect(clients.clusterClient.callAsCurrentUser).toHaveBeenCalledWith(
'search',
expect.objectContaining({ body: typicalSignalsQueryAggs() })
);
expect(myUtils.getIndex).toHaveReturnedWith('fakeindex');
});

test('returns 200 when using aggs and query together', async () => {
const allTogether = getSignalsQueryRequest();
allTogether.payload = { ...typicalSignalsQueryAggs(), ...typicalSignalsQuery() };
clients.clusterClient.callAsCurrentUser.mockImplementation((endpoint, params) => {
expect(params!.body).toMatchObject({
...typicalSignalsQueryAggs(),
...typicalSignalsQuery(),
});
return Promise.resolve(true);
});
const { statusCode } = await server.inject(allTogether);
const request = getSignalsQueryRequest();
request.payload = { ...typicalSignalsQueryAggs(), ...typicalSignalsQuery() };
const { statusCode } = await server.inject(request);

expect(statusCode).toBe(200);
expect(clients.clusterClient.callAsCurrentUser).toHaveBeenCalledWith(
'search',
expect.objectContaining({
body: {
...typicalSignalsQuery(),
...typicalSignalsQueryAggs(),
},
})
);
expect(myUtils.getIndex).toHaveReturnedWith('fakeindex');
});

Expand Down

0 comments on commit 56fc3f5

Please sign in to comment.