models/note.js
import mongoose from 'mongoose'
const Schema = mongoose.Schema;
const NoteSchema = new Schema({
title: {type: String, required: true},
description: {type: String, required: true},
color:{type: String},
createAt:{type: Date, required: true},
author: {type: String, required:true}
}, {collection:'notes'});
mongoose.model('note', NoteSchema);
../Notedb.js
export const createNote = (data) =>{
const note = new Note({
title: data.title,
description: data.description,
color: data.color,
createAt: new Date(),
author: data.author
});
return note.save();
}
../noteApi
const router = express.Router();
router.post('/add', (req, res, next)=>{
return noteDb.createNote(req.body)
.then((done)=>{
res.json(done);
})
.catch((err)=>{
res.status(500).send();
});
});
..Test/note.js
describe('/POST note add' , ()=>{
it('it should POST test', (done)=>{
let _note = {
title: "Test note POST!",
description: "This is test for note api",
color: "yellow",
author: "admin"
}
chai.request(server)
.post('/add')
.send(_note)
.end((err, res)=>{
res.should.have.status(200);
res.body.should.be.a('object');
//res.body.book.should.have.property('title');
done();
});
});
})
При тестировании вылетает такая вот ошибка:
Timeout of 10000ms exceeded. For async tests and hook...