]> git.r.bdr.sh - rbdr/forum/commitdiff
Add tests for actions + pacts for graphql errrors
authorRuben Beltran del Rio <redacted>
Mon, 3 May 2021 18:59:55 +0000 (20:59 +0200)
committerRuben Beltran del Rio <redacted>
Mon, 3 May 2021 18:59:55 +0000 (20:59 +0200)
pacts/forumclient-forumserver.json
src/stores/actions.js
src/stores/actions.test.js [new file with mode: 0644]
src/stores/forums.test.js
src/stores/posts.test.js
src/stores/tags.test.js
src/stores/topics.test.js

index 337ff86fb4ef6653fadfbbd1bbab120d433a49a7..9ec37f83890bf209498b47103c0fb661c499878b 100644 (file)
@@ -6,149 +6,6 @@
     "name": "ForumServer"
   },
   "interactions": [
     "name": "ForumServer"
   },
   "interactions": [
-    {
-      "description": "a request to get a single post",
-      "providerState": "there's data",
-      "request": {
-        "method": "POST",
-        "path": "/graphql",
-        "headers": {
-          "content-type": "application/json"
-        },
-        "body": {
-          "operationName": "GetPost",
-          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
-          "variables": {
-            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
-          }
-        },
-        "matchingRules": {
-          "$.body.query": {
-            "match": "regex",
-            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
-          }
-        }
-      },
-      "response": {
-        "status": 200,
-        "headers": {
-          "Content-Type": "application/json; charset=utf-8"
-        },
-        "body": {
-          "data": {
-            "post": {
-              "id": "8f75eba5-6989-4dd3-b466-e464546ce374",
-              "text": "This is a very pacty post",
-              "created_at": 1619976194937,
-              "author": {
-                "id": "a805b3de-cac4-451c-a1e6-f078869c9db9",
-                "handle": "pacts_person"
-              },
-              "topic": {
-                "id": "5c283ce1-0470-4b98-86f5-1fec9a22c9ac",
-                "title": "The parent pacts topic"
-              }
-            }
-          }
-        },
-        "matchingRules": {
-          "$.body.data.post": {
-            "match": "type"
-          },
-          "$.body.data.post.id": {
-            "match": "type"
-          },
-          "$.body.data.post.text": {
-            "match": "type"
-          },
-          "$.body.data.post.created_at": {
-            "match": "type"
-          },
-          "$.body.data.post.author": {
-            "match": "type"
-          },
-          "$.body.data.post.author.id": {
-            "match": "type"
-          },
-          "$.body.data.post.author.handle": {
-            "match": "type"
-          },
-          "$.body.data.post.topic": {
-            "match": "type"
-          },
-          "$.body.data.post.topic.id": {
-            "match": "type"
-          },
-          "$.body.data.post.topic.title": {
-            "match": "type"
-          }
-        }
-      }
-    },
-    {
-      "description": "a request to get a single post",
-      "providerState": "there's no data",
-      "request": {
-        "method": "POST",
-        "path": "/graphql",
-        "headers": {
-          "content-type": "application/json"
-        },
-        "body": {
-          "operationName": "GetPost",
-          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
-          "variables": {
-            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
-          }
-        },
-        "matchingRules": {
-          "$.body.query": {
-            "match": "regex",
-            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
-          }
-        }
-      },
-      "response": {
-        "status": 200,
-        "headers": {
-          "Content-Type": "application/json; charset=utf-8"
-        },
-        "body": {
-          "data": {
-            "post": null
-          }
-        }
-      }
-    },
-    {
-      "description": "a request to get a single post",
-      "providerState": "there's an error",
-      "request": {
-        "method": "POST",
-        "path": "/graphql",
-        "headers": {
-          "content-type": "application/json"
-        },
-        "body": {
-          "operationName": "GetPost",
-          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
-          "variables": {
-            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
-          }
-        },
-        "matchingRules": {
-          "$.body.query": {
-            "match": "regex",
-            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
-          }
-        }
-      },
-      "response": {
-        "status": 500,
-        "headers": {
-        }
-      }
-    },
     {
       "description": "a request to list the forums",
       "providerState": "there's data",
     {
       "description": "a request to list the forums",
       "providerState": "there's data",
     },
     {
       "description": "a request to list the forums",
     },
     {
       "description": "a request to list the forums",
-      "providerState": "there's an error",
+      "providerState": "there's a server error",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
     },
     {
       "description": "a request to get a single forum",
     },
     {
       "description": "a request to get a single forum",
-      "providerState": "there's an error",
+      "providerState": "there's a server error",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
       }
     },
     {
       }
     },
     {
-      "description": "a request to get a single tag",
-      "providerState": "there's data",
+      "description": "a request to list the forums",
+      "providerState": "there's an error in the response",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
           "content-type": "application/json"
         },
         "body": {
           "content-type": "application/json"
         },
         "body": {
-          "operationName": "GetTag",
-          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "operationName": "GetForums",
+          "query": "query GetForums {\n              forums {\n                id\n                glyph\n                label\n                position\n                __typename\n              }\n            }",
           "variables": {
           "variables": {
-            "id": "pineapple"
           }
         },
         "matchingRules": {
           "$.body.query": {
             "match": "regex",
           }
         },
         "matchingRules": {
           "$.body.query": {
             "match": "regex",
-            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*topics\\s*\\{\\s*id\\s*title\\s*updated_at\\s*ttl\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+            "regex": "query\\s*GetForums\\s*\\{\\s*forums\\s*\\{\\s*id\\s*glyph\\s*label\\s*position\\s*__typename\\s*\\}\\s*\\}"
           }
         }
       },
           }
         }
       },
           "Content-Type": "application/json; charset=utf-8"
         },
         "body": {
           "Content-Type": "application/json; charset=utf-8"
         },
         "body": {
-          "data": {
-            "tag": {
-              "id": "pineapple",
-              "topics": [
-                {
-                  "id": "cd038ae7-e8b4-4e38-9543-3d697e69ac34",
-                  "title": "This topic is about pineapples",
-                  "updated_at": 1619978944077,
-                  "ttl": 3555
-                }
-              ]
+          "errors": [
+            {
+              "message": "An error occurred when fetching forums"
             }
             }
-          }
+          ]
         },
         "matchingRules": {
         },
         "matchingRules": {
-          "$.body.data.tag.id": {
-            "match": "type"
-          },
-          "$.body.data.tag.topics": {
+          "$.body.errors": {
             "min": 1
           },
             "min": 1
           },
-          "$.body.data.tag.topics[*].*": {
-            "match": "type"
-          },
-          "$.body.data.tag.topics[*].id": {
-            "match": "type"
-          },
-          "$.body.data.tag.topics[*].title": {
-            "match": "type"
-          },
-          "$.body.data.tag.topics[*].updated_at": {
+          "$.body.errors[*].*": {
             "match": "type"
           },
             "match": "type"
           },
-          "$.body.data.tag.topics[*].ttl": {
+          "$.body.errors[*].message": {
             "match": "type"
           }
         }
       }
     },
     {
             "match": "type"
           }
         }
       }
     },
     {
-      "description": "a request to get a single tag",
-      "providerState": "there's no data",
+      "description": "a request to get a single forum",
+      "providerState": "there's an error in the response",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
           "content-type": "application/json"
         },
         "body": {
           "content-type": "application/json"
         },
         "body": {
-          "operationName": "GetTag",
-          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "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": {
           "variables": {
-            "id": "pineapple"
+            "id": "freezer"
           }
         },
         "matchingRules": {
           "$.body.query": {
             "match": "regex",
           }
         },
         "matchingRules": {
           "$.body.query": {
             "match": "regex",
-            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*topics\\s*\\{\\s*id\\s*title\\s*updated_at\\s*ttl\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+            "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*\\}"
           }
         }
       },
           }
         }
       },
           "Content-Type": "application/json; charset=utf-8"
         },
         "body": {
           "Content-Type": "application/json; charset=utf-8"
         },
         "body": {
-          "data": {
-            "tag": null
-          }
-        }
-      }
-    },
-    {
-      "description": "a request to get a single tag",
-      "providerState": "there's an error",
-      "request": {
-        "method": "POST",
-        "path": "/graphql",
-        "headers": {
-          "content-type": "application/json"
-        },
-        "body": {
-          "operationName": "GetTag",
-          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
-          "variables": {
-            "id": "pineapple"
-          }
+          "errors": [
+            {
+              "message": "An error occurred when fetching the forum"
+            }
+          ]
         },
         "matchingRules": {
         },
         "matchingRules": {
-          "$.body.query": {
-            "match": "regex",
-            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*topics\\s*\\{\\s*id\\s*title\\s*updated_at\\s*ttl\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          "$.body.errors": {
+            "min": 1
+          },
+          "$.body.errors[*].*": {
+            "match": "type"
+          },
+          "$.body.errors[*].message": {
+            "match": "type"
           }
         }
           }
         }
-      },
-      "response": {
-        "status": 500,
-        "headers": {
-        }
       }
     },
     {
       }
     },
     {
     },
     {
       "description": "a request to get a single topic",
     },
     {
       "description": "a request to get a single topic",
-      "providerState": "there's an error",
+      "providerState": "there's a server error",
       "request": {
         "method": "POST",
         "path": "/graphql",
       "request": {
         "method": "POST",
         "path": "/graphql",
         "headers": {
         }
       }
         "headers": {
         }
       }
+    },
+    {
+      "description": "a request to get a single topic",
+      "providerState": "there's an error in the response",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetTopic",
+          "query": "query GetTopic($id: ID!) {\n              topic(id: $id) {\n                id\n                title\n                updated_at\n                ttl\n                forum {\n                  id\n                  glyph\n                  label\n                  __typename\n                }\n                tags {\n                  id\n                  weight\n                  __typename\n                }\n                posts {\n                  id\n                  text\n                  created_at\n                  author {\n                    id\n                    handle\n                    __typename\n                  }\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "0b58959d-d448-4a4e-84b6-35e5ac0028d1"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetTopic\\(\\$id:\\s*ID!\\)\\s*\\{\\s*topic\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*title\\s*updated_at\\s*ttl\\s*forum\\s*\\{\\s*id\\s*glyph\\s*label\\s*__typename\\s*\\}\\s*tags\\s*\\{\\s*id\\s*weight\\s*__typename\\s*\\}\\s*posts\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 200,
+        "headers": {
+          "Content-Type": "application/json; charset=utf-8"
+        },
+        "body": {
+          "errors": [
+            {
+              "message": "An error occurred when fetching the topic"
+            }
+          ]
+        },
+        "matchingRules": {
+          "$.body.errors": {
+            "min": 1
+          },
+          "$.body.errors[*].*": {
+            "match": "type"
+          },
+          "$.body.errors[*].message": {
+            "match": "type"
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single tag",
+      "providerState": "there's data",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetTag",
+          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "pineapple"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\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": {
+            "tag": {
+              "id": "pineapple",
+              "topics": [
+                {
+                  "id": "cd038ae7-e8b4-4e38-9543-3d697e69ac34",
+                  "title": "This topic is about pineapples",
+                  "updated_at": 1619978944077,
+                  "ttl": 3555
+                }
+              ]
+            }
+          }
+        },
+        "matchingRules": {
+          "$.body.data.tag.id": {
+            "match": "type"
+          },
+          "$.body.data.tag.topics": {
+            "min": 1
+          },
+          "$.body.data.tag.topics[*].*": {
+            "match": "type"
+          },
+          "$.body.data.tag.topics[*].id": {
+            "match": "type"
+          },
+          "$.body.data.tag.topics[*].title": {
+            "match": "type"
+          },
+          "$.body.data.tag.topics[*].updated_at": {
+            "match": "type"
+          },
+          "$.body.data.tag.topics[*].ttl": {
+            "match": "type"
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single tag",
+      "providerState": "there's no data",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetTag",
+          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "pineapple"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\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": {
+            "tag": null
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single tag",
+      "providerState": "there's a server error",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetTag",
+          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "pineapple"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*topics\\s*\\{\\s*id\\s*title\\s*updated_at\\s*ttl\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 500,
+        "headers": {
+        }
+      }
+    },
+    {
+      "description": "a request to get a single tag",
+      "providerState": "there's an error in the response",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetTag",
+          "query": "query GetTag($id: ID!) {\n              tag(id: $id) {\n                id\n                topics {\n                  id\n                  title\n                  updated_at\n                  ttl\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "pineapple"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetTag\\(\\$id:\\s*ID!\\)\\s*\\{\\s*tag\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\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": {
+          "errors": [
+            {
+              "message": "An error occurred when fetching the tag"
+            }
+          ]
+        },
+        "matchingRules": {
+          "$.body.errors": {
+            "min": 1
+          },
+          "$.body.errors[*].*": {
+            "match": "type"
+          },
+          "$.body.errors[*].message": {
+            "match": "type"
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single post",
+      "providerState": "there's data",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetPost",
+          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 200,
+        "headers": {
+          "Content-Type": "application/json; charset=utf-8"
+        },
+        "body": {
+          "data": {
+            "post": {
+              "id": "8f75eba5-6989-4dd3-b466-e464546ce374",
+              "text": "This is a very pacty post",
+              "created_at": 1619976194937,
+              "author": {
+                "id": "a805b3de-cac4-451c-a1e6-f078869c9db9",
+                "handle": "pacts_person"
+              },
+              "topic": {
+                "id": "5c283ce1-0470-4b98-86f5-1fec9a22c9ac",
+                "title": "The parent pacts topic"
+              }
+            }
+          }
+        },
+        "matchingRules": {
+          "$.body.data.post": {
+            "match": "type"
+          },
+          "$.body.data.post.id": {
+            "match": "type"
+          },
+          "$.body.data.post.text": {
+            "match": "type"
+          },
+          "$.body.data.post.created_at": {
+            "match": "type"
+          },
+          "$.body.data.post.author": {
+            "match": "type"
+          },
+          "$.body.data.post.author.id": {
+            "match": "type"
+          },
+          "$.body.data.post.author.handle": {
+            "match": "type"
+          },
+          "$.body.data.post.topic": {
+            "match": "type"
+          },
+          "$.body.data.post.topic.id": {
+            "match": "type"
+          },
+          "$.body.data.post.topic.title": {
+            "match": "type"
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single post",
+      "providerState": "there's no data",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetPost",
+          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 200,
+        "headers": {
+          "Content-Type": "application/json; charset=utf-8"
+        },
+        "body": {
+          "data": {
+            "post": null
+          }
+        }
+      }
+    },
+    {
+      "description": "a request to get a single post",
+      "providerState": "there's a server error",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetPost",
+          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 500,
+        "headers": {
+        }
+      }
+    },
+    {
+      "description": "a request to get a single post",
+      "providerState": "there's an error in the response",
+      "request": {
+        "method": "POST",
+        "path": "/graphql",
+        "headers": {
+          "content-type": "application/json"
+        },
+        "body": {
+          "operationName": "GetPost",
+          "query": "query GetPost($id: ID!) {\n              post(id: $id) {\n                id\n                text\n                created_at\n                author {\n                  id\n                  handle\n                  __typename\n                }\n                topic {\n                  id\n                  title\n                  __typename\n                }\n                __typename\n              }\n            }",
+          "variables": {
+            "id": "8f75eba5-6989-4dd3-b466-e464546ce374"
+          }
+        },
+        "matchingRules": {
+          "$.body.query": {
+            "match": "regex",
+            "regex": "query\\s*GetPost\\(\\$id:\\s*ID!\\)\\s*\\{\\s*post\\(id:\\s*\\$id\\)\\s*\\{\\s*id\\s*text\\s*created_at\\s*author\\s*\\{\\s*id\\s*handle\\s*__typename\\s*\\}\\s*topic\\s*\\{\\s*id\\s*title\\s*__typename\\s*\\}\\s*__typename\\s*\\}\\s*\\}"
+          }
+        }
+      },
+      "response": {
+        "status": 200,
+        "headers": {
+          "Content-Type": "application/json; charset=utf-8"
+        },
+        "body": {
+          "errors": [
+            {
+              "message": "An error occurred when fetching the post"
+            }
+          ]
+        },
+        "matchingRules": {
+          "$.body.errors": {
+            "min": 1
+          },
+          "$.body.errors[*].*": {
+            "match": "type"
+          },
+          "$.body.errors[*].message": {
+            "match": "type"
+          }
+        }
+      }
     }
   ],
   "metadata": {
     }
   ],
   "metadata": {
index ae0190624c751017923a92d9c6ae37364173a28c..f7fbc28d953672ba8097fce78d38405427e8b3e7 100644 (file)
@@ -4,7 +4,7 @@ import { derived, writable } from 'svelte/store';
  * This is a store to set the actions in the top header.
  */
 
  * This is a store to set the actions in the top header.
  */
 
-export const actions = writable({});
+const actions = writable({});
 
 export const enableTopicActions = (id) => {
 
 
 export const enableTopicActions = (id) => {
 
diff --git a/src/stores/actions.test.js b/src/stores/actions.test.js
new file mode 100644 (file)
index 0000000..c650536
--- /dev/null
@@ -0,0 +1,32 @@
+import { enableTopicActions, disableTopicActions, topicActions } from './actions';
+
+describe('Topic actions and state', () => {
+
+  test('There should be no topic actions by default', () => {
+
+    topicActions.subscribe((actions) => {
+
+      expect(actions).toBe(undefined);
+    })();
+  });
+
+  test('enableTopicActions should set the topic id', () => {
+
+    enableTopicActions('free_hat');
+    topicActions.subscribe((actions) => {
+
+      expect(actions).toEqual({
+        id: 'free_hat'
+      });
+    })();
+  });
+
+  test('disableTopicActions should unset the topic id', () => {
+
+    disableTopicActions();
+    topicActions.subscribe((actions) => {
+
+      expect(actions).toEqual(undefined);
+    })();
+  });
+});
index eb4bc071bf77d930127fa5d2e2ee760815466d2d..732964fe530b6d1ae948c9fc381f4f3f0cdb2abb 100644 (file)
@@ -320,14 +320,14 @@ describe('Forums store pact', () => {
     });
   });
 
     });
   });
 
-  describe('When there\'s an error', () => {
+  describe('When there\'s a server error', () => {
 
     describe('GetForums', () => {
 
       beforeAll(async () => {
 
         const forumQuery = new GraphQLInteraction()
 
     describe('GetForums', () => {
 
       beforeAll(async () => {
 
         const forumQuery = new GraphQLInteraction()
-          .given('there\'s an error')
+          .given('there\'s a server error')
           .uponReceiving('a request to list the forums')
           .withRequest({
             path: '/graphql',
           .uponReceiving('a request to list the forums')
           .withRequest({
             path: '/graphql',
@@ -379,7 +379,7 @@ describe('Forums store pact', () => {
       beforeAll(async () => {
 
         const forumQuery = new GraphQLInteraction()
       beforeAll(async () => {
 
         const forumQuery = new GraphQLInteraction()
-          .given('there\'s an error')
+          .given('there\'s a server error')
           .uponReceiving('a request to get a single forum')
           .withRequest({
             path: '/graphql',
           .uponReceiving('a request to get a single forum')
           .withRequest({
             path: '/graphql',
@@ -433,4 +433,138 @@ describe('Forums store pact', () => {
       });
     });
   });
       });
     });
   });
+
+  describe('When there\'s an error in the response', () => {
+
+    describe('GetForums', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s an error in the response')
+          .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: {
+              errors: eachLike({
+                message: like('An error occurred when fetching forums')
+              })
+            }
+          });
+        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();
+        });
+        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.graphQLErrors).toEqual(expect.arrayContaining([{
+          message: 'An error occurred when fetching forums'
+        }]));
+      });
+    });
+
+    describe('GetForum', () => {
+
+      beforeAll(async () => {
+
+        const forumQuery = new GraphQLInteraction()
+          .given('there\'s an error in the response')
+          .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: {
+              errors: eachLike({
+                message: like('An error occurred when fetching the forum')
+              })
+            }
+          });
+        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.graphQLErrors).toEqual(expect.arrayContaining([{
+          message: 'An error occurred when fetching the forum'
+        }]));
+      });
+    });
+  });
 });
 });
index 5d1fc05f9d73543b0b5f3e2ad57dea2ab0244ee4..ab17286de6f535bffdeb920bc7c4a484b87dcbf7 100644 (file)
@@ -3,7 +3,7 @@ import { resolve } from 'path';
 
 import { resolveAfter } from '$/utils/resolve_after';
 
 
 import { resolveAfter } from '$/utils/resolve_after';
 
-const { like } = Matchers;
+const { eachLike, like } = Matchers;
 
 jest.mock('$/config/config.js');
 
 
 jest.mock('$/config/config.js');
 
@@ -199,14 +199,14 @@ describe('Posts store pact', () => {
     });
   });
 
     });
   });
 
-  describe('When there\'s an error', () => {
+  describe('When there\'s a server error', () => {
 
     describe('GetPost', () => {
 
       beforeAll(async () => {
 
         const postQuery = new GraphQLInteraction()
 
     describe('GetPost', () => {
 
       beforeAll(async () => {
 
         const postQuery = new GraphQLInteraction()
-          .given('there\'s an error')
+          .given('there\'s a server error')
           .uponReceiving('a request to get a single post')
           .withRequest({
             path: '/graphql',
           .uponReceiving('a request to get a single post')
           .withRequest({
             path: '/graphql',
@@ -262,4 +262,78 @@ describe('Posts store pact', () => {
       });
     });
   });
       });
     });
   });
+
+  describe('When there\'s an error in the response', () => {
+
+    describe('GetPost', () => {
+
+      beforeAll(async () => {
+
+        const postQuery = new GraphQLInteraction()
+          .given('there\'s an error in the response')
+          .uponReceiving('a request to get a single post')
+          .withRequest({
+            path: '/graphql',
+            method: 'POST'
+          })
+          .withOperation('GetPost')
+          .withQuery(
+            `query GetPost($id: ID!) {
+              post(id: $id) {
+                id
+                text
+                created_at
+                author {
+                  id
+                  handle
+                  __typename
+                }
+                topic {
+                  id
+                  title
+                  __typename
+                }
+                __typename
+              }
+            }`
+          )
+          .withVariables({
+            id: '8f75eba5-6989-4dd3-b466-e464546ce374'
+          })
+          .willRespondWith({
+            status: 200,
+            headers: {
+              'Content-Type': 'application/json; charset=utf-8'
+            },
+            body: {
+              errors: eachLike({
+                message: like('An error occurred when fetching the post')
+              })
+            }
+          });
+        return await internals.provider.addInteraction(postQuery);
+      });
+
+      test('it returns the error', async () => {
+
+        const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374');
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        post.subscribe((postValue) => {
+
+          response = postValue;
+          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.graphQLErrors).toEqual(expect.arrayContaining([{
+          message: 'An error occurred when fetching the post'
+        }]));
+      });
+    });
+  });
 });
 });
index 177919b407fbc27da103486530f22a713623e9b7..bf4fa56b034cb52dadde102cb72aa1942edaaae5 100644 (file)
@@ -181,14 +181,14 @@ describe('Tags store pact', () => {
     });
   });
 
     });
   });
 
-  describe('When there\'s an error', () => {
+  describe('When there\'s a server error', () => {
 
     describe('GetTag', () => {
 
       beforeAll(async () => {
 
         const tagQuery = new GraphQLInteraction()
 
     describe('GetTag', () => {
 
       beforeAll(async () => {
 
         const tagQuery = new GraphQLInteraction()
-          .given('there\'s an error')
+          .given('there\'s a server error')
           .uponReceiving('a request to get a single tag')
           .withRequest({
             path: '/graphql',
           .uponReceiving('a request to get a single tag')
           .withRequest({
             path: '/graphql',
@@ -239,4 +239,73 @@ describe('Tags store pact', () => {
       });
     });
   });
       });
     });
   });
+
+  describe('When there\'s an error in the response', () => {
+
+    describe('GetTag', () => {
+
+      beforeAll(async () => {
+
+        const tagQuery = new GraphQLInteraction()
+          .given('there\'s an error in the response')
+          .uponReceiving('a request to get a single tag')
+          .withRequest({
+            path: '/graphql',
+            method: 'POST'
+          })
+          .withOperation('GetTag')
+          .withQuery(
+            `query GetTag($id: ID!) {
+              tag(id: $id) {
+                id
+                topics {
+                  id
+                  title
+                  updated_at
+                  ttl
+                  __typename
+                }
+                __typename
+              }
+            }`
+          )
+          .withVariables({
+            id: 'pineapple'
+          })
+          .willRespondWith({
+            status: 200,
+            headers: {
+              'Content-Type': 'application/json; charset=utf-8'
+            },
+            body: {
+              errors: eachLike({
+                message: like('An error occurred when fetching the tag')
+              })
+            }
+          });
+        return await internals.provider.addInteraction(tagQuery);
+      });
+
+      test('it returns the error', async () => {
+
+        const tag = getTag('pineapple');
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        tag.subscribe((tagValue) => {
+
+          response = tagValue;
+          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.graphQLErrors).toEqual(expect.arrayContaining([{
+          message: 'An error occurred when fetching the tag'
+        }]));
+      });
+    });
+  });
 });
 });
index 280bddb262ee6487aed90b59cbcc464f5fe5dba8..7c3285bd16381815d50299196bc66346de1e8daf 100644 (file)
@@ -247,14 +247,14 @@ describe('Topics store pact', () => {
     });
   });
 
     });
   });
 
-  describe('When there\'s an error', () => {
+  describe('When there\'s a server error', () => {
 
     describe('GetTopic', () => {
 
       beforeAll(async () => {
 
         const topicQuery = new GraphQLInteraction()
 
     describe('GetTopic', () => {
 
       beforeAll(async () => {
 
         const topicQuery = new GraphQLInteraction()
-          .given('there\'s an error')
+          .given('there\'s a server error')
           .uponReceiving('a request to get a single topic')
           .withRequest({
             path: '/graphql',
           .uponReceiving('a request to get a single topic')
           .withRequest({
             path: '/graphql',
@@ -323,4 +323,91 @@ describe('Topics store pact', () => {
       });
     });
   });
       });
     });
   });
+
+  describe('When there\'s an error in the response', () => {
+
+    describe('GetTopic', () => {
+
+      beforeAll(async () => {
+
+        const topicQuery = new GraphQLInteraction()
+          .given('there\'s an error in the response')
+          .uponReceiving('a request to get a single topic')
+          .withRequest({
+            path: '/graphql',
+            method: 'POST'
+          })
+          .withOperation('GetTopic')
+          .withQuery(
+            `query GetTopic($id: ID!) {
+              topic(id: $id) {
+                id
+                title
+                updated_at
+                ttl
+                forum {
+                  id
+                  glyph
+                  label
+                  __typename
+                }
+                tags {
+                  id
+                  weight
+                  __typename
+                }
+                posts {
+                  id
+                  text
+                  created_at
+                  author {
+                    id
+                    handle
+                    __typename
+                  }
+                  __typename
+                }
+                __typename
+              }
+            }`
+          )
+          .withVariables({
+            id: '0b58959d-d448-4a4e-84b6-35e5ac0028d1'
+          })
+          .willRespondWith({
+            status: 200,
+            headers: {
+              'Content-Type': 'application/json; charset=utf-8'
+            },
+            body: {
+              errors: eachLike({
+                message: like('An error occurred when fetching the topic')
+              })
+            }
+          });
+        return await internals.provider.addInteraction(topicQuery);
+      });
+
+      test('it returns the error', async () => {
+
+        const topic = getTopic('0b58959d-d448-4a4e-84b6-35e5ac0028d1');
+        const { counter, promise: resolveAfterTwo } = resolveAfter(2);
+        let response = null;
+        topic.subscribe((topicValue) => {
+
+          response = topicValue;
+          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.graphQLErrors).toEqual(expect.arrayContaining([{
+          message: 'An error occurred when fetching the topic'
+        }]));
+      });
+    });
+  });
 });
 });