]> git.r.bdr.sh - rbdr/forum/commitdiff
Add error/empty cases for forums
authorRuben Beltran del Rio <redacted>
Sun, 2 May 2021 15:08:43 +0000 (17:08 +0200)
committerRuben Beltran del Rio <redacted>
Sun, 2 May 2021 15:08:43 +0000 (17:08 +0200)
pacts/forumsstore-forumapiserver.json
src/config/__mocks__/config.js
src/stores/forums.test.js

index c3d2c0d66a6ed63f321d2e0e1b9e1f07c5356c80..c0e784bd26965e4f00d101a26590f711be397acd 100644 (file)
@@ -8,6 +8,7 @@
   "interactions": [
     {
       "description": "a request to list the forums",
   "interactions": [
     {
       "description": "a request to list the forums",
+      "providerState": "there's forums",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
@@ -16,7 +17,7 @@
         },
         "body": {
           "operationName": "GetForums",
         },
         "body": {
           "operationName": "GetForums",
-          "query": "query GetForums {\n            forums {\n              id\n              glyph\n              label\n              position\n              __typename\n            }\n          }",
+          "query": "query GetForums {\n              forums {\n                id\n                glyph\n                label\n                position\n                __typename\n              }\n            }",
           "variables": {
           }
         },
           "variables": {
           }
         },
@@ -68,6 +69,7 @@
     },
     {
       "description": "a request to get a single forum",
     },
     {
       "description": "a request to get a single forum",
+      "providerState": "there's forums",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
@@ -76,7 +78,7 @@
         },
         "body": {
           "operationName": "GetForum",
         },
         "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          }",
+          "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"
           }
           "variables": {
             "id": "freezer"
           }
           }
         }
       }
           }
         }
       }
+    },
+    {
+      "description": "a request to list the forums",
+      "providerState": "there's no forums",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetForums",
+          "query": "query GetForums {\n              forums {\n                id\n                glyph\n                label\n                position\n                __typename\n              }\n            }",
+          "variables": {
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetForums\\s*\\{\\s*forums\\s*\\{\\s*id\\s*glyph\\s*label\\s*position\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 200,
+        "headers": {
+          "Content-Type": "application/json; charset=utf-8"
+        },
+        "body": {
+          "data": {
+            "forums": [
+
+            ]
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single forum",
+      "providerState": "there's no forums",
+      "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": null
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to list the forums",
+      "providerState": "there's an error",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetForums",
+          "query": "query GetForums {\n              forums {\n                id\n                glyph\n                label\n                position\n                __typename\n              }\n            }",
+          "variables": {
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetForums\\s*\\{\\s*forums\\s*\\{\\s*id\\s*glyph\\s*label\\s*position\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 500,
+        "headers": {
+        }
+      }
+    },
+    {
+      "description": "a request to get a single forum",
+      "providerState": "there's an error",
+      "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": 500,
+        "headers": {
+        }
+      }
     }
   ],
   "metadata": {
     }
   ],
   "metadata": {
index 0cd8b972290613f0d99b184d92019848d6dbcd67..b70ee312de609f8626533988dcb7dc4dcabda890 100644 (file)
@@ -1,7 +1,15 @@
 export const apollo = {
   uri: 'http://localhost:1234/graphql',
   name: 'COOL_APP',
 export const apollo = {
   uri: 'http://localhost:1234/graphql',
   name: 'COOL_APP',
-  version: '9.9.9'
+  version: '9.9.9',
+  defaultOptions: {
+    watchQuery: {
+      fetchPolicy: 'no-cache'
+    },
+    query: {
+      fetchPolicy: 'no-cache'
+    }
+  }
 };
 
 export const version = '9.9.9';
 };
 
 export const version = '9.9.9';
index 694316baac611c3528c6dfc01ee5b6954fe4b303..e117828dddc1d1dcded15ae77db16ca459776332 100644 (file)
@@ -30,156 +30,406 @@ describe('Forums store pact', () => {
   afterEach(() => internals.provider.verify());
   afterAll(() => internals.provider.finalize());
 
   afterEach(() => internals.provider.verify());
   afterAll(() => internals.provider.finalize());
 
-  describe('GetForums', () => {
-
-    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)
-              })
+  describe('When there\'s forums', () => {
+
+    describe('GetForums', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s forums')
+          .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();
         });
         });
-      return await internals.provider.addInteraction(forumQuery);
+        expect(response.data).toBeInstanceOf(Array);
+        expect(response.data.length).toBe(0);
+        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);
+      });
     });
 
     });
 
-    test('it returns the forums', async () => {
+    describe('GetForum', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s forums')
+          .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 forums = getForums();
-      const { counter, promise: resolveAfterTwo } = resolveAfter(2);
-      let response = null;
-      forums.subscribe((forumsValue) => {
+        const forum = getForum('freezer');
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        forum.subscribe((forumsValue) => {
 
 
-        response = forumsValue;
-        counter();
+          response = forumsValue;
+          counter();
+        });
+        expect(response.data).toBe(null);
+        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);
       });
       });
-      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);
     });
   });
 
     });
   });
 
-  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 {
+  describe('When there\'s no forums', () => {
+
+    describe('GetForums', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s no forums')
+          .uponReceiving('a request to list the forums')
+          .withRequest({
+            path: '/graphql',
+            method: 'POST'
+          })
+          .withOperation('GetForums')
+          .withQuery(
+            `query GetForums {
+              forums {
                 id
                 id
-                title
-                updated_at
-                ttl
+                glyph
+                label
+                position
                 __typename
               }
                 __typename
               }
-              __typename
+            }`
+          )
+          .withVariables({})
+          .willRespondWith({
+            status: 200,
+            headers: {
+              'Content-Type': 'application/json; charset=utf-8'
+            },
+            body: {
+              data: {
+                forums: []
+              }
             }
             }
-          }`
-        )
-        .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 forums', async () => {
+
+        const forums = getForums();
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        forums.subscribe((forumsValue) => {
+
+          response = forumsValue;
+          counter();
+        });
+        expect(response.data).toBeInstanceOf(Array);
+        expect(response.data.length).toBe(0);
+        expect(response.loading).toBe(true);
+        expect(response.error).toBe(undefined);
+        await resolveAfterTwo;
+        expect(response.data).toBeInstanceOf(Array);
+        expect(response.data.length).toBe(0);
+        expect(response.loading).toBe(false);
+        expect(response.error).toBe(undefined);
+      });
+    });
+
+    describe('GetForum', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s no forums')
+          .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: null
+              }
             }
             }
-          }
+          });
+        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).toBe(null);
+        expect(response.loading).toBe(true);
+        expect(response.error).toBe(undefined);
+        await resolveAfterTwo;
+        expect(response.data).toBe(null);
+        expect(response.loading).toBe(false);
+        expect(response.error).toBe(undefined);
+      });
+    });
+  });
+
+  describe('When there\'s an error', () => {
+
+    describe('GetForums', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s an error')
+          .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: 500
+          });
+        return await internals.provider.addInteraction(forumQuery);
+      });
+
+      test('it returns the error', async () => {
+
+        const forums = getForums();
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        forums.subscribe((forumsValue) => {
+
+          response = forumsValue;
+          counter();
         });
         });
-      return await internals.provider.addInteraction(forumQuery);
+        expect(response.data).toBeInstanceOf(Array);
+        expect(response.data.length).toBe(0);
+        expect(response.loading).toBe(true);
+        expect(response.error).toBe(undefined);
+        await resolveAfterTwo;
+        expect(response.data).toBeInstanceOf(Array);
+        expect(response.data.length).toBe(0);
+        expect(response.loading).toBe(false);
+        expect(response.error).toBeInstanceOf(Error);
+      });
     });
 
     });
 
-    test('it returns the forum', async () => {
+    describe('GetForum', () => {
 
 
-      const forum = getForum('freezer');
-      const { counter, promise: resolveAfterTwo } = resolveAfter(2);
-      let response = null;
-      forum.subscribe((forumsValue) => {
+      beforeAll(async () => {
 
 
-        response = forumsValue;
-        counter();
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s an error')
+          .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: 500
+          });
+        return await internals.provider.addInteraction(forumQuery);
+      });
+
+      test('it returns the error', async () => {
+
+        const forum = getForum('freezer');
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        forum.subscribe((forumsValue) => {
+
+          response = forumsValue;
+          counter();
+        });
+        expect(response.data).toBe(null);
+        expect(response.loading).toBe(true);
+        expect(response.error).toBe(undefined);
+        await resolveAfterTwo;
+        expect(response.data).toBe(null);
+        expect(response.loading).toBe(false);
+        expect(response.error).toBeInstanceOf(Error);
       });
       });
-      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);
     });
   });
 });
     });
   });
 });