]>
git.r.bdr.sh - rbdr/forum/blob - src/stores/forums.test.js
e117828dddc1d1dcded15ae77db16ca459776332
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('When there\'s forums', () => {
35 describe('GetForums', () => {
37 beforeAll(async () => {
39 const forumQuery
= new GraphQLInteraction()
40 .given('there\'s forums')
41 .uponReceiving('a request to list the forums')
46 .withOperation('GetForums')
62 'Content-Type': 'application/json; charset=utf-8'
69 label: like('test_forums.butter'),
75 return await internals
.provider
.addInteraction(forumQuery
);
78 test('it returns the forums', async () => {
80 const forums
= getForums();
81 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
83 forums
.subscribe((forumsValue
) => {
85 response
= forumsValue
;
88 expect(response
.data
).toBeInstanceOf(Array
);
89 expect(response
.data
.length
).toBe(0);
90 expect(response
.loading
).toBe(true);
91 expect(response
.error
).toBe(undefined);
92 await resolveAfterTwo
;
93 expect(response
.data
).toEqual(expect
.arrayContaining([{
96 label: 'test_forums.butter',
99 expect(response
.loading
).toBe(false);
100 expect(response
.error
).toBe(undefined);
104 describe('GetForum', () => {
106 beforeAll(async () => {
108 const forumQuery
= new GraphQLInteraction()
109 .given('there\'s forums')
110 .uponReceiving('a request to get a single forum')
115 .withOperation('GetForum')
117 `query GetForum($id: ID!) {
140 'Content-Type': 'application/json; charset=utf-8'
147 label: like('test_forums.freezer'),
150 id: like('629de02c-151a-4db7-bb86-43b2add8a15a'),
151 title: like('Very pacty topic'),
152 updated_at: like(1619954611616),
159 return await internals
.provider
.addInteraction(forumQuery
);
162 test('it returns the forum', async () => {
164 const forum
= getForum('freezer');
165 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
167 forum
.subscribe((forumsValue
) => {
169 response
= forumsValue
;
172 expect(response
.data
).toBe(null);
173 expect(response
.loading
).toBe(true);
174 expect(response
.error
).toBe(undefined);
175 await resolveAfterTwo
;
176 expect(response
.data
.id
).toBe('freezer');
177 expect(response
.data
.glyph
).toBe('✭');
178 expect(response
.data
.label
).toBe('test_forums.freezer');
179 expect(response
.data
.position
).toBe(3);
180 expect(response
.data
.topics
).toEqual(expect
.arrayContaining([{
181 id: '629de02c-151a-4db7-bb86-43b2add8a15a',
182 title: 'Very pacty topic',
183 updated_at: 1619954611616,
186 expect(response
.loading
).toBe(false);
187 expect(response
.error
).toBe(undefined);
192 describe('When there\'s no forums', () => {
194 describe('GetForums', () => {
196 beforeAll(async () => {
198 const forumQuery
= new GraphQLInteraction()
199 .given('there\'s no forums')
200 .uponReceiving('a request to list the forums')
205 .withOperation('GetForums')
221 'Content-Type': 'application/json; charset=utf-8'
229 return await internals
.provider
.addInteraction(forumQuery
);
232 test('it returns the forums', async () => {
234 const forums
= getForums();
235 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
237 forums
.subscribe((forumsValue
) => {
239 response
= forumsValue
;
242 expect(response
.data
).toBeInstanceOf(Array
);
243 expect(response
.data
.length
).toBe(0);
244 expect(response
.loading
).toBe(true);
245 expect(response
.error
).toBe(undefined);
246 await resolveAfterTwo
;
247 expect(response
.data
).toBeInstanceOf(Array
);
248 expect(response
.data
.length
).toBe(0);
249 expect(response
.loading
).toBe(false);
250 expect(response
.error
).toBe(undefined);
254 describe('GetForum', () => {
256 beforeAll(async () => {
258 const forumQuery
= new GraphQLInteraction()
259 .given('there\'s no forums')
260 .uponReceiving('a request to get a single forum')
265 .withOperation('GetForum')
267 `query GetForum($id: ID!) {
290 'Content-Type': 'application/json; charset=utf-8'
298 return await internals
.provider
.addInteraction(forumQuery
);
301 test('it returns the forum', async () => {
303 const forum
= getForum('freezer');
304 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
306 forum
.subscribe((forumsValue
) => {
308 response
= forumsValue
;
311 expect(response
.data
).toBe(null);
312 expect(response
.loading
).toBe(true);
313 expect(response
.error
).toBe(undefined);
314 await resolveAfterTwo
;
315 expect(response
.data
).toBe(null);
316 expect(response
.loading
).toBe(false);
317 expect(response
.error
).toBe(undefined);
322 describe('When there\'s an error', () => {
324 describe('GetForums', () => {
326 beforeAll(async () => {
328 const forumQuery
= new GraphQLInteraction()
329 .given('there\'s an error')
330 .uponReceiving('a request to list the forums')
335 .withOperation('GetForums')
351 return await internals
.provider
.addInteraction(forumQuery
);
354 test('it returns the error', async () => {
356 const forums
= getForums();
357 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
359 forums
.subscribe((forumsValue
) => {
361 response
= forumsValue
;
364 expect(response
.data
).toBeInstanceOf(Array
);
365 expect(response
.data
.length
).toBe(0);
366 expect(response
.loading
).toBe(true);
367 expect(response
.error
).toBe(undefined);
368 await resolveAfterTwo
;
369 expect(response
.data
).toBeInstanceOf(Array
);
370 expect(response
.data
.length
).toBe(0);
371 expect(response
.loading
).toBe(false);
372 expect(response
.error
).toBeInstanceOf(Error
);
376 describe('GetForum', () => {
378 beforeAll(async () => {
380 const forumQuery
= new GraphQLInteraction()
381 .given('there\'s an error')
382 .uponReceiving('a request to get a single forum')
387 .withOperation('GetForum')
389 `query GetForum($id: ID!) {
412 return await internals
.provider
.addInteraction(forumQuery
);
415 test('it returns the error', async () => {
417 const forum
= getForum('freezer');
418 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
420 forum
.subscribe((forumsValue
) => {
422 response
= forumsValue
;
425 expect(response
.data
).toBe(null);
426 expect(response
.loading
).toBe(true);
427 expect(response
.error
).toBe(undefined);
428 await resolveAfterTwo
;
429 expect(response
.data
).toBe(null);
430 expect(response
.loading
).toBe(false);
431 expect(response
.error
).toBeInstanceOf(Error
);