X-Git-Url: https://git.r.bdr.sh/rbdr/forum/blobdiff_plain/3435a35ccb828fe81720d057e38eaa4223e917a7..26dfa00e2f4eddbdc71ae4d92ee5676f11413ada:/src/stores/forums.test.js 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' + }])); + }); + }); + }); });