Skip to content

Commit

Permalink
use response.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 6, 2022
1 parent 7277722 commit b8fe823
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion examples/node-esm/__integration-tests__/esm.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Node ESM', () => {
}),
})
expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data.greetings).toBe('Hello world!')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ it('should expose Node req and res objects in the context', async () => {
`http://localhost:${port}/graphql?query=query{isNode}`,
)
expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.isNode).toBe(true)
} finally {
Expand Down
26 changes: 13 additions & 13 deletions packages/graphql-yoga/__tests__/error-masking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('error masking', () => {
body: JSON.stringify({ query: '{ hi hello }' }),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data.hi).toBeNull()
expect(body.errors![0].message).toBe('Unexpected error.')
expect(body.data.hello).toBeNull()
Expand All @@ -57,7 +57,7 @@ describe('error masking', () => {
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query: '{ hi hello }' }),
})
const body = JSON.parse(await response.text())
const body = await response.json()

expect(body.data.hi).toBeNull()
expect(body.errors![0].message).toBe('Hahahaha')
Expand All @@ -77,7 +77,7 @@ describe('error masking', () => {
body: JSON.stringify({ query: '{ hi hello }' }),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data.hi).toBeNull()
expect(body.errors![0].message).toBe('Unexpected error.')
expect(body.data.hello).toBeNull()
Expand All @@ -99,7 +99,7 @@ describe('error masking', () => {
body: JSON.stringify({ query: '{ hi hello }' }),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data.hi).toBeNull()
expect(body.errors?.[0]?.message).toBe('Unexpected error.')
expect(body.errors?.[0]?.extensions).toStrictEqual({
Expand Down Expand Up @@ -129,7 +129,7 @@ describe('error masking', () => {
body: JSON.stringify({ query: '{ hi hello }' }),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data.hi).toBeNull()
expect(body.errors?.[0]?.message).toBe('Unexpected error.')
expect(body.errors?.[0]?.extensions).toStrictEqual({
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('error masking', () => {

expect(response.status).toBe(500)

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors?.[0]?.message).toBe('Unexpected error.')
})

Expand All @@ -184,7 +184,7 @@ describe('error masking', () => {
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query: '{ __typename }' }),
})
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body).toMatchInlineSnapshot(`
Object {
"errors": Array [
Expand All @@ -210,7 +210,7 @@ describe('error masking', () => {
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query: '{ __typename }' }),
})
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body).toMatchInlineSnapshot(`
Object {
"errors": Array [
Expand All @@ -236,7 +236,7 @@ describe('error masking', () => {
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query: '{ __typename }' }),
})
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body).toMatchInlineSnapshot(`
Object {
"errors": Array [
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('error masking', () => {
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ query: '{ greetings }' }),
})
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body).toMatchInlineSnapshot(`
Object {
"errors": Array [
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('error masking', () => {
})

expect(response.status).toEqual(400)
const body = JSON.parse(await response.text())
const body = await response.json()

expect(body).toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('error masking', () => {
})

expect(response.status).toEqual(400)
const body = JSON.parse(await response.text())
const body = await response.json()

expect(body).toMatchInlineSnapshot(`
Object {
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('error masking', () => {
body: JSON.stringify({ query: '{a}' }),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body).toStrictEqual({
errors: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-yoga/__tests__/http-extensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('GraphQLError.extensions.http', () => {

expect(response.status).toBe(503)

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body).toMatchObject({
data: {
a: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-yoga/__tests__/introspection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('introspection', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data?.__schema.queryType.name).toBe('Query')
})
Expand Down
28 changes: 14 additions & 14 deletions packages/graphql-yoga/__tests__/requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('requests', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.ping).toBe('pong')
})
Expand All @@ -57,7 +57,7 @@ describe('requests', () => {
)

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.ping).toBe('pong')
})
Expand All @@ -75,7 +75,7 @@ describe('requests', () => {
expect(response.status).toBe(405)

expect(response.headers.get('allow')).toEqual('POST')
const body = JSON.parse(await response.text())
const body = await response.json()

expect(body.data).toBeUndefined()
expect(body.errors).toHaveLength(1)
Expand All @@ -98,7 +98,7 @@ describe('requests', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.echo).toBe(null)
})
Expand All @@ -118,7 +118,7 @@ describe('requests', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.echo).toBe('hello')
})
Expand All @@ -131,7 +131,7 @@ describe('requests', () => {
})
expect(response.status).toBe(400)

const body = JSON.parse(await response.text())
const body = await response.json()

expect(body.errors).toBeDefined()
expect(body.data).toBeUndefined()
Expand All @@ -145,7 +145,7 @@ describe('requests', () => {
})
expect(response.status).toBe(400)

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeDefined()
expect(body.errors[0].message).toEqual('POST body sent invalid JSON.')

Expand All @@ -161,7 +161,7 @@ describe('requests', () => {

expect(response.status).toBe(400)

const body = JSON.parse(await response.text())
const body = await response.json()

expect(body.errors).toBeDefined()
expect(body.data).toBeUndefined()
Expand All @@ -176,7 +176,7 @@ describe('requests', () => {

expect(response.status).toBe(400)

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data).toBeUndefined()
expect(body.errors?.[0].message).toBe('Must provide query string.')
})
Expand All @@ -190,7 +190,7 @@ describe('requests', () => {

expect(response.status).toBe(400)

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data).toBeUndefined()
expect(body.errors?.[0].message).toBe(
'Expected "query" param to be a string, but given object.',
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('requests', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.ping).toBe('pong')
})
Expand All @@ -239,7 +239,7 @@ describe('requests', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.ping).toBe('pong')
})
Expand All @@ -254,7 +254,7 @@ describe('requests', () => {
})

expect(response.status).toBe(200)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.ping).toBe('pong')
})
Expand All @@ -269,7 +269,7 @@ describe('requests', () => {
})

expect(response.status).toBe(400)
const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.data).toBeUndefined()
expect(body.errors?.[0].message).toBe(
'Unexpected parameter "test" in the request body.',
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/apq/__tests__/apq.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Automatic Persisted Queries', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeDefined()
expect(body.errors[0].message).toBe('PersistedQueryNotFound')
})
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('Automatic Persisted Queries', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.__typename).toBe('Query')
})
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('Automatic Persisted Queries', () => {
const entry = store.get(persistedQueryEntry.sha256Hash)
expect(entry).toBe(query)

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.__typename).toBe('Query')
})
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('Automatic Persisted Queries', () => {
})

expect(response.status).toEqual(500)
expect(JSON.parse(await response.text())).toEqual({
expect(await response.json()).toEqual({
errors: [{ message: 'PersistedQueryMismatch' }],
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Persisted Operations', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeDefined()
expect(body.errors[0].message).toBe('PersistedQueryNotFound')
})
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('Persisted Operations', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data.__typename).toBe('Query')
})
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('Persisted Operations', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeDefined()
expect(body.errors[0].message).toBe('PersistedQueryOnly')
})
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Persisted Operations', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data).toEqual({ __typename: 'Query' })
})
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('Persisted Operations', () => {
}),
})

const body = JSON.parse(await response.text())
const body = await response.json()
expect(body.errors).toBeUndefined()
expect(body.data).toEqual({ __typename: 'Query' })
})
Expand Down

0 comments on commit b8fe823

Please sign in to comment.