mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-19 22:51:29 +00:00
Both types of tests are now working
This commit is contained in:
18
server.js
18
server.js
@@ -25,6 +25,24 @@ app.use(mw.admin);
|
|||||||
app.use(require('./server/brew.api.js'));
|
app.use(require('./server/brew.api.js'));
|
||||||
app.use(require('./server/interface.routes.js'));
|
app.use(require('./server/interface.routes.js'));
|
||||||
|
|
||||||
|
setTimeout(()=>{
|
||||||
|
var test = require('./server/brew.data.js');
|
||||||
|
|
||||||
|
test.create({text : 'test'})
|
||||||
|
.then((brew) => {
|
||||||
|
console.log(brew);
|
||||||
|
})
|
||||||
|
.catch(console.log);
|
||||||
|
|
||||||
|
test.get({})
|
||||||
|
.then((brew) => {
|
||||||
|
console.log(brew);
|
||||||
|
})
|
||||||
|
.catch(console.log);
|
||||||
|
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
//app.use(require('./server/admin.api.js'));
|
//app.use(require('./server/admin.api.js'));
|
||||||
|
|
||||||
|
|||||||
@@ -84,15 +84,6 @@ const BrewData = {
|
|||||||
const newBrew = new Brew(brew);
|
const newBrew = new Brew(brew);
|
||||||
|
|
||||||
return newBrew.save();
|
return newBrew.save();
|
||||||
|
|
||||||
//TODO: add error decorators to the catches
|
|
||||||
const temp = newBrew.save().then(()=>{
|
|
||||||
console.log('SAVED');
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(typeof temp, _.keys(temp), temp);
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
},
|
},
|
||||||
update : (newBrew) => {
|
update : (newBrew) => {
|
||||||
return Brew.findOneAndUpdate({ editId : newBrew.editId },
|
return Brew.findOneAndUpdate({ editId : newBrew.editId },
|
||||||
|
|||||||
@@ -6,13 +6,18 @@ const dbPath = process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb:/
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
connect : ()=>{
|
connect : ()=>{
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject)=>{
|
||||||
mongoose.createConnection(dbPath,
|
if(mongoose.connection.readyState == 1){
|
||||||
|
console.log('already connected');
|
||||||
|
return resolve();
|
||||||
|
}
|
||||||
|
mongoose.connect(dbPath,
|
||||||
(err) => {
|
(err) => {
|
||||||
if(err){
|
if(err){
|
||||||
console.log('Error : Could not connect to a Mongo Database.');
|
console.log('Error : Could not connect to a Mongo Database.');
|
||||||
console.log(' If you are running locally, make sure mongodb.exe is running.');
|
console.log(' If you are running locally, make sure mongodb.exe is running.');
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
|
console.log('mongo connected.');
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
|
const should = require('chai').use(require('chai-as-promised')).should();
|
||||||
const request = require('supertest-as-promised');
|
const request = require('supertest-as-promised');
|
||||||
const app = require('../server.js');
|
const app = require('../server.js');
|
||||||
|
|
||||||
|
|
||||||
const apiPath = '/api/brew';
|
const apiPath = '/api/brew';
|
||||||
|
|
||||||
describe('/api/brew', () => {
|
|
||||||
|
|
||||||
|
describe(apiPath, () => {
|
||||||
|
|
||||||
describe('POST', () => {
|
describe('POST', () => {
|
||||||
|
|
||||||
it('creates a new brew', () => {
|
it('creates a new brew', () => {
|
||||||
return request(app)
|
return request(app)
|
||||||
.post(apiPath)
|
.post(apiPath)
|
||||||
@@ -18,8 +17,12 @@ describe('/api/brew', () => {
|
|||||||
})
|
})
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res.body);
|
const brew = res.body;
|
||||||
});
|
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');
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,38 +1,24 @@
|
|||||||
|
|
||||||
const should = require('chai').use(require('chai-as-promised')).should();
|
const should = require('chai').use(require('chai-as-promised')).should();
|
||||||
|
|
||||||
const BrewDB = require('../server/db.js');
|
const BrewDB = require('../server/db.js');
|
||||||
const BrewData = require('../server/brew.data.js');
|
const BrewData = require('../server/brew.data.js');
|
||||||
|
|
||||||
|
|
||||||
describe.skip('BrewDB', () => {
|
describe('BrewDB', () => {
|
||||||
|
|
||||||
before('Await DB', ()=>{
|
before('Await DB', ()=>{
|
||||||
return BrewDB.connect()
|
return BrewDB.connect().catch()
|
||||||
.then(()=>{
|
|
||||||
console.log('connected');
|
|
||||||
})
|
|
||||||
.catch(()=>{
|
|
||||||
console.log('sdfdsfdsfdsf');
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates ID on save', (done) => {
|
it('generates ID on save', () => {
|
||||||
console.log('getting here');
|
|
||||||
return BrewData.create({
|
return BrewData.create({
|
||||||
text : "Brew Text"
|
text : "Brew Text"
|
||||||
}).then((brew) => {
|
}).then((brew) => {
|
||||||
console.log('here2');
|
|
||||||
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');
|
||||||
console.log('and I am done');
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.log('an error', e);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user