Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import express from 'express';
- import GraphQL from 'express-graphql';
- import mongoose from 'mongoose';
- import bluebird from 'bluebird';
- import { tester } from 'graphql-tester';
- import Schema from '../../../../graphql';
- import { createExpressWrapper } from '../../../../../../test/mockingServer';
- import { dropTestDatabase } from '../../../../../../test/fixture';
- const chai = require('chai');
- const chaiAsPromised = require('chai-as-promised');
- const database = require('../../../../../../config/env-config-wespeak');
- const dbUri = database.getUri();
- describe('-- Starting Mocking Express Server --', () => {
- mongoose.Promise = bluebird;
- mongoose.connect(dbUri, { useMongoClient: true });
- chai.use(chaiAsPromised);
- chai.should();
- const app = express();
- const ApiCall = tester({
- server: createExpressWrapper(app),
- url: '/express/graphql',
- });
- app.use('/express/graphql', GraphQL({
- schema: Schema,
- }));
- let user;
- let userID;
- describe('GraphQL query doesn`t exist', () => {
- const response = ApiCall('{ somethingElse(who: "Graham") }');
- it('Returns false', () => response.should.eventually.have.property('success').equal(false));
- it('Returns a status code 400', () => response.should.eventually.have.property('status').equal(400));
- it('Returns some errors', () => response.should.eventually.have.property('errors'));
- });
- describe('Successful query', () => {
- user = ApiCall(`mutation {
- addUsers(data: {email: "test@test.com", password: "Test", firstName: "Test", lastName: "Test"}) {
- _id
- firstName
- lastName
- email
- token
- }
- }`);
- describe('Create user who is not in the database', () => {
- it('Returns status 200', () => user.should.eventually.have.property('status').equal(200));
- it('Returns id different to null', () => user.should.eventually.have.property('data')
- .have.property('addUsers').have.property('_id').not.equal(null));
- it('Returns a user with good values for firstName property', () => user.should.eventually.have.property('data')
- .have.property('addUsers').have.property('firstName').equal('Test'));
- it('Returns a user with good values for lastName property', () => user.should.eventually.have.property('data')
- .have.property('addUsers').have.property('lastName').equal('Test'));
- it('Returns a user with good values for email property', () => user.should.eventually.have.property('data')
- .have.property('addUsers').have.property('email').equal('test@test.com'));
- xit('Returns a user with good values for token property', () => user.should.eventually.have.property('data')
- .have.property('addUsers').have.property('token').not.equal(null));
- });
- describe('Get user', () => {
- user.then((result) => {
- return JSON.parse(result);
- }).then((data) => {
- console.log('data', data);
- });
- const response = ApiCall('{ User(id: "59ea081fc5da77c0b5385ad9") { _id } }');
- it('should return status 200', () => response.should.eventually.have.property('status').equal(200));
- it('Should have success true', () => response.should.eventually.have.property('success').equal(true));
- it('ID is equal to id query', () => response.should.eventually
- .have.property('data').have.property('User').have.property('_id')
- .not.equal(null));
- });
- });
- afterEach(() => {
- dropTestDatabase();
- });
- });
Add Comment
Please, Sign In to add comment