add entity link schema validation policy
This commit is contained in:
@@ -39,6 +39,10 @@ describe('SchemaValidEntityPolicy', () => {
|
||||
tags:
|
||||
- java
|
||||
- data
|
||||
links:
|
||||
- url: https://example.com
|
||||
title: Website
|
||||
icon: website
|
||||
spec:
|
||||
custom: stuff
|
||||
`);
|
||||
@@ -198,6 +202,24 @@ describe('SchemaValidEntityPolicy', () => {
|
||||
await expect(policy.enforce(data)).rejects.toThrow(/tags/);
|
||||
});
|
||||
|
||||
it('accepts missing links', async () => {
|
||||
delete data.metadata.links;
|
||||
await expect(policy.enforce(data)).resolves.toBe(data);
|
||||
});
|
||||
|
||||
it('accepts empty links array', async () => {
|
||||
data.metadata.links = [];
|
||||
await expect(policy.enforce(data)).resolves.toBe(data);
|
||||
});
|
||||
|
||||
it.each([['invalid type'], [123], [{}], [{ url: 'https://foo' }]])(
|
||||
'rejects bad links type %s',
|
||||
async (val: any) => {
|
||||
data.metadata.links = val;
|
||||
await expect(policy.enforce(data)).rejects.toThrow(/links/);
|
||||
},
|
||||
);
|
||||
|
||||
//
|
||||
// spec
|
||||
//
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import * as yup from 'yup';
|
||||
import { EntityPolicy } from '../../types';
|
||||
import { Entity } from '../Entity';
|
||||
import { Entity, EntityLink } from '../Entity';
|
||||
|
||||
const DEFAULT_ENTITY_SCHEMA = yup
|
||||
.object({
|
||||
@@ -33,6 +33,7 @@ const DEFAULT_ENTITY_SCHEMA = yup
|
||||
labels: yup.object<Record<string, string>>().notRequired(),
|
||||
annotations: yup.object<Record<string, string>>().notRequired(),
|
||||
tags: yup.array<string>().notRequired(),
|
||||
links: yup.array<EntityLink>().notRequired(),
|
||||
})
|
||||
.required(),
|
||||
spec: yup.object({}).notRequired(),
|
||||
|
||||
Reference in New Issue
Block a user