diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-05-02 00:23:16 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-05-02 00:23:16 +0200 |
| commit | 73973edab9aaa81312ba80a68bfe34bf5abcecd9 (patch) | |
| tree | 9d3916655c416407e12dc66e9f1f865cec0fb2b3 /src/stores/forums.test.js | |
| parent | 55fb920baa9792266be1a6b981f954c622c1eaf9 (diff) | |
Add pact test for forums store
Diffstat (limited to 'src/stores/forums.test.js')
| -rw-r--r-- | src/stores/forums.test.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/stores/forums.test.js b/src/stores/forums.test.js new file mode 100644 index 0000000..25293c8 --- /dev/null +++ b/src/stores/forums.test.js @@ -0,0 +1,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); + }); + }); +}); |