-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
William
committed
Jun 19, 2021
1 parent
801120f
commit 463712c
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const binary = require('./binary'); | ||
const fs = require('fs'); | ||
|
||
module.exports = (res, filePath, contentType) => binary(res, fs.readFileSync(filePath), contentType); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const response = require('./../src/lib/response'); | ||
const fs = require('fs'); | ||
|
||
const svg = `<?xml version="1.0"><svg width="1" height="1" version="1.1" xmlns="http://www.w3.org/2000/svg"><rect x="0" y="0" width="1" height="1" fill="black" /></svg>`; | ||
|
||
beforeEach(() => { | ||
fs.writeFileSync('temp.svg', Buffer.from(svg)); | ||
}); | ||
|
||
afterEach(() => { | ||
fs.unlinkSync('temp.svg'); | ||
}); | ||
|
||
test('file response', () => { | ||
const res = response(); | ||
|
||
res.file('temp.svg', 'image/svg+xml'); | ||
|
||
expect(res.getResponse()).toEqual({ | ||
body: Buffer.from(svg).toString('base64'), | ||
headers: { 'Content-Type': 'image/svg+xml' }, | ||
isBase64Encoded: true, | ||
statusCode: 200, | ||
}); | ||
}); |