Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhristinin committed Aug 25, 2021
1 parent e3efe4e commit 70b1cbf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,6 @@ describe('create rules schema', () => {
expect(message.schema).toEqual({});
});

test('saved_query type can have filters with it', () => {
const payload: SavedQueryCreateSchema = {
...getCreateSavedQueryRulesSchemaMock(),
filters: [],
};

const decoded = createRulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('filters cannot be a string', () => {
const payload = {
...getCreateRulesSchemaMock(),
Expand Down Expand Up @@ -1013,16 +1000,14 @@ describe('create rules schema', () => {
expect(message.schema).toEqual(payload);
});

test('saved_id is required when type is saved_query and will not validate without it', () => {
test('saved_id is not required when type is saved_query and will validate without it', () => {
/* eslint-disable @typescript-eslint/naming-convention */
const { saved_id, ...payload } = getCreateSavedQueryRulesSchemaMock();
const decoded = createRulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "saved_id"',
]);
expect(message.schema).toEqual({});
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('threshold is required when type is threshold and will not validate without it', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
RulesSchema,
checkTypeDependents,
getDependents,
addSavedId,
addQueryFields,
addTimelineTitle,
addMlFields,
Expand Down Expand Up @@ -85,42 +84,25 @@ describe('rules_schema', () => {
expect(message.schema).toEqual({});
});

test('it should validate a type of "saved_query" with a "saved_id" dependent', () => {

test('it should validate a type of "saved_query" without a "saved_id" dependent', () => {
const payload = getRulesSchemaMock();
payload.type = 'saved_query';
payload.saved_id = 'save id 123';

const decoded = rulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
const expected = getRulesSchemaMock();

const expected = getRulesSchemaMock();
expected.type = 'saved_query';
expected.saved_id = 'save id 123';

expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(expected);
});

test('it should NOT validate a type of "saved_query" without a "saved_id" dependent', () => {
const payload = getRulesSchemaMock();
payload.type = 'saved_query';
delete payload.saved_id;

const decoded = rulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "saved_id"',
]);
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" when it has extra data', () => {
const payload: RulesSchema & { invalid_extra_data?: string } = getRulesSchemaMock();
payload.type = 'saved_query';
payload.saved_id = 'save id 123';
payload.invalid_extra_data = 'invalid_extra_data';

const decoded = rulesSchema.decode(payload);
Expand Down Expand Up @@ -187,35 +169,7 @@ describe('rules_schema', () => {
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_title" but there is NOT a "timeline_id"', () => {
const payload = getRulesSchemaMock();
payload.saved_id = 'some saved id';
payload.type = 'saved_query';
payload.timeline_title = 'some timeline title';

const decoded = rulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual(['invalid keys "timeline_title"']);
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_id" but there is NOT a "timeline_title"', () => {
const payload = getRulesSchemaMock();
payload.saved_id = 'some saved id';
payload.type = 'saved_query';
payload.timeline_id = 'some timeline id';

const decoded = rulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "timeline_title"',
]);
expect(message.schema).toEqual({});
});


describe('checkTypeDependents', () => {
test('it should validate a type of "query" without anything extra', () => {
Expand Down Expand Up @@ -257,42 +211,24 @@ describe('rules_schema', () => {
expect(message.schema).toEqual({});
});

test('it should validate a type of "saved_query" with a "saved_id" dependent', () => {
test('it should validate a type of "saved_query" without a "saved_id" dependent', () => {
const payload = getRulesSchemaMock();
payload.type = 'saved_query';
payload.saved_id = 'save id 123';

const decoded = checkTypeDependents(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
const expected = getRulesSchemaMock();

expected.type = 'saved_query';
expected.saved_id = 'save id 123';

expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(expected);
});

test('it should NOT validate a type of "saved_query" without a "saved_id" dependent', () => {
const payload = getRulesSchemaMock();
payload.type = 'saved_query';
delete payload.saved_id;

const decoded = checkTypeDependents(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "saved_id"',
]);
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" when it has extra data', () => {
const payload: RulesSchema & { invalid_extra_data?: string } = getRulesSchemaMock();
payload.type = 'saved_query';
payload.saved_id = 'save id 123';
payload.invalid_extra_data = 'invalid_extra_data';

const decoded = checkTypeDependents(payload);
Expand Down Expand Up @@ -358,36 +294,6 @@ describe('rules_schema', () => {
expect(getPaths(left(message.errors))).toEqual(['invalid keys "timeline_title"']);
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_title" but there is NOT a "timeline_id"', () => {
const payload = getRulesSchemaMock();
payload.saved_id = 'some saved id';
payload.type = 'saved_query';
payload.timeline_title = 'some timeline title';

const decoded = checkTypeDependents(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual(['invalid keys "timeline_title"']);
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_id" but there is NOT a "timeline_title"', () => {
const payload = getRulesSchemaMock();
payload.saved_id = 'some saved id';
payload.type = 'saved_query';
payload.timeline_id = 'some timeline id';

const decoded = checkTypeDependents(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "timeline_title"',
]);
expect(message.schema).toEqual({});
});
});

describe('getDependents', () => {
Expand Down Expand Up @@ -433,25 +339,8 @@ describe('rules_schema', () => {
expect(message.schema).toEqual({});
});

test('it should validate a type of "saved_query" with a "saved_id" dependent', () => {
const payload = getRulesSchemaMock();
payload.type = 'saved_query';
payload.saved_id = 'save id 123';

const dependents = getDependents(payload);
const decoded = dependents.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
const expected = getRulesSchemaMock();

expected.type = 'saved_query';
expected.saved_id = 'save id 123';

expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(expected);
});

test('it should NOT validate a type of "saved_query" without a "saved_id" dependent', () => {
test('it should validate a type of "saved_query" without a "saved_id" dependent', () => {
const payload = getRulesSchemaMock();
payload.type = 'saved_query';
delete payload.saved_id;
Expand All @@ -461,16 +350,13 @@ describe('rules_schema', () => {
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "saved_id"',
]);
expect(message.schema).toEqual({});
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('it should NOT validate a type of "saved_query" when it has extra data', () => {
const payload: RulesSchema & { invalid_extra_data?: string } = getRulesSchemaMock();
payload.type = 'saved_query';
payload.saved_id = 'save id 123';
payload.invalid_extra_data = 'invalid_extra_data';

const dependents = getDependents(payload);
Expand Down Expand Up @@ -542,20 +428,6 @@ describe('rules_schema', () => {
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_title" but there is NOT a "timeline_id"', () => {
const payload = getRulesSchemaMock();
payload.saved_id = 'some saved id';
payload.type = 'saved_query';
payload.timeline_title = 'some timeline title';

const decoded = checkTypeDependents(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual(['invalid keys "timeline_title"']);
expect(message.schema).toEqual({});
});

test('it should NOT validate a type of "saved_query" with a "saved_id" dependent and a "timeline_id" but there is NOT a "timeline_title"', () => {
const payload = getRulesSchemaMock();
payload.saved_id = 'some saved id';
Expand Down Expand Up @@ -645,18 +517,6 @@ describe('rules_schema', () => {
});
});

describe('addSavedId', () => {
test('should return empty array if not given a type of "saved_query"', () => {
const emptyArray = addSavedId({ type: 'query' });
const expected: t.Mixed[] = [];
expect(emptyArray).toEqual(expected);
});

test('should array of size 1 given a "saved_query"', () => {
const array = addSavedId({ type: 'saved_query' });
expect(array.length).toEqual(1);
});
});

describe('addTimelineTitle', () => {
test('should return empty array if not given a timeline_id', () => {
Expand Down Expand Up @@ -762,9 +622,9 @@ describe('rules_schema', () => {
expect(fields).toEqual(expected);
});

test('should return nine (9) fields for a rule of type "threat_match"', () => {
test('should return eight (8) fields for a rule of type "threat_match"', () => {
const fields = addThreatMatchFields({ type: 'threat_match' });
expect(fields.length).toEqual(9);
expect(fields.length).toEqual(8);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
created_at,
created_by,
updated_at,
saved_id,
timeline_id,
timeline_title,
threshold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('helpers', () => {
);
});

test('returns expected array of ListItems when "savedId" exists', () => {
test('returns empty array of ListItems when "savedId" exists', () => {
const mockQueryBarWithSavedId = {
...mockQueryBar,
query: '',
Expand All @@ -189,7 +189,7 @@ describe('helpers', () => {
query: mockQueryBarWithSavedId.query,
savedId: mockQueryBarWithSavedId.saved_id,
});
expect(result[0].description).toEqual(<>{mockQueryBarWithSavedId.saved_id} </>);
expect(result.length).toEqual(0);
});
});

Expand Down
Loading

0 comments on commit 70b1cbf

Please sign in to comment.