});
});
- 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',
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',
});
});
});
+
+ 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'
+ }]));
+ });
+ });
+ });
});