add unit test

Signed-off-by: Alex McKay <amckay@spotify.com>
This commit is contained in:
Alex McKay
2024-03-29 14:11:50 -04:00
parent 18c7f12f39
commit 4d910d176f
@@ -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: [] });