apollo-server/packages/graphql-server-restify/src/restifyApollo.test.ts

47 lines
1.4 KiB
TypeScript
Raw Normal View History

import 'mocha';
import * as restify from 'restify';
import { graphiqlRestify, graphqlRestify } from './restifyApollo';
import testSuite, { schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
import { expect } from 'chai';
import { GraphQLOptions } from 'graphql-server-core';
function createApp(options: CreateAppOptions = {}) {
const server = restify.createServer({
name: 'Restify Test Server',
});
options.graphqlOptions = options.graphqlOptions || { schema };
if (!options.excludeParser) {
server.use(restify.bodyParser());
server.use(restify.queryParser());
}
if (options.graphiqlOptions ) {
server.get('/graphiql', graphiqlRestify( options.graphiqlOptions ));
}
server.get('/graphql', graphqlRestify(options.graphqlOptions));
server.post('/graphql', graphqlRestify(options.graphqlOptions));
2016-10-24 12:39:17 -07:00
return server;
}
describe('graphqlRestify', () => {
it('throws error if called without schema', () => {
expect(() => graphqlRestify(undefined as GraphQLOptions)).to.throw('Apollo Server requires options.');
});
it('throws an error if called with more than one argument', () => {
expect(() => (<any>graphqlRestify)({}, 'x')).to.throw(
'Apollo Server expects exactly one argument, got 2');
});
it('generates a function if the options are ok', () => {
expect(() => graphqlRestify({ schema })).to.be.a('function');
});
});
describe('integration:Restify', () => {
testSuite(createApp);
});