From 4d910d176fca69b234d32af87c098fe5a2e18bf0 Mon Sep 17 00:00:00 2001 From: Alex McKay Date: Fri, 29 Mar 2024 14:11:50 -0400 Subject: [PATCH] add unit test Signed-off-by: Alex McKay --- .../EntitySwitch/conditions.test.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/plugins/catalog/src/components/EntitySwitch/conditions.test.ts b/plugins/catalog/src/components/EntitySwitch/conditions.test.ts index 66408aec18..363ce772cb 100644 --- a/plugins/catalog/src/components/EntitySwitch/conditions.test.ts +++ b/plugins/catalog/src/components/EntitySwitch/conditions.test.ts @@ -20,6 +20,7 @@ import { isKind, isNamespace, isResourceType, + isApiType, isEntityWith, } from './conditions'; @@ -65,6 +66,27 @@ const notComponent: Entity = { spec: { type: 'service' }, }; +const graphqlApi: Entity = { + apiVersion: '', + kind: 'api', + metadata: { name: 'aProtocol' }, + spec: { type: 'graphql' }, +}; + +const grpcApi: Entity = { + apiVersion: '', + kind: 'api', + metadata: { name: 'aProtocol' }, + spec: { type: 'grpc' }, +}; + +const notApi: Entity = { + apiVersion: '', + kind: 'not-api', + metadata: { name: 'aProtocol' }, + spec: { type: 'grpc' }, +}; + const missingSpecType: Entity = { apiVersion: '', kind: 'another-type', @@ -133,6 +155,26 @@ describe('isComponentType', () => { }); }); +describe('isApiType', () => { + it('should false on non API kinds', () => { + const checkEntity = isApiType('openapi'); + + expect(checkEntity(notApi)).not.toBeTruthy(); + }); + it('should check for the intended type', () => { + const checkEntity = isApiType('grpc'); + + expect(checkEntity(graphqlApi)).not.toBeTruthy(); + expect(checkEntity(grpcApi)).toBeTruthy(); + }); + it('should check for multiple types', () => { + const checkEntity = isApiType(['grpc', 'graphql']); + + expect(checkEntity(graphqlApi)).toBeTruthy(); + expect(checkEntity(grpcApi)).toBeTruthy(); + }); +}); + describe('isEntityWith', () => { it('allows for a kind-only check (empty type array)', () => { const checkEntity = isEntityWith({ kind: 'api', type: [] });