diff options
Diffstat (limited to 'src/stores')
| -rw-r--r-- | src/stores/forum.js | 4 | ||||
| -rw-r--r-- | src/stores/forums.js | 3 | ||||
| -rw-r--r-- | src/stores/forums.test.js | 94 | ||||
| -rw-r--r-- | src/stores/posts.js (renamed from src/stores/post.js) | 0 | ||||
| -rw-r--r-- | src/stores/tags.js (renamed from src/stores/tag.js) | 0 | ||||
| -rw-r--r-- | src/stores/topics.js (renamed from src/stores/topic.js) | 0 |
6 files changed, 91 insertions, 10 deletions
diff --git a/src/stores/forum.js b/src/stores/forum.js deleted file mode 100644 index a4a66a5..0000000 --- a/src/stores/forum.js +++ /dev/null @@ -1,4 +0,0 @@ -import { store } from './apollo'; -import { GET_FORUM } from '$/data/queries'; - -export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } }); diff --git a/src/stores/forums.js b/src/stores/forums.js index 39822a3..2c03a05 100644 --- a/src/stores/forums.js +++ b/src/stores/forums.js @@ -1,4 +1,5 @@ import { store } from './apollo'; -import { GET_FORUMS } from '$/data/queries'; +import { GET_FORUM, GET_FORUMS } from '$/data/queries'; +export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } }); export const getForums = () => store({ key: 'forums', query: GET_FORUMS, initialValue: [] }); diff --git a/src/stores/forums.test.js b/src/stores/forums.test.js index 25293c8..694316b 100644 --- a/src/stores/forums.test.js +++ b/src/stores/forums.test.js @@ -3,19 +3,17 @@ 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'; +import { getForum, getForums } from './forums'; const internals = { provider: null }; -describe('Forum store pact', () => { +describe('Forums store pact', () => { beforeAll(async () => { @@ -32,7 +30,7 @@ describe('Forum store pact', () => { afterEach(() => internals.provider.verify()); afterAll(() => internals.provider.finalize()); - describe('there are forums', () => { + describe('GetForums', () => { beforeAll(async () => { @@ -98,4 +96,90 @@ describe('Forum store pact', () => { expect(response.error).toBe(undefined); }); }); + + describe('GetForum', () => { + + beforeAll(async () => { + + const forumQuery = new GraphQLInteraction() + .uponReceiving('a request to get a single forum') + .withRequest({ + path: '/graphql', + method: 'POST' + }) + .withOperation('GetForum') + .withQuery( + `query GetForum($id: ID!) { + forum(id: $id) { + id + glyph + label + position + topics { + id + title + updated_at + ttl + __typename + } + __typename + } + }` + ) + .withVariables({ + id: 'freezer' + }) + .willRespondWith({ + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf-8' + }, + body: { + data: { + forum: like({ + id: 'freezer', + glyph: like('✭'), + label: like('test_forums.freezer'), + position: like(3), + topics: eachLike({ + id: like('629de02c-151a-4db7-bb86-43b2add8a15a'), + title: like('Very pacty topic'), + updated_at: like(1619954611616), + ttl: like(3601) + }) + }) + } + } + }); + return await internals.provider.addInteraction(forumQuery); + }); + + test('it returns the forum', async () => { + + const forum = getForum('freezer'); + const { counter, promise: resolveAfterTwo } = resolveAfter(2); + let response = null; + forum.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.id).toBe('freezer'); + expect(response.data.glyph).toBe('✭'); + expect(response.data.label).toBe('test_forums.freezer'); + expect(response.data.position).toBe(3); + expect(response.data.topics).toEqual(expect.arrayContaining([{ + id: '629de02c-151a-4db7-bb86-43b2add8a15a', + title: 'Very pacty topic', + updated_at: 1619954611616, + ttl: 3601 + }])); + expect(response.loading).toBe(false); + expect(response.error).toBe(undefined); + }); + }); }); diff --git a/src/stores/post.js b/src/stores/posts.js index 0cbf1d5..0cbf1d5 100644 --- a/src/stores/post.js +++ b/src/stores/posts.js diff --git a/src/stores/tag.js b/src/stores/tags.js index d74b719..d74b719 100644 --- a/src/stores/tag.js +++ b/src/stores/tags.js diff --git a/src/stores/topic.js b/src/stores/topics.js index c90f1a3..c90f1a3 100644 --- a/src/stores/topic.js +++ b/src/stores/topics.js |