]> git.r.bdr.sh - rbdr/forum/commitdiff
Add getForum pact, normalize stores
authorRuben Beltran del Rio <redacted>
Sun, 2 May 2021 11:37:11 +0000 (13:37 +0200)
committerRuben Beltran del Rio <redacted>
Sun, 2 May 2021 11:37:11 +0000 (13:37 +0200)
pacts/forumsstore-forumapiserver.json
src/routes/f/[id].svelte
src/routes/g/[id].svelte
src/routes/p/[id].svelte
src/routes/t/[id].svelte
src/stores/forum.js [deleted file]
src/stores/forums.js
src/stores/forums.test.js
src/stores/posts.js [moved from src/stores/post.js with 100% similarity]
src/stores/tags.js [moved from src/stores/tag.js with 100% similarity]
src/stores/topics.js [moved from src/stores/topic.js with 100% similarity]

index 26a2810b2b271d921d3f29c5ecdde63d6831f808..c3d2c0d66a6ed63f321d2e0e1b9e1f07c5356c80 100644 (file)
           }
         }
       }
+    },
+    {
+      "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": {
index 83afc8a905995ff89e8a1c773c174ae5c49679d9..a92862f3e3d26a085f3298d2948cc3c4c3aeeb49 100644 (file)
@@ -14,7 +14,7 @@
 
        export let id;
 
-       import { getForum } from '$/stores/forum';
+       import { getForum } from '$/stores/forums';
        $: store = getForum(id);
        $: forum = $store.data;
 </script>
index 023fbd8636e1794aa322536e85831a8c8ff19c56..d6a83cd56b4d42a3c5d1c8409a695298f3900d74 100644 (file)
@@ -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';
index 915cfeb5b14cac8a38eab9ddaf558597ea5b98ef..3eeb5288947cedd612fd2c80d7401a188a357497 100644 (file)
@@ -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';
index 9d3ab9e214b97697b3af1e353973d6e4345f1eb7..50aad509ff909185f8a9099fab3150131aeb3070 100644 (file)
@@ -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 (file)
index a4a66a5..0000000
+++ /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 } });
index 39822a376c4b0b39ec26337e9ce2da3cd06b47b7..2c03a05eeb2c643c13e80c2cfe40d7de50956e92 100644 (file)
@@ -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: [] });
index 25293c803d04c80d175ace34d9fe8f5951fa7898..694316baac611c3528c6dfc01ee5b6954fe4b303 100644 (file)
@@ -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);
+    });
+  });
 });
similarity index 100%
rename from src/stores/post.js
rename to src/stores/posts.js
similarity index 100%
rename from src/stores/tag.js
rename to src/stores/tags.js
similarity index 100%
rename from src/stores/topic.js
rename to src/stores/topics.js