2018-04-18 05:38:57 -07:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
import { expect } from 'chai';
|
|
|
|
import { stub } from 'sinon';
|
|
|
|
import 'mocha';
|
2018-05-24 15:43:17 -07:00
|
|
|
import * as MockReq from 'mock-req';
|
2018-04-18 05:38:57 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
GraphQLSchema,
|
|
|
|
GraphQLObjectType,
|
|
|
|
GraphQLString,
|
|
|
|
GraphQLInt,
|
|
|
|
} from 'graphql';
|
|
|
|
|
|
|
|
import { runHttpQuery, HttpQueryError } from './runHttpQuery';
|
|
|
|
|
|
|
|
const queryType = new GraphQLObjectType({
|
|
|
|
name: 'QueryType',
|
|
|
|
fields: {
|
|
|
|
testString: {
|
|
|
|
type: GraphQLString,
|
|
|
|
resolve() {
|
|
|
|
return 'it works';
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const schema = new GraphQLSchema({
|
|
|
|
query: queryType,
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('runHttpQuery', () => {
|
|
|
|
describe('handling a GET query', () => {
|
|
|
|
const mockQueryRequest = {
|
|
|
|
method: 'GET',
|
|
|
|
query: {
|
|
|
|
query: '{ testString }',
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
schema,
|
|
|
|
},
|
2018-05-24 15:43:17 -07:00
|
|
|
request: new MockReq(),
|
2018-04-18 05:38:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
it('raises a 400 error if the query is missing', () => {
|
|
|
|
const noQueryRequest = Object.assign({}, mockQueryRequest, {
|
|
|
|
query: 'foo',
|
|
|
|
});
|
|
|
|
return runHttpQuery([], noQueryRequest).catch(err => {
|
|
|
|
expect(err.statusCode).to.equal(400);
|
|
|
|
expect(err.message).to.equal('Must provide query string.');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|