1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-13 20:25:58 +00:00

Triyng to setup api tests

This commit is contained in:
Scott Tolksdorf
2017-01-01 17:06:44 -08:00
parent a0bc4fddf8
commit 537a75b2ab
4 changed files with 43 additions and 10 deletions

View File

@@ -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"
}
}

33
test/brew.apitest.js Normal file
View File

@@ -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);
});
});
});
});

View File

@@ -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');
})
});
});
});

View File

@@ -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,