From: Ruben Beltran del Rio Date: Mon, 3 May 2021 18:59:55 +0000 (+0200) Subject: Add tests for actions + pacts for graphql errrors X-Git-Url: https://git.r.bdr.sh/rbdr/forum/commitdiff_plain/26dfa00e2f4eddbdc71ae4d92ee5676f11413ada?ds=sidebyside;hp=3435a35ccb828fe81720d057e38eaa4223e917a7 Add tests for actions + pacts for graphql errrors --- diff --git a/pacts/forumclient-forumserver.json b/pacts/forumclient-forumserver.json index 337ff86..9ec37f8 100644 --- a/pacts/forumclient-forumserver.json +++ b/pacts/forumclient-forumserver.json @@ -6,149 +6,6 @@ "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", @@ -363,7 +220,7 @@ }, { "description": "a request to list the forums", - "providerState": "there's an error", + "providerState": "there's a server error", "request": { "method": "POST", "path": "/graphql", @@ -391,7 +248,7 @@ }, { "description": "a request to get a single forum", - "providerState": "there's an error", + "providerState": "there's a server error", "request": { "method": "POST", "path": "/graphql", @@ -419,8 +276,8 @@ } }, { - "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", @@ -428,16 +285,15 @@ "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": { - "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*\\}" + "regex": "query\\s*GetForums\\s*\\{\\s*forums\\s*\\{\\s*id\\s*glyph\\s*label\\s*position\\s*__typename\\s*\\}\\s*\\}" } } }, @@ -447,48 +303,28 @@ "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": { - "$.body.data.tag.id": { - "match": "type" - }, - "$.body.data.tag.topics": { + "$.body.errors": { "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" }, - "$.body.data.tag.topics[*].ttl": { + "$.body.errors[*].message": { "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", @@ -496,16 +332,16 @@ "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": { - "id": "pineapple" + "id": "freezer" } }, "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*\\}" } } }, @@ -515,39 +351,23 @@ "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": { - "$.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": { - } } }, { @@ -708,7 +528,7 @@ }, { "description": "a request to get a single topic", - "providerState": "there's an error", + "providerState": "there's a server error", "request": { "method": "POST", "path": "/graphql", @@ -734,6 +554,425 @@ "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": { diff --git a/src/stores/actions.js b/src/stores/actions.js index ae01906..f7fbc28 100644 --- a/src/stores/actions.js +++ b/src/stores/actions.js @@ -4,7 +4,7 @@ import { derived, writable } from 'svelte/store'; * This is a store to set the actions in the top header. */ -export const actions = writable({}); +const actions = writable({}); export const enableTopicActions = (id) => { diff --git a/src/stores/actions.test.js b/src/stores/actions.test.js new file mode 100644 index 0000000..c650536 --- /dev/null +++ b/src/stores/actions.test.js @@ -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); + })(); + }); +}); diff --git a/src/stores/forums.test.js b/src/stores/forums.test.js index eb4bc07..732964f 100644 --- a/src/stores/forums.test.js +++ b/src/stores/forums.test.js @@ -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() - .given('there\'s an error') + .given('there\'s a server error') .uponReceiving('a request to list the forums') .withRequest({ path: '/graphql', @@ -379,7 +379,7 @@ describe('Forums store pact', () => { 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', @@ -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' + }])); + }); + }); + }); }); diff --git a/src/stores/posts.test.js b/src/stores/posts.test.js index 5d1fc05..ab17286 100644 --- a/src/stores/posts.test.js +++ b/src/stores/posts.test.js @@ -3,7 +3,7 @@ import { resolve } from 'path'; import { resolveAfter } from '$/utils/resolve_after'; -const { like } = Matchers; +const { eachLike, like } = Matchers; 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() - .given('there\'s an error') + .given('there\'s a server error') .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' + }])); + }); + }); + }); }); diff --git a/src/stores/tags.test.js b/src/stores/tags.test.js index 177919b..bf4fa56 100644 --- a/src/stores/tags.test.js +++ b/src/stores/tags.test.js @@ -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() - .given('there\'s an error') + .given('there\'s a server error') .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' + }])); + }); + }); + }); }); diff --git a/src/stores/topics.test.js b/src/stores/topics.test.js index 280bddb..7c3285b 100644 --- a/src/stores/topics.test.js +++ b/src/stores/topics.test.js @@ -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() - .given('there\'s an error') + .given('there\'s a server error') .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' + }])); + }); + }); + }); });