Skip to content

Commit

Permalink
test: add tests and exclude packages path
Browse files Browse the repository at this point in the history
  • Loading branch information
dweber019 committed Mar 31, 2024
1 parent a284ddb commit 98ef6ce
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@
"prettier --write"
]
},
"packageManager": "yarn@3.2.4"
"packageManager": "yarn@3.2.4",
"jest": {
"testPathIgnorePatterns": [
"packages"
]
}
}
128 changes: 128 additions & 0 deletions plugins/accentuate/src/api/AccentuateClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { AccentuateClient, JsonSchema } from '../api';
import { schemas } from '../schemas';
import * as componentSchema from '../schemas/Component.v1alpha1.schema.json';

describe('AccentuateClient', () => {
test('should return schema when kind found', async () => {
const accentuateClient = new AccentuateClient({
catalogApi: null as any,
fetchApi: null as any,
discoveryApi: null as any,
identityApi: null as any,
schemas: schemas,
});

const entity = {
kind: 'Component',
spec: {
type: 'service',
},
} as unknown as any;

const result = accentuateClient.getSchema(entity);

expect(result!.schema).toMatchObject(componentSchema);
});

test('should return undefined if schema not found', async () => {
const accentuateClient = new AccentuateClient({
catalogApi: null as any,
fetchApi: null as any,
discoveryApi: null as any,
identityApi: null as any,
schemas: schemas,
});

const entity = {
kind: 'Foo',
spec: {
type: 'service',
},
} as unknown as any;

const result = accentuateClient.getSchema(entity);

expect(result).toBeUndefined();
});

test('should return specific schema for type', async () => {
const specificSchema = {
kind: 'Component',
type: 'service',
schema: 'found',
uiSchema: undefined,
} as unknown as JsonSchema;
const accentuateClient = new AccentuateClient({
catalogApi: null as any,
fetchApi: null as any,
discoveryApi: null as any,
identityApi: null as any,
schemas: [...schemas, specificSchema],
});

const entity = {
kind: 'Component',
spec: {
type: 'service',
},
} as unknown as any;

const result = accentuateClient.getSchema(entity);

expect(result?.schema).toEqual('found');
});

test('should return specific schema for type case insensitive', async () => {
const specificSchema = {
kind: 'Component',
type: 'SERVICE',
schema: 'found',
uiSchema: undefined,
} as unknown as JsonSchema;
const accentuateClient = new AccentuateClient({
catalogApi: null as any,
fetchApi: null as any,
discoveryApi: null as any,
identityApi: null as any,
schemas: [...schemas, specificSchema],
});

const entity = {
kind: 'Component',
spec: {
type: 'service',
},
} as unknown as any;

const result = accentuateClient.getSchema(entity);

expect(result?.schema).toEqual('found');
});

test('should return general schema if not matching type', async () => {
const specificSchema = {
kind: 'Component',
type: 'other',
schema: 'found',
uiSchema: undefined,
} as unknown as JsonSchema;
const accentuateClient = new AccentuateClient({
catalogApi: null as any,
fetchApi: null as any,
discoveryApi: null as any,
identityApi: null as any,
schemas: [...schemas, specificSchema],
});

const entity = {
kind: 'Component',
spec: {
type: 'service',
},
} as unknown as any;

const result = accentuateClient.getSchema(entity);

expect(result!.schema).toMatchObject(componentSchema);
});
});

0 comments on commit 98ef6ce

Please sign in to comment.