]>
git.r.bdr.sh - rbdr/forum/blob - src/stores/forums.test.js
25293c803d04c80d175ace34d9fe8f5951fa7898
1 import { GraphQLInteraction
, Pact
, Matchers
} from '@pact-foundation/pact';
2 import { resolve
} from 'path';
4 import { resolveAfter
} from '$/utils/resolve_after';
6 import { act
} from '@testing-library/svelte';
8 const { eachLike
, like
} = Matchers
;
10 jest
.mock('$/config/config.js');
12 import { getForums
} from './forums';
18 describe('Forum store pact', () => {
20 beforeAll(async () => {
22 internals
.provider
= new Pact({
24 dir: resolve(process
.cwd(), 'pacts'),
25 consumer: 'ForumsStore',
26 provider: 'ForumAPIServer'
29 await internals
.provider
.setup();
32 afterEach(() => internals
.provider
.verify());
33 afterAll(() => internals
.provider
.finalize());
35 describe('there are forums', () => {
37 beforeAll(async () => {
39 const forumQuery
= new GraphQLInteraction()
40 .uponReceiving('a request to list the forums')
45 .withOperation('GetForums')
61 'Content-Type': 'application/json; charset=utf-8'
68 label: like('test_forums.butter'),
74 return await internals
.provider
.addInteraction(forumQuery
);
77 test('it returns the forums', async () => {
79 const forums
= getForums();
80 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
82 forums
.subscribe((forumsValue
) => {
84 response
= forumsValue
;
87 expect(response
.data
).toEqual(expect
.arrayContaining([]));
88 expect(response
.loading
).toBe(true);
89 expect(response
.error
).toBe(undefined);
90 await resolveAfterTwo
;
91 expect(response
.data
).toEqual(expect
.arrayContaining([{
94 label: 'test_forums.butter',
97 expect(response
.loading
).toBe(false);
98 expect(response
.error
).toBe(undefined);