Guest User

Untitled

a guest
Dec 2nd, 2017
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. import express from 'express';
  2. import GraphQL from 'express-graphql';
  3. import mongoose from 'mongoose';
  4. import bluebird from 'bluebird';
  5. import { tester } from 'graphql-tester';
  6. import Schema from '../../../../graphql';
  7. import { createExpressWrapper } from '../../../../../../test/mockingServer';
  8. import { dropTestDatabase } from '../../../../../../test/fixture';
  9. const chai = require('chai');
  10. const chaiAsPromised = require('chai-as-promised');
  11. const database = require('../../../../../../config/env-config-wespeak');
  12. const dbUri = database.getUri();
  13.  
  14. describe('-- Starting Mocking Express Server --', () => {
  15. mongoose.Promise = bluebird;
  16. mongoose.connect(dbUri, { useMongoClient: true });
  17. chai.use(chaiAsPromised);
  18. chai.should();
  19. const app = express();
  20. const ApiCall = tester({
  21. server: createExpressWrapper(app),
  22. url: '/express/graphql',
  23. });
  24. app.use('/express/graphql', GraphQL({
  25. schema: Schema,
  26. }));
  27.  
  28. let user;
  29. let userID;
  30. describe('GraphQL query doesn`t exist', () => {
  31. const response = ApiCall('{ somethingElse(who: "Graham") }');
  32. it('Returns false', () => response.should.eventually.have.property('success').equal(false));
  33. it('Returns a status code 400', () => response.should.eventually.have.property('status').equal(400));
  34. it('Returns some errors', () => response.should.eventually.have.property('errors'));
  35. });
  36.  
  37. describe('Successful query', () => {
  38. user = ApiCall(`mutation {
  39. addUsers(data: {email: "test@test.com", password: "Test", firstName: "Test", lastName: "Test"}) {
  40. _id
  41. firstName
  42. lastName
  43. email
  44. token
  45. }
  46. }`);
  47.  
  48. describe('Create user who is not in the database', () => {
  49. it('Returns status 200', () => user.should.eventually.have.property('status').equal(200));
  50. it('Returns id different to null', () => user.should.eventually.have.property('data')
  51. .have.property('addUsers').have.property('_id').not.equal(null));
  52. it('Returns a user with good values for firstName property', () => user.should.eventually.have.property('data')
  53. .have.property('addUsers').have.property('firstName').equal('Test'));
  54. it('Returns a user with good values for lastName property', () => user.should.eventually.have.property('data')
  55. .have.property('addUsers').have.property('lastName').equal('Test'));
  56. it('Returns a user with good values for email property', () => user.should.eventually.have.property('data')
  57. .have.property('addUsers').have.property('email').equal('test@test.com'));
  58. xit('Returns a user with good values for token property', () => user.should.eventually.have.property('data')
  59. .have.property('addUsers').have.property('token').not.equal(null));
  60. });
  61.  
  62. describe('Get user', () => {
  63. user.then((result) => {
  64. return JSON.parse(result);
  65. }).then((data) => {
  66. console.log('data', data);
  67. });
  68. const response = ApiCall('{ User(id: "59ea081fc5da77c0b5385ad9") { _id } }');
  69. it('should return status 200', () => response.should.eventually.have.property('status').equal(200));
  70. it('Should have success true', () => response.should.eventually.have.property('success').equal(true));
  71. it('ID is equal to id query', () => response.should.eventually
  72. .have.property('data').have.property('User').have.property('_id')
  73. .not.equal(null));
  74. });
  75. });
  76. afterEach(() => {
  77. dropTestDatabase();
  78. });
  79. });
Add Comment
Please, Sign In to add comment