diff --git a/package.json b/package.json index 2b7c8f5..5fd621e 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,8 @@ "app-module-path": "^2.1.0", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", - "mocha": "^3.2.0" + "mocha": "^3.2.0", + "supertest": "^2.0.1", + "supertest-as-promised": "^4.0.2" } } diff --git a/test/brew.apitest.js b/test/brew.apitest.js new file mode 100644 index 0000000..d99b417 --- /dev/null +++ b/test/brew.apitest.js @@ -0,0 +1,33 @@ +const testing = require('./test.init.js'); +const request = require('supertest-as-promised'); + + +const app = require('../server.js') + + +const apiPath = '/api/brew'; + +describe('/api/brew', () => { + + before('Await DB', ()=>{ + return require('db.js').connect(); + }); + + describe('POST', () => { + + it('creates a new brew', () => { + return request(app) + .post(apiPath) + .send({ + text : 'Brew Text' + }) + .expect(200) + .then((res) => { + console.log(res.body); + }); + }); + + }); + + +}); \ No newline at end of file diff --git a/test/brew.datatest.js b/test/brew.datatest.js index 8fbdd00..69946c1 100644 --- a/test/brew.datatest.js +++ b/test/brew.datatest.js @@ -8,20 +8,19 @@ const BrewDB = require('../server/brew.data.js'); describe('BrewDB', () => { - it('generates ID on save', (done) => { + before('Await DB', ()=>{ + return require('db.js').connect(); + }); + + it('generates ID on save', () => { return BrewDB.create({ text : "Brew Text" }).then((brew) => { - console.log('running?'); should.exist(brew); brew.should.have.property('editId').that.is.a('string'); brew.should.have.property('shareId').that.is.a('string'); brew.should.have.property('text').that.is.a('string'); - done(); - }) - .catch(()=>{ - console.log('yo'); - }) + }); }); }); \ No newline at end of file diff --git a/test/test.init.js b/test/test.init.js index f46219e..5205f08 100644 --- a/test/test.init.js +++ b/test/test.init.js @@ -1,3 +1,4 @@ +require('app-module-path').addPath('./server'); // initialize config const config = require('nconf') @@ -7,11 +8,9 @@ const config = require('nconf') .file('environment', { file: `../config/${process.env.NODE_ENV}.json` }) .file('defaults', { file: '../config/default.json' }); -// other libs const should = require('chai').use(require('chai-as-promised')).should(); - module.exports = { config: config, should: should,