My chai test creates the database entry but doesn’t add the ‘board’ value.
Is there some way to deal with a field that’s reference?
My mongoose object looks like:
const ThreadSchema = new Schema({
"text": {
'type': String
},
"delete_password": {
'type': String,
'select': false
},
"created_on": {
'type': Date,
'default': new Date()
},
"bumped_on": {
'type': Date,
'default': new Date()
},
"reported": {
'type': Boolean,
'select': false,
'default': false
},
"replycount":{
'type': Number,
'default': 0
},
"board" : {
'type': mongoose.Schema.Types.ObjectId,
'ref': 'Board'
},
replies: [{
'type': mongoose.Schema.Types.ObjectId,
'ref': 'Reply'
}]
});
and my test looks like
test('All fields complete', function(done) {
chai.request(server)
.post('/api/threads/test')
.send({
text: 'test thread text',
delete_password: 'password',
board: ObjectId('5d8f748a1d788a3be2b9a7b7')
})
.end(function(err, res){
expect(err).to.be.null;
assert.equal(res.status, 200);
expect(res.body).to.eventually.be.a('object');
//assert.property(res.body.thread, 'text');
done();
});
});