Skip to content

Commit 93079c5

Browse files
committed
Added tests for getSchemaEntries module
1 parent d0c7f5e commit 93079c5

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as core from '@actions/core';
2+
import { getSchemaEntries } from '../../src/utils/getSchemaEntries';
3+
4+
afterEach(() => {
5+
jest.restoreAllMocks();
6+
});
7+
8+
it(`Should find both color and category entries`, () => {
9+
const color_schema_unit = {
10+
type: 'text',
11+
name: 'Color'
12+
} as const,
13+
category_schema_unit = {
14+
type: 'multi_select',
15+
name: 'Category',
16+
options: []
17+
} as any;
18+
const [category_schema_entry, color_schema_entry] = getSchemaEntries({
19+
color: color_schema_unit,
20+
category: category_schema_unit
21+
});
22+
23+
expect(category_schema_entry).toStrictEqual([
24+
'category',
25+
category_schema_unit
26+
]);
27+
28+
expect(color_schema_entry).toStrictEqual(['color', color_schema_unit]);
29+
});
30+
31+
it(`Should not find both color and category entries`, () => {
32+
const color_schema_unit = {
33+
type: 'text',
34+
name: 'color'
35+
} as const,
36+
category_schema_unit = {
37+
type: 'multi_select',
38+
name: 'category',
39+
options: []
40+
} as any;
41+
const setFailedMock = jest.spyOn(core, 'setFailed');
42+
43+
const [category_schema_entry, color_schema_entry] = getSchemaEntries({
44+
color: color_schema_unit,
45+
category: category_schema_unit
46+
});
47+
48+
expect(setFailedMock).toHaveBeenNthCalledWith(
49+
1,
50+
"Couldn't find Category named multi_select type column in the database"
51+
);
52+
expect(setFailedMock).toHaveBeenNthCalledWith(
53+
2,
54+
"Couldn't find Color named text type column in the database"
55+
);
56+
expect(category_schema_entry).toStrictEqual(undefined);
57+
expect(color_schema_entry).toStrictEqual(undefined);
58+
});

0 commit comments

Comments
 (0)