server stuff

This commit is contained in:
Tyrel Souza 2017-11-30 22:33:22 -05:00
parent 33b68638d3
commit 4e33fe7343
3 changed files with 36 additions and 3 deletions

View File

@ -4,9 +4,13 @@
"description": "yeahhh", "description": "yeahhh",
"main": "server/server.js", "main": "server/server.js",
"scripts": { "scripts": {
"start": "node server/server.js",
"test": "mocha server/**/*.test.js", "test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'" "test-watch": "nodemon --exec 'npm test'"
}, },
"engines":{
"node": "8.9.1",
},
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",

View File

@ -8,6 +8,7 @@ var {User} = require('./models/user')
var {Todo} = require('./models/todo') var {Todo} = require('./models/todo')
var app = express(); var app = express();
const port = process.env.PORT || 8888;
app.use(bodyParser.json()); app.use(bodyParser.json());
@ -47,8 +48,8 @@ app.get('/todos/:id', (req, res) => {
app.listen(8888, () => { app.listen(port, () => {
console.log("Started on port 8888"); console.log(`Started on port ${port}`);
}); });
module.exports = {app} module.exports = {app}

View File

@ -1,10 +1,14 @@
const expect = require('expect'); const expect = require('expect');
const request = require('supertest'); const request = require('supertest');
const {ObjectID} = require('mongodb');
const {app} = require('./../server'); const {app} = require('./../server');
const {Todo} = require('./../models/todo'); const {Todo} = require('./../models/todo');
var dummy = [ {text: 'One'}, {text: 'Two'}, {text: 'Three'} ]; var dummy = [
{_id: new ObjectID(), text: 'One'},
{_id: new ObjectID(), text: 'Two'},
{_id: new ObjectID(), text: 'Three'} ];
beforeEach((done) => { beforeEach((done) => {
@ -70,3 +74,27 @@ describe("GET /todos", () => {
.end(done); .end(done);
}) })
}) })
describe("GET /todos/:id", () => {
it("should get a single todo", (done) => {
request(app)
.get(`/todos/${dummy[0]._id.toHexString()}`)
.expect(200)
.expect((res) => {
expect(res.body.todo.text).toBe(dummy[0].text)
})
.end(done)
})
it("should return a 404 if todo not found", (done) => {
request(app)
.get(`/todos/${new ObjectID()}`)
.expect(404)
.end(done)
})
it("should return a 404 if id is bad", (done) => {
request(app)
.get(`/todos/${dummy[0]._id.toHexString()}11111`)
.expect(404)
.end(done)
})
});