config stuff
This commit is contained in:
parent
adc036877d
commit
0eb649c3cd
|
@ -5,8 +5,8 @@
|
|||
"main": "server/server.js",
|
||||
"scripts": {
|
||||
"start": "node server/server.js",
|
||||
"test": "mocha server/**/*.test.js",
|
||||
"test-watch": "nodemon --exec 'npm test'"
|
||||
"test": "NODE_ENV=test mocha server/**/*.test.js",
|
||||
"test-watch": "NODE_ENV=test nodemon --exec 'npm test'"
|
||||
},
|
||||
"engines": {
|
||||
"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');
|
||||
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 }
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require('./config/config')
|
||||
|
||||
const express = require('express')
|
||||
const _ = require('lodash')
|
||||
const bodyParser = require('body-parser')
|
||||
|
@ -9,8 +11,6 @@ var {User} = require('./models/user')
|
|||
var {Todo} = require('./models/todo')
|
||||
|
||||
var app = express();
|
||||
const port = process.env.PORT || 8888;
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.post('/todos', (req, res) => {
|
||||
|
@ -72,6 +72,7 @@ app.patch('/todos/:id', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
const port = process.env.PORT;
|
||||
app.listen(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: 'Three'} ];
|
||||
|
||||
|
||||
beforeEach((done) => {
|
||||
Todo.remove({}).then(() => {
|
||||
return Todo.insertMany(dummy);
|
||||
|
@ -132,26 +131,29 @@ describe("DELETE /todos/:id", () => {
|
|||
|
||||
describe("PATCH /todos/:id", () => {
|
||||
it("should update a single todo", (done) => {
|
||||
var newText = "butts";
|
||||
var text = "butts";
|
||||
request(app)
|
||||
.patch(`/todos/${dummy[0]._id.toHexString()}`)
|
||||
.send({text: newText , completed: true})
|
||||
.send({completed: true, text})
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.body.todo.text).toBe(newText);
|
||||
expect(res.body.todo.completedAt).toBeA('number');
|
||||
var {todo} = res.body;
|
||||
expect(todo.text).toBe(text);
|
||||
expect(todo.completed).toBe(true);
|
||||
expect(todo.completedAt).toBeA('number');
|
||||
})
|
||||
.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)
|
||||
.patch(`/todos/${dummy[1]._id.toHexString()}`)
|
||||
.send({completed: false})
|
||||
.expect(200)
|
||||
.expect((res) => {
|
||||
expect(res.body.todo.completedAt).toBe(null);
|
||||
expect(res.body.todo.completed).toBe(false);
|
||||
var {todo} = res.body;
|
||||
expect(todo.completedAt).toNotExist();
|
||||
expect(todo.completed).toBe(false);
|
||||
})
|
||||
.end(done)
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user