Skip to content

Commit

Permalink
add unit tests for policy filtering query
Browse files Browse the repository at this point in the history
  • Loading branch information
pzl committed Aug 28, 2020
1 parent 636190b commit 53dfce5
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { GetPolicyResponseSchema } from '../../../../common/endpoint/schema/policy';
import { getESQueryPolicyResponseByHostID } from './service';

describe('test policy handlers schema', () => {
it('validate that get policy response query schema', async () => {
Expand All @@ -17,3 +18,21 @@ describe('test policy handlers schema', () => {
expect(() => GetPolicyResponseSchema.query.validate({})).toThrowError();
});
});

describe('test policy query', () => {
it('queries for the correct host', async () => {
const hostID = 'f757d3c0-e874-11ea-9ad9-015510b487f4';
const query = getESQueryPolicyResponseByHostID(hostID, 'anyindex');
expect(query.body.query.bool.filter.term).toEqual({ 'host.id': hostID });
});

it('filters out initial policy by ID', async () => {
const query = getESQueryPolicyResponseByHostID(
'f757d3c0-e874-11ea-9ad9-015510b487f4',
'anyindex'
);
expect(query.body.query.bool.must_not.term).toEqual({
'Endpoint.policy.applied.id': '00000000-0000-0000-0000-000000000000',
});
});
});

0 comments on commit 53dfce5

Please sign in to comment.