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
96
97
98
99
100
101
|
import { GraphQLInteraction, Pact, Matchers } from '@pact-foundation/pact';
import { resolve } from 'path';
import { resolveAfter } from '$/utils/resolve_after';
import { act } from '@testing-library/svelte';
const { eachLike, like } = Matchers;
jest.mock('$/config/config.js');
import { getForums } from './forums';
const internals = {
provider: null
};
describe('Forum store pact', () => {
beforeAll(async () => {
internals.provider = new Pact({
port: 1234,
dir: resolve(process.cwd(), 'pacts'),
consumer: 'ForumsStore',
provider: 'ForumAPIServer'
});
await internals.provider.setup();
});
afterEach(() => internals.provider.verify());
afterAll(() => internals.provider.finalize());
describe('there are forums', () => {
beforeAll(async () => {
const forumQuery = new GraphQLInteraction()
.uponReceiving('a request to list the forums')
.withRequest({
path: '/graphql',
method: 'POST'
})
.withOperation('GetForums')
.withQuery(
`query GetForums {
forums {
id
glyph
label
position
__typename
}
}`
)
.withVariables({})
.willRespondWith({
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
body: {
data: {
forums: eachLike({
id: like('butter'),
glyph: like('⌘'),
label: like('test_forums.butter'),
position: like(1)
})
}
}
});
return await internals.provider.addInteraction(forumQuery);
});
test('it returns the forums', async () => {
const forums = getForums();
const { counter, promise: resolveAfterTwo } = resolveAfter(2);
let response = null;
forums.subscribe((forumsValue) => {
response = forumsValue;
counter();
});
expect(response.data).toEqual(expect.arrayContaining([]));
expect(response.loading).toBe(true);
expect(response.error).toBe(undefined);
await resolveAfterTwo;
expect(response.data).toEqual(expect.arrayContaining([{
id: 'butter',
glyph: '⌘',
label: 'test_forums.butter',
position: 1
}]));
expect(response.loading).toBe(false);
expect(response.error).toBe(undefined);
});
});
});
|