-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetSchemaEntries.test.ts
90 lines (82 loc) · 2.25 KB
/
getSchemaEntries.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as core from '@actions/core';
import {
SelectSchemaUnit,
TextSchemaUnit,
TitleSchemaUnit
} from '@nishans/types';
import { getSchemaEntries } from '../../src/utils/getSchemaEntries';
afterEach(() => {
jest.restoreAllMocks();
});
it(`Should find both color and category entries`, () => {
const color_schema_unit = {
type: 'text',
name: 'Color'
} as TextSchemaUnit,
category_schema_unit = {
type: 'select',
name: 'Category',
options: []
} as SelectSchemaUnit,
title_schema_unit = {
type: 'title',
name: 'Name',
options: []
} as TitleSchemaUnit;
const [
category_schema_entry,
color_schema_entry,
title_schema_entry
] = getSchemaEntries({
color: color_schema_unit,
category: category_schema_unit,
title: title_schema_unit
});
expect(category_schema_entry).toStrictEqual([
'category',
category_schema_unit
]);
expect(title_schema_entry).toStrictEqual(['title', title_schema_unit]);
expect(color_schema_entry).toStrictEqual(['color', color_schema_unit]);
});
it(`Should not find both color, title, category entries`, () => {
const color_schema_unit = {
type: 'text',
name: 'color'
} as TextSchemaUnit,
category_schema_unit = {
type: 'select',
name: 'category',
options: []
} as SelectSchemaUnit,
title_schema_unit = {
type: 'title',
name: 'name',
options: []
} as TitleSchemaUnit;
const setFailedMock = jest.spyOn(core, 'setFailed');
const [
category_schema_entry,
color_schema_entry,
title_schema_entry
] = getSchemaEntries({
color: color_schema_unit,
category: category_schema_unit,
title: title_schema_unit
});
expect(setFailedMock).toHaveBeenNthCalledWith(
1,
"Couldn't find Category named select type column in the database"
);
expect(setFailedMock).toHaveBeenNthCalledWith(
2,
"Couldn't find Color named text type column in the database"
);
expect(setFailedMock).toHaveBeenNthCalledWith(
3,
"Couldn't find Name named title type column in the database"
);
expect(category_schema_entry).toStrictEqual(undefined);
expect(color_schema_entry).toStrictEqual(undefined);
expect(title_schema_entry).toStrictEqual(undefined);
});