Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
✅ Add tests for #48
  • Loading branch information
khaosdoctor committed Jul 31, 2020
1 parent 8452381 commit d72210b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -49,11 +49,13 @@
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.8",
"@types/nock": "^11.1.0",
"@types/node": "^14.0.27",
"concurrently": "^5.2.0",
"conduct": "^2.3.1",
"husky": "^4.2.5",
"jest": "^26.2.2",
"nock": "^13.0.3",
"pre-push": "^0.1.1",
"standard": "^14.3.4",
"ts-jest": "^26.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/runner.ts
Expand Up @@ -66,7 +66,7 @@ function getPayload (headers: UserOptions['headers'], query: QueryType, parsedQu
operationName: query.name || null,
variables: getQueryVariables(query.variables) || null
},
http2: true
http2: false
}

info('Payload to be sent: %O', returnObject)
Expand Down
31 changes: 29 additions & 2 deletions tests/runner.test.ts
@@ -1,6 +1,7 @@
import { run as runner } from '../src/modules/runner'
import { GotQL } from '../src/types/generics'
import got, { Got as GotInstance } from 'got'
import intercept from 'nock'

declare type got = {
post: Function
Expand Down Expand Up @@ -36,7 +37,7 @@ const defaultHeaders = {
}

const defaultPayload = {
http2: true
http2: false
}

const parseToGotInstance = (gotInstance: got | undefined): GotInstance => gotInstance as GotInstance
Expand Down Expand Up @@ -165,7 +166,33 @@ describe('runner', () => {
await expect(() => response).rejects.toThrowError('Runner error: Error when executing query: error')
})

it.todo('Should successfully handle a simple query errors with custom codes')
it('Should successfully executes when the user passes on an extended Got instance (#48)', async () => {
test.context.endpointIp = 'https://somedns.com/'
const query = {
operation: {
name: 'TestOp',
fields: ['t1', 't2']
}
}

const expectedResponse = {
data: 'Simple data',
endpoint: test.context.endpointIp,
statusCode: 200,
message: 'OK'
}

intercept(test.context.endpointIp)
.post('/')
.reply(200, expectedResponse)

const customInstance = got.extend({ timeout: 1000 })
const gotSpy = jest.spyOn(customInstance, 'post')

const response = await runner(test.context.endpointIp, query, GotQL.ExecutionType.QUERY, customInstance)
expect(gotSpy).toBeCalledTimes(1)
expect(response).toEqual(expectedResponse)
})

it('Should successfully handle a simple query with custom headers', async () => {
const query = {
Expand Down

0 comments on commit d72210b

Please sign in to comment.