Skip to content

Commit

Permalink
chore: clean up integration tests as it isn't necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
longility authored and kettanaito committed Jun 12, 2021
1 parent bcd72bc commit 4c9b7f2
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 2,080 deletions.
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"test:smoke": "config/scripts/smoke.sh",
"test:ts": "tsc -p test/typings/tsconfig.json",
"test:focused": "node node_modules/ts-node/dist/bin.js --project=test/tsconfig.json test/focusedTest.ts",
"codegen:test": "graphql-codegen --config test/graphql-api/typed-document-node.codegen.yml",
"prepublishOnly": "yarn lint && yarn test:unit && yarn build && yarn test:integration",
"postinstall": "node -e \"try{require('./config/scripts/postinstall')}catch(e){}\""
},
Expand Down Expand Up @@ -89,10 +88,6 @@
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.2",
"@graphql-codegen/cli": "^1.21.5",
"@graphql-codegen/typed-document-node": "^1.18.6",
"@graphql-codegen/typescript": "^1.22.1",
"@graphql-codegen/typescript-operations": "^1.18.0",
"@open-draft/test-server": "^0.2.3",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-inject": "^4.0.2",
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions src/graphql.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { graphql } from './graphql'
import {
GetUserDetailDocument,
GetUserDetailQueryVariables,
LoginDocument,
LoginMutationVariables,
} from './graphql.test-data'

test('exports supported GraphQL operation types', () => {
expect(graphql).toBeDefined()
Expand All @@ -9,3 +15,25 @@ test('exports supported GraphQL operation types', () => {
'link',
])
})

test('pass proper type to request variable and data payload parameter for query', () => {
const op = graphql.query(GetUserDetailDocument, (req, res, ctx) => {
// If type doesn't match, this should fail compilation
const variables: GetUserDetailQueryVariables = req.variables

// MANUAL VERIFICATION: intellisense on `ctx.data` should be of type `DataContext<GetUserDetailQuery>`.
// Not sure how to test this.
ctx.data
})
})

test('pass proper type to request variable and data payload parameter for mutation', () => {
const op = graphql.mutation(LoginDocument, (req, res, ctx) => {
// If type doesn't match, this should fail compilation
const variables: LoginMutationVariables = req.variables

// MANUAL VERIFICATION: intellisense on `ctx.data` should be of type `DataContext<LoginMutation>`.
// Not sure how to test this.
ctx.data
})
})
97 changes: 3 additions & 94 deletions src/handlers/GraphQLHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DocumentNode } from 'graphql'
import { Headers } from 'headers-utils/lib'
import { context } from '..'
import { createMockedRequest } from '../../test/support/utils'
import { GetUserDetailDocument, LoginDocument } from '../graphql.test-data'
import { response } from '../response'
import {
GraphQLContext,
Expand Down Expand Up @@ -82,50 +83,9 @@ describe('info', () => {
})

test('parses operation name out of DocumentNode for query', () => {
const getUserDetailDocument: DocumentNode = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: { kind: 'Name', value: 'GetUserDetail' },
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {
kind: 'Variable',
name: { kind: 'Name', value: 'userId' },
},
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'String' },
},
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'user' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
],
},
},
],
},
},
],
}
const handler = new GraphQLHandler(
'query',
getUserDetailDocument,
GetUserDetailDocument,
'*',
resolver,
)
Expand All @@ -139,58 +99,7 @@ describe('info', () => {
})

test('parses operation name out of DocumentNode for mutation', () => {
const loginDocument: DocumentNode = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'mutation',
name: { kind: 'Name', value: 'Login' },
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: {
kind: 'Variable',
name: { kind: 'Name', value: 'username' },
},
type: {
kind: 'NonNullType',
type: {
kind: 'NamedType',
name: { kind: 'Name', value: 'String' },
},
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'login' },
arguments: [
{
kind: 'Argument',
name: { kind: 'Name', value: 'username' },
value: {
kind: 'Variable',
name: { kind: 'Name', value: 'username' },
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
],
},
},
],
},
},
],
}
const handler = new GraphQLHandler('mutation', loginDocument, '*', resolver)
const handler = new GraphQLHandler('mutation', LoginDocument, '*', resolver)

expect(handler.info).toHaveProperty('header', 'mutation Login (origin: *)')
expect(handler.info).toHaveProperty('operationType', 'mutation')
Expand Down
8 changes: 0 additions & 8 deletions test/graphql-api/typed-document-node.codegen.yml

This file was deleted.

109 changes: 0 additions & 109 deletions test/graphql-api/typed-document-node.node.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions test/graphql-api/typed-document-node.schema.graphql

This file was deleted.

Loading

0 comments on commit 4c9b7f2

Please sign in to comment.