1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-15 22:26:01 +00:00

adding in some api tests

This commit is contained in:
Scott Tolksdorf
2017-01-01 17:47:26 -08:00
parent 5ba3f98696
commit 10f4759471
6 changed files with 68 additions and 14 deletions

37
api.test.js Normal file
View File

@@ -0,0 +1,37 @@
const request = require('superagent');
const brewData = require('./server/brew.data.js');
const path = 'localhost:8000';
request.post(`${path}/api/brew`)
.send({
text : 'new brew'
})
.end((err, res) => {
console.log(err, res && res.body);
console.log('creaitng brew');
//creating brew
brewData.create({
text : 'yeah yeah'
})
.then((brew) => {
console.log(brew);
})
.catch((e) => {
console.log(e);
})
/*
res.body.text = 'check it';
brewData.update(res.body)
.then((newBrew) => {
console.log(newBrew);
})
.catch((e) => {
console.log(e);
})
*/
})

View File

@@ -36,6 +36,9 @@ app.use(require('./server/interface.routes.js'));
//app.use(require('./server/admin.api.js'));
//Error Handler
app.use(require('./server/error.js').expressHandler);
const PORT = process.env.PORT || 8000;
app.listen(PORT);
console.log(`server on port:${PORT}`);

View File

@@ -9,6 +9,7 @@ router.get('/api/brew', (req, res, next) => {
//TODO
});
//Get

View File

@@ -78,6 +78,7 @@ const BrewData = {
return Brew.findOne(query).exec();
},
create : (brew) => {
console.log('here');
delete brew.shareId;
delete brew.editId;

26
server/error.js Normal file
View File

@@ -0,0 +1,26 @@
const ApiError = require('egads').extend('Server Error', 500, 'Generic Server Error');
ApiError.noBrew = ApiError.extend('Can not find a brew with that id', 404);
ApiError.expressHandler = (err, req, res, next) => {
if(err instanceof ApiError){
return res.status(err.status).send({
type : err.name,
message : err.message
});
}
//If server error, print the whole stack for debugging
return res.status(500).send({
message : err.message,
stack : err.stack
});
};
module.exports = ApiError;

View File

@@ -1,14 +0,0 @@
const egads = require('egads');
const Error = egads.extend('Server Error', 500, 'Generic Server Error');
Error.noBrew = Error.extend('Can not find a brew with that id', 404);
module.exports = Error;