aboutsummaryrefslogtreecommitdiff
path: root/src/stores/topics.test.js
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2021-05-03 20:59:55 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2021-05-03 20:59:55 +0200
commit26dfa00e2f4eddbdc71ae4d92ee5676f11413ada (patch)
tree9df324ee7c3b9350e521018d35b0b18f5eef4fc9 /src/stores/topics.test.js
parent3435a35ccb828fe81720d057e38eaa4223e917a7 (diff)
Add tests for actions + pacts for graphql errrors
Diffstat (limited to 'src/stores/topics.test.js')
-rw-r--r--src/stores/topics.test.js91
1 files changed, 89 insertions, 2 deletions
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'
+ }]));
+ });
+ });
+ });
});