-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds point in time finder methods and functions
- Loading branch information
1 parent
6468a6c
commit b39c95a
Showing
19 changed files
with
927 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/kbn-securitysolution-io-ts-list-types/src/common/max_size/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { exactCheck } from '@kbn/securitysolution-io-ts-utils'; | ||
import { maxSizeOrUndefined } from '.'; | ||
|
||
import { pipe } from 'fp-ts/lib/pipeable'; | ||
import { left } from 'fp-ts/lib/Either'; | ||
|
||
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; | ||
|
||
describe('maxSizeOrUndefined', () => { | ||
test('it will validate a correct max value', () => { | ||
const payload = 123; | ||
const decoded = maxSizeOrUndefined.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([]); | ||
expect(message.schema).toEqual(payload); | ||
}); | ||
|
||
test('it will fail to validate a 0', () => { | ||
const payload = 0; | ||
const decoded = maxSizeOrUndefined.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "0" supplied to "(PositiveIntegerGreaterThanZero | undefined)"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it will fail to validate a -1', () => { | ||
const payload = -1; | ||
const decoded = maxSizeOrUndefined.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "-1" supplied to "(PositiveIntegerGreaterThanZero | undefined)"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
|
||
test('it will fail to validate a string', () => { | ||
const payload = '123'; | ||
const decoded = maxSizeOrUndefined.decode(payload); | ||
const checked = exactCheck(payload, decoded); | ||
const message = pipe(checked, foldLeftRight); | ||
expect(getPaths(left(message.errors))).toEqual([ | ||
'Invalid value "123" supplied to "(PositiveIntegerGreaterThanZero | undefined)"', | ||
]); | ||
expect(message.schema).toEqual({}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/kbn-securitysolution-io-ts-list-types/src/common/max_size/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types'; | ||
import * as t from 'io-ts'; | ||
|
||
export const max_size = PositiveIntegerGreaterThanZero; | ||
export type MaxSize = t.TypeOf<typeof max_size>; | ||
|
||
export const maxSizeOrUndefined = t.union([max_size, t.undefined]); | ||
export type MaxSizeOrUndefined = t.TypeOf<typeof maxSizeOrUndefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.