Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save javierfernandes/f808eb8618a7d1b0e4698708771e048f to your computer and use it in GitHub Desktop.

Select an option

Save javierfernandes/f808eb8618a7d1b0e4698708771e048f to your computer and use it in GitHub Desktop.
import { graphql } from 'graphql'
import mongoose from 'mongoose'
import { Mockgoose } from 'mockgoose'
import rtm from '../../src/features/rtm'
import '../../src/models/all'
import { expect } from 'chai'
import { compileSchemas } from '../../src/graphql/utils/compileSchema'
// subscriptiosn
import WebSocket from 'ws'
import { SubscriptionClient } from 'subscriptions-transport-ws';
import ApolloClient from 'apollo-client'
const GRAPHQL_ENDPOINT = 'ws://localhost:5000/subscriptions';
const internalDescribeQL = (describeFn) => (title, body) => {
describeFn(title, () => {
// context
let schema
let apollo
let networkInterface
const mockgoose = new Mockgoose(mongoose);
before(async () => {
await mockgoose.prepareStorage()
await mongoose.connect('mongodb://example.com/TestingDB')
schema = compileSchemas()
await rtm.setup({})
// subscriptions
networkInterface = new SubscriptionClient(GRAPHQL_ENDPOINT, { reconnect: true }, WebSocket)
apollo = new ApolloClient({ networkInterface })
})
after(done => {
rtm.teardown()
networkInterface.close()
mongoose.disconnect(done)
})
beforeEach(() => {
mockgoose.helper.reset()
})
// utils functions for tests
const expectQuery = async(query, expected) =>
expect(await execGraphQL(query)).to.deep.equal(expected)
const expectQueryResult = (query, expected) => expectQuery(query, { data: expected })
const execGraphQL = query => graphql(schema, query, undefined, { })
const client = () => apollo
// interpret body
body({ expectQuery, expectQueryResult, execGraphQL, client }, schema)
})
}
export const describeGQL = internalDescribeQL(describe)
describeGQL.only = internalDescribeQL(describe.only)
describeGQL.skip = internalDescribeQL(describe.skip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment