From b960ecdd94e7d07742bb75a3359371f4c7c88113 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Fri, 29 Jan 2016 11:13:39 +0100 Subject: [PATCH] first attempt to fix fialing api-v3 tests --- test/README.md | 5 ----- test/api/README.md | 8 +++++--- test/helpers/api-integration/mongo.js | 6 ++---- test/helpers/api-integration/requester.js | 4 +++- test/helpers/api-unit.helper.js | 3 --- test/helpers/common.helper.js | 1 - test/helpers/globals.helper.js | 1 - test/mocha.opts | 1 - 8 files changed, 10 insertions(+), 19 deletions(-) delete mode 100644 test/README.md diff --git a/test/README.md b/test/README.md deleted file mode 100644 index 8115753727..0000000000 --- a/test/README.md +++ /dev/null @@ -1,5 +0,0 @@ -We need to clean up this directory. The *real* tests are in spec/ mock/ e2e/ and api.mocha.coffee. We want to: - -1. Move all old / deprecated tests from casper, test2, etc into spec, mock, e2e -1. Remove dependency of api.mocha.coffee on Derby, port it to Mongoose -1. Add better test-coverage diff --git a/test/api/README.md b/test/api/README.md index b5223cc0f4..ff3296721f 100644 --- a/test/api/README.md +++ b/test/api/README.md @@ -1,5 +1,7 @@ # So you want to write API integration tests? +@TODO rewrite + That's great! This README will serve as a quick primer for style conventions and practices for these tests. ## What is this? @@ -73,7 +75,7 @@ POST-groups_id_leave.test.js To mitigate [callback hell](http://callbackhell.com/) :imp:, we've written a helper method to generate a user object that can make http requests that [return promises](https://babeljs.io/docs/learn-es2015/#promises). This makes it very easy to chain together commands. All you need to do to make a subsequent request is return another promise and then call `.then((result) => {})` on the surrounding block, like so: ```js -it('does something', () => { +it('does something', () => { let user; return generateUser().then((_user) => { // We return the initial promise so this test can be run asyncronously @@ -97,7 +99,7 @@ it('does something', () => { If the test is simple, you can use the [chai-as-promised](http://chaijs.com/plugins/chai-as-promised) `return expect(somePromise).to.eventually` syntax to make your assertion. ```js -it('makes the party creator the leader automatically', () => { +it('makes the party creator the leader automatically', () => { return expect(user.post('/groups', { type: 'party', })).to.eventually.have.deep.property('leader._id', user._id); @@ -107,7 +109,7 @@ it('makes the party creator the leader automatically', () => { If the test is checking that the request returns an error, use the `.eventually.be.rejected.and.eql` syntax. ```js -it('returns an error', () => { +it('returns an error', () => { return expect(user.get('/groups/id-of-a-party-that-user-does-not-belong-to')) .to.eventually.be.rejected.and.eql({ code: 404, diff --git a/test/helpers/api-integration/mongo.js b/test/helpers/api-integration/mongo.js index bbe22496b6..e3db242fd3 100644 --- a/test/helpers/api-integration/mongo.js +++ b/test/helpers/api-integration/mongo.js @@ -1,9 +1,7 @@ /* eslint-disable no-use-before-define */ - +import nconf from 'nconf'; import { MongoClient as mongo } from 'mongodb'; -const DB_URI = 'mongodb://localhost/habitrpg_test'; - // Useful for checking things that have been deleted, // but you no longer have access to, // like private parties or users @@ -81,7 +79,7 @@ export async function getDocument (collectionName, doc) { export function connectToMongo () { return new Promise((resolve, reject) => { - mongo.connect(DB_URI, (err, db) => { + mongo.connect(nconf.get('NODE_DB_URI'), (err, db) => { if (err) return reject(err); resolve(db); diff --git a/test/helpers/api-integration/requester.js b/test/helpers/api-integration/requester.js index de090f54aa..be2ea5c817 100644 --- a/test/helpers/api-integration/requester.js +++ b/test/helpers/api-integration/requester.js @@ -1,8 +1,10 @@ /* eslint-disable no-use-before-define */ import superagent from 'superagent'; +import nconf from 'nconf'; +import app from '../../../website/src/server'; -const API_TEST_SERVER_PORT = 3003; +const API_TEST_SERVER_PORT = nconf.get('PORT'); let apiVersion; // Sets up an abject that can make all REST requests diff --git a/test/helpers/api-unit.helper.js b/test/helpers/api-unit.helper.js index 0a4a22df79..8988ca684a 100644 --- a/test/helpers/api-unit.helper.js +++ b/test/helpers/api-unit.helper.js @@ -4,9 +4,6 @@ import { defaultsDeep as defaults } from 'lodash'; import { model as User } from '../../website/src/models/user'; import { model as Group } from '../../website/src/models/group'; -mongoose.Promise = require('q').Promise; - -mongoose.connect('mongodb://localhost/habitica-unit-tests'); let connection = mongoose.connection; before((done) => { diff --git a/test/helpers/common.helper.js b/test/helpers/common.helper.js index 5e526c1424..5e0660d3c4 100644 --- a/test/helpers/common.helper.js +++ b/test/helpers/common.helper.js @@ -1,6 +1,5 @@ import mongoose from 'mongoose'; import Q from 'q'; -mongoose.Promise = Q.Promise; import { wrap as wrapUser } from '../../common/script/index'; import { model as User } from '../../website/src/models/user'; diff --git a/test/helpers/globals.helper.js b/test/helpers/globals.helper.js index 19f3ebfc71..f08df055fd 100644 --- a/test/helpers/globals.helper.js +++ b/test/helpers/globals.helper.js @@ -1,5 +1,4 @@ /* eslint-disable no-undef */ -require('babel-core/register'); //------------------------------ // Global modules //------------------------------ diff --git a/test/mocha.opts b/test/mocha.opts index bcdefd3e55..c55b351ceb 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -5,5 +5,4 @@ --growl --globals io --compilers js:babel-core/register ---require test/api-legacy/api-helper --require ./test/helpers/globals.helper