Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 10 additions & 56 deletions x-pack/plugins/lists/common/schemas/common/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
EsDataTypeRangeTerm,
EsDataTypeSingle,
EsDataTypeUnion,
ExceptionListTypeEnum,
OperatorEnum,
Type,
esDataTypeGeoPoint,
esDataTypeGeoPointRange,
Expand All @@ -25,60 +27,10 @@ import {
esDataTypeUnion,
exceptionListType,
operator,
operator_type as operatorType,
type,
} from './schemas';

describe('Common schemas', () => {
describe('operatorType', () => {
test('it should validate for "match"', () => {
const payload = 'match';
const decoded = operatorType.decode(payload);
const message = pipe(decoded, foldLeftRight);

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

test('it should validate for "match_any"', () => {
const payload = 'match_any';
const decoded = operatorType.decode(payload);
const message = pipe(decoded, foldLeftRight);

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

test('it should validate for "list"', () => {
const payload = 'list';
const decoded = operatorType.decode(payload);
const message = pipe(decoded, foldLeftRight);

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

test('it should validate for "exists"', () => {
const payload = 'exists';
const decoded = operatorType.decode(payload);
const message = pipe(decoded, foldLeftRight);

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

test('it should contain 4 keys', () => {
// Might seem like a weird test, but its meant to
// ensure that if operatorType is updated, you
// also update the OperatorTypeEnum, a workaround
// for io-ts not yet supporting enums
// https://github.com/gcanti/io-ts/issues/67
const keys = Object.keys(operatorType.keys);

expect(keys.length).toEqual(4);
});
});

describe('operator', () => {
test('it should validate for "included"', () => {
const payload = 'included';
Expand All @@ -98,15 +50,16 @@ describe('Common schemas', () => {
expect(message.schema).toEqual(payload);
});

test('it should contain 2 keys', () => {
test('it should contain same amount of keys as enum', () => {
// Might seem like a weird test, but its meant to
// ensure that if operator is updated, you
// also update the operatorEnum, a workaround
// for io-ts not yet supporting enums
// https://github.com/gcanti/io-ts/issues/67
const keys = Object.keys(operator.keys);
const keys = Object.keys(operator.keys).sort().join(',').toLowerCase();
const enumKeys = Object.keys(OperatorEnum).sort().join(',').toLowerCase();

expect(keys.length).toEqual(2);
expect(keys).toEqual(enumKeys);
});
});

Expand All @@ -129,15 +82,16 @@ describe('Common schemas', () => {
expect(message.schema).toEqual(payload);
});

test('it should contain 2 keys', () => {
test('it should contain same amount of keys as enum', () => {
// Might seem like a weird test, but its meant to
// ensure that if exceptionListType is updated, you
// also update the ExceptionListTypeEnum, a workaround
// for io-ts not yet supporting enums
// https://github.com/gcanti/io-ts/issues/67
const keys = Object.keys(exceptionListType.keys);
const keys = Object.keys(exceptionListType.keys).sort().join(',').toLowerCase();
const enumKeys = Object.keys(ExceptionListTypeEnum).sort().join(',').toLowerCase();

expect(keys.length).toEqual(2);
expect(keys).toEqual(enumKeys);
});
});

Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/lists/common/schemas/common/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,6 @@ export enum OperatorEnum {
EXCLUDED = 'excluded',
}

export const operator_type = t.keyof({
exists: null,
list: null,
match: null,
match_any: null,
});
export type OperatorType = t.TypeOf<typeof operator_type>;
export enum OperatorTypeEnum {
NESTED = 'nested',
MATCH = 'match',
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/lists/common/shared_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export {
NamespaceType,
Operator,
OperatorEnum,
OperatorType,
OperatorTypeEnum,
ExceptionListTypeEnum,
comment,
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/security_solution/common/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export {
NamespaceType,
Operator,
OperatorEnum,
OperatorType,
OperatorTypeEnum,
ExceptionListTypeEnum,
exceptionListItemSchema,
Expand Down