mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-13 22:45:57 +00:00
Triyng to setup api tests
This commit is contained in:
@@ -41,6 +41,8 @@
|
|||||||
"app-module-path": "^2.1.0",
|
"app-module-path": "^2.1.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"chai-as-promised": "^6.0.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
33
test/brew.apitest.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
@@ -8,20 +8,19 @@ const BrewDB = require('../server/brew.data.js');
|
|||||||
|
|
||||||
describe('BrewDB', () => {
|
describe('BrewDB', () => {
|
||||||
|
|
||||||
it('generates ID on save', (done) => {
|
before('Await DB', ()=>{
|
||||||
|
return require('db.js').connect();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('generates ID on save', () => {
|
||||||
return BrewDB.create({
|
return BrewDB.create({
|
||||||
text : "Brew Text"
|
text : "Brew Text"
|
||||||
}).then((brew) => {
|
}).then((brew) => {
|
||||||
console.log('running?');
|
|
||||||
should.exist(brew);
|
should.exist(brew);
|
||||||
brew.should.have.property('editId').that.is.a('string');
|
brew.should.have.property('editId').that.is.a('string');
|
||||||
brew.should.have.property('shareId').that.is.a('string');
|
brew.should.have.property('shareId').that.is.a('string');
|
||||||
brew.should.have.property('text').that.is.a('string');
|
brew.should.have.property('text').that.is.a('string');
|
||||||
done();
|
});
|
||||||
})
|
|
||||||
.catch(()=>{
|
|
||||||
console.log('yo');
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
require('app-module-path').addPath('./server');
|
||||||
|
|
||||||
// initialize config
|
// initialize config
|
||||||
const config = require('nconf')
|
const config = require('nconf')
|
||||||
@@ -7,11 +8,9 @@ const config = require('nconf')
|
|||||||
.file('environment', { file: `../config/${process.env.NODE_ENV}.json` })
|
.file('environment', { file: `../config/${process.env.NODE_ENV}.json` })
|
||||||
.file('defaults', { file: '../config/default.json' });
|
.file('defaults', { file: '../config/default.json' });
|
||||||
|
|
||||||
// other libs
|
|
||||||
const should = require('chai').use(require('chai-as-promised')).should();
|
const should = require('chai').use(require('chai-as-promised')).should();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
config: config,
|
config: config,
|
||||||
should: should,
|
should: should,
|
||||||
|
|||||||
Reference in New Issue
Block a user