}
}
}
+ },
+ {
+ "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": {
export let id;
- import { getForum } from '$/stores/forum';
+ import { getForum } from '$/stores/forums';
$: store = getForum(id);
$: forum = $store.data;
</script>
<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';
<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';
<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';
+++ /dev/null
-import { store } from './apollo';
-import { GET_FORUM } from '$/data/queries';
-
-export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } });
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: [] });
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 () => {
afterEach(() => internals.provider.verify());
afterAll(() => internals.provider.finalize());
- describe('there are forums', () => {
+ describe('GetForums', () => {
beforeAll(async () => {
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);
+ });
+ });
});