I am wanting to validate that a call to one of my REST API's end-point is serving up a file, but I am not sure how to go about it and I am not seeing any examples on this? I did look at the documentation, but this didn't help me much.
The server side code essentially does (in Express):
handleRetrieveContent(req, res, next) {
const filepaht = '...';
res.sendFile(filepath)
}
and the test case:
it('Should get a file', (done) => {
chai.request(url)
.get('/api/exercise/1?token=' + token)
.end(function(err, res) {
if (err) { done(err); }
res.should.have.status(200);
// Not sure what the test here should be?
res.should.be.json;
// TODO get access to saved file and do tests on it
});
});
I am essentially wanting to do the following tests:
- ensure the response is a file
- ensure the file is of valid content (checksum test)
Any help would be appreciated.