]>
git.r.bdr.sh - rbdr/forum/blob - src/stores/topics.test.js
280bddb262ee6487aed90b59cbcc464f5fe5dba8
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 { getTopic
} from './topics';
16 describe('Topics store pact', () => {
18 beforeAll(async () => {
20 internals
.provider
= new Pact({
22 dir: resolve(process
.cwd(), 'pacts'),
23 consumer: 'ForumClient',
24 provider: 'ForumServer',
25 pactfileWriteMode: 'update'
28 await internals
.provider
.setup();
31 afterEach(() => internals
.provider
.verify());
32 afterAll(() => internals
.provider
.finalize());
34 describe('When there\'s data', () => {
36 describe('GetTopic', () => {
38 beforeAll(async () => {
40 const topicQuery
= new GraphQLInteraction()
41 .given('there\'s data')
42 .uponReceiving('a request to get a single topic')
47 .withOperation('GetTopic')
49 `query GetTopic($id: ID!) {
82 id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1'
87 'Content-Type': 'application/json; charset=utf-8'
92 id: like('0b58959d-d448-4a4e-84b6-35e5ac0028d1'),
93 title: like('The pacty topic of the day'),
94 updated_at: like(1619979888906),
99 label: like('test_forums.cucumber')
106 id: like('ed93530e-6f9c-4701-91ef-14f9e0ed3e26'),
107 text: like('The content of this post is very relevant'),
108 created_at: like(1619979889798),
110 id: like('07fb2ba0-0945-464a-b215-873296710c8c'),
111 handle: like('cucumber_fan92')
118 return await internals
.provider
.addInteraction(topicQuery
);
121 test('it returns the topic', async () => {
123 const topic
= getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1');
124 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
126 topic
.subscribe((topicValue
) => {
128 response
= topicValue
;
131 expect(response
.data
).toBe(null);
132 expect(response
.loading
).toBe(true);
133 expect(response
.error
).toBe(undefined);
134 await resolveAfterTwo
;
135 expect(response
.data
).toEqual({
136 id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1',
137 title: 'The pacty topic of the day',
138 updated_at: 1619979888906,
143 label: 'test_forums.cucumber'
150 id: 'ed93530e-6f9c-4701-91ef-14f9e0ed3e26',
151 text: 'The content of this post is very relevant',
152 created_at: 1619979889798,
154 id: '07fb2ba0-0945-464a-b215-873296710c8c',
155 handle: 'cucumber_fan92'
159 expect(response
.loading
).toBe(false);
160 expect(response
.error
).toBe(undefined);
165 describe('When there\'s no data', () => {
167 describe('GetTopic', () => {
169 beforeAll(async () => {
171 const topicQuery
= new GraphQLInteraction()
172 .given('there\'s no data')
173 .uponReceiving('a request to get a single topic')
178 .withOperation('GetTopic')
180 `query GetTopic($id: ID!) {
213 id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1'
218 'Content-Type': 'application/json; charset=utf-8'
226 return await internals
.provider
.addInteraction(topicQuery
);
229 test('it returns the topic', async () => {
231 const topic
= getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1');
232 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
234 topic
.subscribe((topicValue
) => {
236 response
= topicValue
;
239 expect(response
.data
).toBe(null);
240 expect(response
.loading
).toBe(true);
241 expect(response
.error
).toBe(undefined);
242 await resolveAfterTwo
;
243 expect(response
.data
).toBe(null);
244 expect(response
.loading
).toBe(false);
245 expect(response
.error
).toBe(undefined);
250 describe('When there\'s an error', () => {
252 describe('GetTopic', () => {
254 beforeAll(async () => {
256 const topicQuery
= new GraphQLInteraction()
257 .given('there\'s an error')
258 .uponReceiving('a request to get a single topic')
263 .withOperation('GetTopic')
265 `query GetTopic($id: ID!) {
298 id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1'
303 return await internals
.provider
.addInteraction(topicQuery
);
306 test('it returns the error', async () => {
308 const topic
= getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1');
309 const { counter
, promise: resolveAfterTwo
} = resolveAfter(2);
311 topic
.subscribe((topicValue
) => {
313 response
= topicValue
;
316 expect(response
.data
).toBe(null);
317 expect(response
.loading
).toBe(true);
318 expect(response
.error
).toBe(undefined);
319 await resolveAfterTwo
;
320 expect(response
.data
).toBe(null);
321 expect(response
.loading
).toBe(false);
322 expect(response
.error
).toBeInstanceOf(Error
);