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