}`
)
.withVariables({
- id: 'freezer'
+ id: '8f75eba5-6989-4dd3-b466-e464546ce374'
})
.willRespondWith({
status: 200,
test('it returns the post', async () => {
- const post = getPost('freezer');
+ const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374');
const { counter, promise: resolveAfterTwo } = resolveAfter(2);
let response = null;
post.subscribe((postValue) => {
}`
)
.withVariables({
- id: 'freezer'
+ id: '8f75eba5-6989-4dd3-b466-e464546ce374'
})
.willRespondWith({
status: 200,
test('it returns the post', async () => {
- const post = getPost('freezer');
+ const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374');
const { counter, promise: resolveAfterTwo } = resolveAfter(2);
let response = null;
post.subscribe((postValue) => {
});
});
- 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',
}`
)
.withVariables({
- id: 'freezer'
+ id: '8f75eba5-6989-4dd3-b466-e464546ce374'
})
.willRespondWith({
status: 500
test('it returns the error', async () => {
- const post = getPost('freezer');
+ const post = getPost('8f75eba5-6989-4dd3-b466-e464546ce374');
const { counter, promise: resolveAfterTwo } = resolveAfter(2);
let response = null;
post.subscribe((postValue) => {
});
});
});
+
+ 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'
+ }]));
+ });
+ });
+ });
});