I am trying to write a test that checks whether an API route outputs a ZIP file with the correct contents.
I am using mocha and supertest for testing, and I would like to actually read the output stream/buffer, read the zip file contents and see if the contents are correct.
Any ideas how should I do it? When I try to read res.body
, it's just an empty object.
request(app)
.get( "/api/v1/orders/download?id[]=1&id=2" )
.set( "Authorization", authData )
.expect( 200 )
.expect( 'Content-Type', /application\/zip/ )
.end( function (err, res) {
if (err) return done( err );
console.log( 'body:', res.body )
// Write the temp HTML file to filesystem using utf-8 encoding
var zip = new AdmZip( res.body );
var zipEntries = zip.getEntries();
console.log( 'zipentries:', zipEntries );
zipEntries.forEach(function(zipEntry) {
console.log(zipEntry.toString()); // outputs zip entries information
});
done();
});
.buffer()
to the request. – Snowman