-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathprompts.ts
95 lines (87 loc) · 2 KB
/
prompts.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
91
92
93
94
95
import { DataSource } from 'typeorm';
import createOrGetConnection from '../src/db';
import {
disposeGraphQLTesting,
GraphQLTestClient,
GraphQLTestingState,
initializeGraphQLTesting,
MockContext,
} from './helpers';
import { Prompt } from '../src/entity/Prompt';
let con: DataSource;
let state: GraphQLTestingState;
let client: GraphQLTestClient;
let loggedUser: string = null;
beforeAll(async () => {
con = await createOrGetConnection();
state = await initializeGraphQLTesting(
() => new MockContext(con, loggedUser),
);
client = state.client;
});
afterAll(() => disposeGraphQLTesting(state));
beforeEach(async () => {
loggedUser = null;
await con.getRepository(Prompt).save([
{
id: 'prompt1',
order: 1,
label: 'label1',
description: 'description1',
prompt: 'prompt1',
flags: { icon: 'icon1', color: 'color1' },
},
{
id: 'prompt2',
order: 2,
label: 'label2',
description: 'description2',
prompt: 'prompt2',
flags: { icon: 'icon2', color: 'color2' },
},
{
id: 'prompt3',
order: 3,
label: 'label3',
description: 'description3',
prompt: 'prompt3',
flags: { icon: 'icon3', color: 'color3' },
},
]);
});
describe('query prompts', () => {
const QUERY = `{
prompts {
id
label
description
flags {
icon
color
}
}
}`;
it('should return all prompts in order', async () => {
const res = await client.query(QUERY);
expect(res.data.prompts).toEqual([
{
id: 'prompt1',
label: 'label1',
description: 'description1',
flags: { icon: 'icon1', color: 'color1' },
},
{
id: 'prompt2',
label: 'label2',
description: 'description2',
flags: { icon: 'icon2', color: 'color2' },
},
{
id: 'prompt3',
label: 'label3',
description: 'description3',
flags: { icon: 'icon3', color: 'color3' },
},
]);
});
});