UPDATE: I finally figured this out. I removed the .query() and added the param to the .get()
.get('/api/books/'+idToQuery)
test('Test GET /api/books/[id] with valid id in db', function(done){
chai.request(server)
// create test entry in database
.post('/api/books')
.send({
title: 'Test Book - valid id'
})
.end(function(err,res){
let idToQuery = res.body._id; // this successfully sends back the '_id' of the new data created in the .post()
chai.request(server)
.get('/api/books')
.query({_id: idToQuery }) // query with new '_id'
.end(function(err, res){
console.log(res.body) // this prints out entire database NOT just the one I am querying for
assert.equal(res.status, 200);
assert.isObject(res.body, 'response should be an object');
assert.property(res.body, 'title', 'Test Book - valid id');
done();
});
});
});
The line: .query({_id: idToQuery }) does not seem to be working as the console.log(res.body) prints out all the database entries. So obviously the asserts fail as it doesn’t know which one to test.
Am I doing this correctly? or is there some other way to create a test entry to use for the asserts()?