Answer the question
In order to leave comments, you need to log in
How to fix error when checking POST through chai?
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);
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();
}
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();
});
});
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();
});
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question