-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Improve runtime mappings validation.
- Loading branch information
Showing
4 changed files
with
75 additions
and
6 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
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
51 changes: 51 additions & 0 deletions
51
...ransform/public/app/sections/create_transform/components/step_define/common/types.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,51 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { isRuntimeField, isRuntimeMappings } from './types'; | ||
|
||
describe('Transform: step_define type guards', () => { | ||
it('isRuntimeField()', () => { | ||
expect(isRuntimeField(1)).toBe(false); | ||
expect(isRuntimeField(null)).toBe(false); | ||
expect(isRuntimeField([])).toBe(false); | ||
expect(isRuntimeField({})).toBe(false); | ||
expect(isRuntimeField({ someAttribute: 'someValue' })).toBe(false); | ||
expect(isRuntimeField({ type: 'wrong-type' })).toBe(false); | ||
expect(isRuntimeField({ type: 'keyword', someAttribute: 'some value' })).toBe(false); | ||
|
||
expect(isRuntimeField({ type: 'keyword' })).toBe(true); | ||
expect(isRuntimeField({ type: 'keyword', script: 'some script' })).toBe(true); | ||
}); | ||
|
||
it('isRuntimeMappings()', () => { | ||
expect(isRuntimeMappings(1)).toBe(false); | ||
expect(isRuntimeMappings(null)).toBe(false); | ||
expect(isRuntimeMappings([])).toBe(false); | ||
expect(isRuntimeMappings({})).toBe(false); | ||
expect(isRuntimeMappings({ someAttribute: 'someValue' })).toBe(false); | ||
expect(isRuntimeMappings({ fieldName1: { type: 'keyword' }, fieldName2: 'someValue' })).toBe( | ||
false | ||
); | ||
expect( | ||
isRuntimeMappings({ | ||
fieldName1: { type: 'keyword' }, | ||
fieldName2: { type: 'keyword', someAttribute: 'some value' }, | ||
}) | ||
).toBe(false); | ||
|
||
expect(isRuntimeMappings({ fieldName: { type: 'keyword' } })).toBe(true); | ||
expect( | ||
isRuntimeMappings({ fieldName1: { type: 'keyword' }, fieldName2: { type: 'keyword' } }) | ||
).toBe(true); | ||
expect( | ||
isRuntimeMappings({ | ||
fieldName1: { type: 'keyword' }, | ||
fieldName2: { type: 'keyword', script: 'some script' }, | ||
}) | ||
).toBe(true); | ||
}); | ||
}); |
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