]>
git.r.bdr.sh - rbdr/forum/blob - src/stores/forums.test.js
1 import { GraphQLInteraction
, Pact
, Matchers
} from '@pact-foundation/pact';
2 import { resolve
} from 'path';
4 import { resolveAfter
} from '$/utils/resolve_after';
6 const { eachLike
, like
} = Matchers
;
8 jest
.mock('$/config/config.js');
10 import { getForum
, getForums
} from './forums';
16 describe('Forums store pact', () => {
18 beforeAll(async () => {
20 internals
.provider
= new Pact({
22 dir: resolve(process
.cwd(), 'pacts'),
23 consumer: 'ForumsStore',
24 provider: 'ForumAPIServer'
27 await internals
.provider
.setup();
30 afterEach(() => internals
.provider
.verify());
31 afterAll(() => internals
.provider
.finalize());
33 describe('GetForums', () => {
35 beforeAll(async () => {
37 const forumQuery
= new GraphQLInteraction()
38 .uponReceiving('a request to list the forums')
43 .withOperation('GetForums')
59 'Content-Type': 'application/json; charset=utf-8'
66 label: like('test_forums.butter'),
72 return await internals
.provider
.addInteraction(forumQuery
);
75 test('it returns the forums', async () => {
77 const forums
= getForums();
78 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
80 forums
.subscribe((forumsValue
) => {
82 response
= forumsValue
;
85 expect(response
.data
).toEqual(expect
.arrayContaining([]));
86 expect(response
.loading
).toBe(true);
87 expect(response
.error
).toBe(undefined);
88 await resolveAfterTwo
;
89 expect(response
.data
).toEqual(expect
.arrayContaining([{
92 label: 'test_forums.butter',
95 expect(response
.loading
).toBe(false);
96 expect(response
.error
).toBe(undefined);
100 describe('GetForum', () => {
102 beforeAll(async () => {
104 const forumQuery
= new GraphQLInteraction()
105 .uponReceiving('a request to get a single forum')
110 .withOperation('GetForum')
112 `query GetForum($id: ID!) {
135 'Content-Type': 'application/json; charset=utf-8'
142 label: like('test_forums.freezer'),
145 id: like('629de02c-151a-4db7-bb86-43b2add8a15a'),
146 title: like('Very pacty topic'),
147 updated_at: like(1619954611616),
154 return await internals
.provider
.addInteraction(forumQuery
);
157 test('it returns the forum', async () => {
159 const forum
= getForum('freezer');
160 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
162 forum
.subscribe((forumsValue
) => {
164 response
= forumsValue
;
167 expect(response
.data
).toEqual(expect
.arrayContaining([]));
168 expect(response
.loading
).toBe(true);
169 expect(response
.error
).toBe(undefined);
170 await resolveAfterTwo
;
171 expect(response
.data
.id
).toBe('freezer');
172 expect(response
.data
.glyph
).toBe('✭');
173 expect(response
.data
.label
).toBe('test_forums.freezer');
174 expect(response
.data
.position
).toBe(3);
175 expect(response
.data
.topics
).toEqual(expect
.arrayContaining([{
176 id: '629de02c-151a-4db7-bb86-43b2add8a15a',
177 title: 'Very pacty topic',
178 updated_at: 1619954611616,
181 expect(response
.loading
).toBe(false);
182 expect(response
.error
).toBe(undefined);