Add subcomponentOf field to Component spec

This commit is contained in:
James Turley
2021-01-12 14:22:25 +00:00
parent fb1b2f6079
commit eeb6f3ba93
2 changed files with 18 additions and 0 deletions
@@ -33,6 +33,7 @@ describe('ComponentV1alpha1Validator', () => {
type: 'service',
lifecycle: 'production',
owner: 'me',
subcomponentOf: 'monolith',
providesApis: ['api-0'],
consumesApis: ['api-0'],
},
@@ -103,6 +104,21 @@ describe('ComponentV1alpha1Validator', () => {
await expect(validator.check(entity)).rejects.toThrow(/owner/);
});
it('accepts missing subcomponentOf', async () => {
delete (entity as any).spec.subcomponentOf;
await expect(validator.check(entity)).resolves.toBe(true);
});
it('rejects wrong subcomponentOf', async () => {
(entity as any).spec.subcomponentOf = 7;
await expect(validator.check(entity)).rejects.toThrow(/subcomponentOf/);
});
it('rejects empty subcomponentOf', async () => {
(entity as any).spec.subcomponentOf = '';
await expect(validator.check(entity)).rejects.toThrow(/subcomponentOf/);
});
it('accepts missing providesApis', async () => {
delete (entity as any).spec.providesApis;
await expect(validator.check(entity)).resolves.toBe(true);
@@ -29,6 +29,7 @@ const schema = yup.object<Partial<ComponentEntityV1alpha1>>({
type: yup.string().required().min(1),
lifecycle: yup.string().required().min(1),
owner: yup.string().required().min(1),
subcomponentOf: yup.string().notRequired().min(1),
providesApis: yup.array(yup.string().required()).notRequired(),
consumesApis: yup.array(yup.string().required()).notRequired(),
})
@@ -42,6 +43,7 @@ export interface ComponentEntityV1alpha1 extends Entity {
type: string;
lifecycle: string;
owner: string;
subcomponentOf?: string;
providesApis?: string[];
consumesApis?: string[];
};