diff options
| -rw-r--r-- | pacts/forumsstore-forumapiserver.json | 79 | ||||
| -rw-r--r-- | src/routes/f/[id].svelte | 2 | ||||
| -rw-r--r-- | src/routes/g/[id].svelte | 2 | ||||
| -rw-r--r-- | src/routes/p/[id].svelte | 2 | ||||
| -rw-r--r-- | src/routes/t/[id].svelte | 2 | ||||
| -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 |
11 files changed, 174 insertions, 14 deletions
diff --git a/pacts/forumsstore-forumapiserver.json b/pacts/forumsstore-forumapiserver.json index 26a2810..c3d2c0d 100644 --- a/pacts/forumsstore-forumapiserver.json +++ b/pacts/forumsstore-forumapiserver.json @@ -65,6 +65,85 @@ } } } + }, + { + "description": "a request to get a single forum", + "request": { + "method": "POST", + "path": "/graphql", + "headers": { + "content-type": "application/json" + }, + "body": { + "operationName": "GetForum", + "query": "query GetForum($id: ID!) {\n forum(id: $id) {\n id\n glyph\n label\n position\n topics {\n id\n title\n updated_at\n ttl\n __typename\n }\n __typename\n }\n }", + "variables": { + "id": "freezer" + } + }, + "matchingRules": { + "$.body.query": { + "match": "regex", + "regex": "query\\s*GetForum\\(\\$id:\\s*ID!\\)\\s*\\{\\s*forum\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*glyph\\s*label\\s*position\\s*topics\\s*\\{\\s*id\\s*title\\s*updated_at\\s*ttl\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}" + } + } + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/json; charset=utf-8" + }, + "body": { + "data": { + "forum": { + "id": "freezer", + "glyph": "✭", + "label": "test_forums.freezer", + "position": 3, + "topics": [ + { + "id": "629de02c-151a-4db7-bb86-43b2add8a15a", + "title": "Very pacty topic", + "updated_at": 1619954611616, + "ttl": 3601 + } + ] + } + } + }, + "matchingRules": { + "$.body.data.forum": { + "match": "type" + }, + "$.body.data.forum.glyph": { + "match": "type" + }, + "$.body.data.forum.label": { + "match": "type" + }, + "$.body.data.forum.position": { + "match": "type" + }, + "$.body.data.forum.topics": { + "min": 1 + }, + "$.body.data.forum.topics[*].*": { + "match": "type" + }, + "$.body.data.forum.topics[*].id": { + "match": "type" + }, + "$.body.data.forum.topics[*].title": { + "match": "type" + }, + "$.body.data.forum.topics[*].updated_at": { + "match": "type" + }, + "$.body.data.forum.topics[*].ttl": { + "match": "type" + } + } + } } ], "metadata": { diff --git a/src/routes/f/[id].svelte b/src/routes/f/[id].svelte index 83afc8a..a92862f 100644 --- a/src/routes/f/[id].svelte +++ b/src/routes/f/[id].svelte @@ -14,7 +14,7 @@ export let id; - import { getForum } from '$/stores/forum'; + import { getForum } from '$/stores/forums'; $: store = getForum(id); $: forum = $store.data; </script> diff --git a/src/routes/g/[id].svelte b/src/routes/g/[id].svelte index 023fbd8..d6a83cd 100644 --- a/src/routes/g/[id].svelte +++ b/src/routes/g/[id].svelte @@ -8,7 +8,7 @@ <script> import { _ } from 'svelte-i18n'; - import { getTag } from '$/stores/tag'; + import { getTag } from '$/stores/tags'; import ErrorBlock from '$/components/error_block/error_block.svelte'; import Loader from '$/components/loader/loader.svelte'; import Tag from '$/components/tag/tag.svelte'; diff --git a/src/routes/p/[id].svelte b/src/routes/p/[id].svelte index 915cfeb..3eeb528 100644 --- a/src/routes/p/[id].svelte +++ b/src/routes/p/[id].svelte @@ -8,7 +8,7 @@ <script> import { _ } from 'svelte-i18n'; - import { getPost } from '$/stores/post'; + import { getPost } from '$/stores/posts'; import Post from '$/components/post/post.svelte'; import ErrorBlock from '$/components/error_block/error_block.svelte'; import Loader from '$/components/loader/loader.svelte'; diff --git a/src/routes/t/[id].svelte b/src/routes/t/[id].svelte index 9d3ab9e..50aad50 100644 --- a/src/routes/t/[id].svelte +++ b/src/routes/t/[id].svelte @@ -9,7 +9,7 @@ <script> import { onDestroy } from 'svelte'; import { _ } from 'svelte-i18n'; - import { getTopic } from '$/stores/topic'; + import { getTopic } from '$/stores/topics'; import { disableTopicActions, enableTopicActions } from '$/stores/actions'; import Topic from '$/components/topic/topic.svelte'; 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 |