QA Projects - Personal Library - can't send req.param with chai-http

Tell us what’s happening:
So I’m working at the Personal Library project and I’m having an issue with one of the test. The test passes if I hard-code the book ID in the .get() method, but it doesn’t if I send the ID within the .send()method (commented lines in the sample code below). Loggin the response of the test return an empty object.
Also this part of the API works as expected if I visit it in the browser (I get a book object with _id, title, etc.).
Project so far on Replit (test at lines 111-128).

Any suggestion?

Your code so far

test('Test GET /api/books/[id] with valid id in db',  function(done){
          .get('/api/books/647de934b733d0ae5fca0e4f') // works...
          // .get('/api/books/:id')                   
          // .send({                           // this should be the same
          //   id: "647de934b733d0ae5fca0e4f"  // but doesn't work
          // })
          .end((err, res) => {
            assert.equal(res.status, 200);
            assert.equal(res.type, 'application/json');
            assert.isObject(res.body, 'res.body should be an object');
  , '_id', 'res.body should have an _id property');
  , 'title');
  , 'comments');

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/113.0

Challenge: Quality Assurance Projects - Personal Library

Link to the challenge:, ‘_id’, ‘res.body should have an _id property’);

You use _id here.

But you use id there. Maybe a typo?

 //   id: "647de934b733d0ae5fca0e4f"  // but doesn't work
1 Like

Because that’s what is returned from mongoose, that’s not a typo…but thanks anyway

I would assume it is because it’s a GET request and send is for updates (like a POST).

For params I think the way you would normally do it is just adding it to the GET path, it can still be a variable if needed. For query strings, there is the query method.

As an aside, I believe the Mongoose id is a virtual getter.

1 Like

Yes, I ended doing this forming the paths with template literals. I didn’t find much about the .send() method in the chai or chai-http docs.

Thank you.