From 91fc991a7930ae4b4fc458652b800a12324d6eab Mon Sep 17 00:00:00 2001 From: Andrew Thauer <6507159+andrewthauer@users.noreply.github.com> Date: Thu, 28 Jan 2021 06:07:02 -0500 Subject: [PATCH] add entity link schema validation policy --- .../policies/SchemaValidEntityPolicy.test.ts | 22 +++++++++++++++++++ .../policies/SchemaValidEntityPolicy.ts | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.test.ts b/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.test.ts index d63ba49dbe..23289d83aa 100644 --- a/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.test.ts +++ b/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.test.ts @@ -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 // diff --git a/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts b/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts index 4ff73e9a49..ed49bea526 100644 --- a/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts +++ b/packages/catalog-model/src/entity/policies/SchemaValidEntityPolicy.ts @@ -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>().notRequired(), annotations: yup.object>().notRequired(), tags: yup.array().notRequired(), + links: yup.array().notRequired(), }) .required(), spec: yup.object({}).notRequired(),