config stuff
This commit is contained in:
parent
adc036877d
commit
0eb649c3cd
@ -5,8 +5,8 @@
|
|||||||
"main": "server/server.js",
|
"main": "server/server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server/server.js",
|
"start": "node server/server.js",
|
||||||
"test": "mocha server/**/*.test.js",
|
"test": "NODE_ENV=test mocha server/**/*.test.js",
|
||||||
"test-watch": "nodemon --exec 'npm test'"
|
"test-watch": "NODE_ENV=test nodemon --exec 'npm test'"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "8.9.1"
|
"node": "8.9.1"
|
||||||
|
7
server/config/config.js
Normal file
7
server/config/config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
var env = process.env.NODE_ENV || 'development';
|
||||||
|
if (env === 'development') {
|
||||||
|
process.env.PORT = 8888;
|
||||||
|
process.env.MONGODB_URI = 'mongodb://127.0.0.1:27017/TodoApp'
|
||||||
|
} else if (env === 'test') {
|
||||||
|
process.env.MONGODB_URI = 'mongodb://127.0.0.1:27017/TodoAppTest'
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
var mongoose = require('mongoose');
|
var mongoose = require('mongoose');
|
||||||
mongoose.Promise = global.Promise;
|
mongoose.Promise = global.Promise;
|
||||||
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/TodoApp');
|
mongoose.connect(process.env.MONGODB_URI);
|
||||||
|
|
||||||
module.exports = { mongoose }
|
module.exports = { mongoose }
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
require('./config/config')
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
@ -9,8 +11,6 @@ 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());
|
||||||
|
|
||||||
app.post('/todos', (req, res) => {
|
app.post('/todos', (req, res) => {
|
||||||
@ -72,6 +72,7 @@ app.patch('/todos/:id', (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const port = process.env.PORT;
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Started on port ${port}`);
|
console.log(`Started on port ${port}`);
|
||||||
});
|
});
|
||||||
|
@ -10,7 +10,6 @@ var dummy = [
|
|||||||
{_id: new ObjectID(), text: 'Two', completed: true, completedAt: 333},
|
{_id: new ObjectID(), text: 'Two', completed: true, completedAt: 333},
|
||||||
{_id: new ObjectID(), text: 'Three'} ];
|
{_id: new ObjectID(), text: 'Three'} ];
|
||||||
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
Todo.remove({}).then(() => {
|
Todo.remove({}).then(() => {
|
||||||
return Todo.insertMany(dummy);
|
return Todo.insertMany(dummy);
|
||||||
@ -132,26 +131,29 @@ describe("DELETE /todos/:id", () => {
|
|||||||
|
|
||||||
describe("PATCH /todos/:id", () => {
|
describe("PATCH /todos/:id", () => {
|
||||||
it("should update a single todo", (done) => {
|
it("should update a single todo", (done) => {
|
||||||
var newText = "butts";
|
var text = "butts";
|
||||||
request(app)
|
request(app)
|
||||||
.patch(`/todos/${dummy[0]._id.toHexString()}`)
|
.patch(`/todos/${dummy[0]._id.toHexString()}`)
|
||||||
.send({text: newText , completed: true})
|
.send({completed: true, text})
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
expect(res.body.todo.text).toBe(newText);
|
var {todo} = res.body;
|
||||||
expect(res.body.todo.completedAt).toBeA('number');
|
expect(todo.text).toBe(text);
|
||||||
|
expect(todo.completed).toBe(true);
|
||||||
|
expect(todo.completedAt).toBeA('number');
|
||||||
})
|
})
|
||||||
.end(done)
|
.end(done)
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should clear completed at when todo is not completed", (done) => {
|
it("should clear completedAt when todo is not completed", (done) => {
|
||||||
request(app)
|
request(app)
|
||||||
.patch(`/todos/${dummy[1]._id.toHexString()}`)
|
.patch(`/todos/${dummy[1]._id.toHexString()}`)
|
||||||
.send({completed: false})
|
.send({completed: false})
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect((res) => {
|
.expect((res) => {
|
||||||
expect(res.body.todo.completedAt).toBe(null);
|
var {todo} = res.body;
|
||||||
expect(res.body.todo.completed).toBe(false);
|
expect(todo.completedAt).toNotExist();
|
||||||
|
expect(todo.completed).toBe(false);
|
||||||
})
|
})
|
||||||
.end(done)
|
.end(done)
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user