mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
log an invalid type for SO (#115175)
This commit is contained in:
parent
e18afaa45d
commit
852c5dd205
2 changed files with 50 additions and 2 deletions
|
@ -491,6 +491,52 @@ describe('#rawToSavedObject', () => {
|
|||
expect(actual).toHaveProperty('namespaces', ['baz']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('throws if provided invalid type', () => {
|
||||
expect(() =>
|
||||
singleNamespaceSerializer.rawToSavedObject({
|
||||
_id: 'foo:bar',
|
||||
_source: {
|
||||
// @ts-expect-error expects a string
|
||||
// eslint-disable-next-line
|
||||
type: new String('foo'),
|
||||
},
|
||||
})
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Expected saved object type to be a string but given [String] with [foo] value."`
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
singleNamespaceSerializer.rawToSavedObject({
|
||||
_id: 'foo:bar',
|
||||
_source: {
|
||||
// @ts-expect-error expects astring
|
||||
type: {
|
||||
toString() {
|
||||
return 'foo';
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Expected saved object type to be a string but given [Object] with [foo] value."`
|
||||
);
|
||||
});
|
||||
|
||||
describe('throws if provided invalid id', () => {
|
||||
expect(() =>
|
||||
singleNamespaceSerializer.rawToSavedObject({
|
||||
// @ts-expect-error expects a string
|
||||
// eslint-disable-next-line
|
||||
_id: new String('foo:bar'),
|
||||
_source: {
|
||||
type: 'foo',
|
||||
},
|
||||
})
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Expected document id to be a string but given [String] with [foo:bar] value."`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#savedObjectToRaw', () => {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import typeDetect from 'type-detect';
|
||||
import { LEGACY_URL_ALIAS_TYPE } from '../object_types';
|
||||
import { decodeVersion, encodeVersion } from '../version';
|
||||
import { ISavedObjectTypeRegistry } from '../saved_objects_type_registry';
|
||||
|
@ -236,6 +236,8 @@ function checkIdMatchesPrefix(id: string, prefix: string) {
|
|||
|
||||
function assertNonEmptyString(value: string, name: string) {
|
||||
if (!value || typeof value !== 'string') {
|
||||
throw new TypeError(`Expected "${value}" to be a ${name}`);
|
||||
throw new TypeError(
|
||||
`Expected ${name} to be a string but given [${typeDetect(value)}] with [${value}] value.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue