move tests into separate describe

This commit is contained in:
Peter Clement 2024-03-15 14:13:38 +00:00
parent 43308ad2f3
commit 61f0f5be18
1 changed files with 79 additions and 76 deletions

View File

@ -50,13 +50,6 @@ describe("REST Integration", () => {
const BASE_URL = "https://myapi.com" const BASE_URL = "https://myapi.com"
let config: any let config: any
beforeAll(async () => {
await databaseTestProviders.s3.start()
})
afterAll(async () => {
await databaseTestProviders.s3.stop()
})
beforeEach(() => { beforeEach(() => {
config = new TestConfiguration({ config = new TestConfiguration({
url: BASE_URL, url: BASE_URL,
@ -632,83 +625,93 @@ describe("REST Integration", () => {
expect(calledConfig.agent.options.rejectUnauthorized).toBe(false) expect(calledConfig.agent.options.rejectUnauthorized).toBe(false)
}) })
it("uploads file to object store and returns signed URL", async () => { describe("File Handling", () => {
const responseData = Buffer.from("teest file contnt") beforeAll(async () => {
const filename = "test.tar.gz" await databaseTestProviders.s3.start()
const contentType = "application/gzip"
;(fetch as unknown as jest.Mock).mockImplementationOnce(() =>
Promise.resolve({
headers: {
raw: () => ({
"content-type": [contentType],
"content-disposition": [`attachment; filename="${filename}"`],
}),
get: (header: any) => {
if (header === "content-type") return contentType
if (header === "content-disposition")
return `attachment; filename="${filename}"`
},
},
arrayBuffer: jest.fn(() => Promise.resolve(responseData)),
})
)
const query = {
path: "api",
}
const response = await config.integration.read(query)
expect(response.data).toEqual({
size: responseData.byteLength,
name: "00000000-0000-0000-0000-000000000000.tar.gz",
url: "/files/signed/tmp-file-attachments/app-id/00000000-0000-0000-0000-000000000000.tar.gz",
extension: "tar.gz",
key: expect.stringContaining(
"app-id/00000000-0000-0000-0000-000000000000.tar.gz"
),
}) })
})
it("uploads file with non ascii filename to object store and returns signed URL ", async () => { afterAll(async () => {
const responseData = Buffer.from("teest file contnt") await databaseTestProviders.s3.stop()
const non_ascii_filename = "ex%C3%A4mple.txt" })
const contentType = "text/plain"
;(fetch as unknown as jest.Mock).mockImplementationOnce(() => it("uploads file to object store and returns signed URL", async () => {
Promise.resolve({ const responseData = Buffer.from("teest file contnt")
headers: { const filename = "test.tar.gz"
raw: () => ({ const contentType = "application/gzip"
"content-type": [contentType],
"content-disposition": [ ;(fetch as unknown as jest.Mock).mockImplementationOnce(() =>
`attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf`, Promise.resolve({
], headers: {
}), raw: () => ({
get: (header: any) => { "content-type": [contentType],
if (header === "content-type") return contentType "content-disposition": [`attachment; filename="${filename}"`],
if (header === "content-disposition") }),
return `attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf` get: (header: any) => {
if (header === "content-type") return contentType
if (header === "content-disposition")
return `attachment; filename="${filename}"`
},
}, },
}, arrayBuffer: jest.fn(() => Promise.resolve(responseData)),
arrayBuffer: jest.fn(() => Promise.resolve(responseData)), })
)
const query = {
path: "api",
}
const response = await config.integration.read(query)
expect(response.data).toEqual({
size: responseData.byteLength,
name: "00000000-0000-0000-0000-000000000000.tar.gz",
url: "/files/signed/tmp-file-attachments/app-id/00000000-0000-0000-0000-000000000000.tar.gz",
extension: "tar.gz",
key: expect.stringContaining(
"app-id/00000000-0000-0000-0000-000000000000.tar.gz"
),
}) })
) })
const query = { it("uploads file with non ascii filename to object store and returns signed URL ", async () => {
path: "api", const responseData = Buffer.from("teest file contnt")
} const non_ascii_filename = "ex%C3%A4mple.txt"
const contentType = "text/plain"
const response = await config.integration.read(query) ;(fetch as unknown as jest.Mock).mockImplementationOnce(() =>
Promise.resolve({
headers: {
raw: () => ({
"content-type": [contentType],
"content-disposition": [
`attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf`,
],
}),
get: (header: any) => {
if (header === "content-type") return contentType
if (header === "content-disposition")
return `attachment; filename="£ and ? rates.pdf"; filename*=UTF-8\'\'%C2%A3%20and%20%E2%82%AC%20rates.pdf`
},
},
arrayBuffer: jest.fn(() => Promise.resolve(responseData)),
})
)
expect(response.data).toEqual({ const query = {
size: responseData.byteLength, path: "api",
name: "00000000-0000-0000-0000-000000000000.pdf", }
url: "/files/signed/tmp-file-attachments/app-id/00000000-0000-0000-0000-000000000000.pdf",
extension: "pdf", const response = await config.integration.read(query)
key: expect.stringContaining(
"app-id/00000000-0000-0000-0000-000000000000.pdf" expect(response.data).toEqual({
), size: responseData.byteLength,
name: "00000000-0000-0000-0000-000000000000.pdf",
url: "/files/signed/tmp-file-attachments/app-id/00000000-0000-0000-0000-000000000000.pdf",
extension: "pdf",
key: expect.stringContaining(
"app-id/00000000-0000-0000-0000-000000000000.pdf"
),
})
}) })
}) })
}) })