forwardemail / forwardemail/supertest

file download : checking both file content and status

Open
#714 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

I found a smart way to test a file download, with pipe and its on 'finish' event .
This way the file download is completed successfully (and well completed) , ... it could be a someone help !
Solution is to use the "callback way" with "done" and I do not return any promise .
```
it.only('GET DOCUMENT RESULT : /contracts/{id}/documentresult/', function (done) {
if (mock) {
mock.getPdf();
}
const request = reqserv
.get('/api/v4/contracts/' + MockContract.CONTRACT_ID + '/documentresult/')
.set({ j_token: j_token })
.set('Accept', 'application/pdf');
const filePath = './test/downloaded/lepdf.pdf';
const file: NodeJS.WritableStream = fs.createWriteStream(filePath);
const stream = request.pipe(file);
stream.on('finish', () => {
console.log('done');
done();
});
});
```

BUT this way , I cannot manage to retrieve the response status ,e.g in order to check equal 200.
finish event dont provide any passed variable.
Is there any other event I could use to check the response status ?

I also tried with
``... .set('Accept', 'application/pdf').expect(200);

but it is not working , nor I can use any expect callback handler , which causes error ( twice end ... )

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.