Test case.
This commit is contained in:
parent
16c69dcc33
commit
e320524c63
|
@ -1,13 +1,13 @@
|
||||||
import { getAttachmentHeaders } from "../utils/restUtils"
|
import { getAttachmentHeaders } from "../utils/restUtils"
|
||||||
import type { Headers } from "node-fetch"
|
import type { Headers } from "node-fetch"
|
||||||
|
|
||||||
function headers(dispositionValue: string) {
|
function headers(dispositionValue: string, contentType?: string) {
|
||||||
return {
|
return {
|
||||||
get: (name: string) => {
|
get: (name: string) => {
|
||||||
if (name.toLowerCase() === "content-disposition") {
|
if (name.toLowerCase() === "content-disposition") {
|
||||||
return dispositionValue
|
return dispositionValue
|
||||||
} else {
|
} else {
|
||||||
return "application/pdf"
|
return contentType || "application/pdf"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
set: () => {},
|
set: () => {},
|
||||||
|
@ -35,4 +35,14 @@ describe("getAttachmentHeaders", () => {
|
||||||
)
|
)
|
||||||
expect(contentDisposition).toBe(`inline; filename="report.pdf"`)
|
expect(contentDisposition).toBe(`inline; filename="report.pdf"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle an image", () => {
|
||||||
|
const { contentDisposition } = getAttachmentHeaders(
|
||||||
|
headers("", "image/png"),
|
||||||
|
{
|
||||||
|
downloadImages: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
expect(contentDisposition).toBe(`attachment; filename="image.png"`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue