1
0
Fork 0
mirror of synced 2024-07-16 11:45:47 +12:00

Some fixes for the rest test cases which mocked too widely.

This commit is contained in:
mike12345567 2024-05-15 14:40:08 +01:00
parent fcb535efee
commit a8e12dfb6b
2 changed files with 28 additions and 13 deletions

View file

@ -4,7 +4,11 @@ jest.mock("node-fetch", () => {
raw: () => {
return { "content-type": ["application/json"] }
},
get: () => ["application/json"],
get: (name: string) => {
if (name.toLowerCase() === "content-type") {
return ["application/json"]
}
},
},
json: jest.fn(() => ({
my_next_cursor: 123,
@ -211,7 +215,16 @@ describe("REST Integration", () => {
json: json ? async () => json : undefined,
text: text ? async () => text : undefined,
headers: {
get: (key: any) => (key === "content-length" ? 100 : header),
get: (key: string) => {
switch (key.toLowerCase()) {
case "content-length":
return 100
case "content-type":
return header
default:
return ""
}
},
raw: () => ({ "content-type": header }),
},
}

View file

@ -7,18 +7,20 @@ export function getAttachmentHeaders(headers: Headers) {
// the API does not follow the requirements of https://www.ietf.org/rfc/rfc2183.txt
// all content-disposition headers should be format disposition-type; parameters
// but some APIs do not provide a type, causing the parse below to fail - add one to fix this
const quotesRegex = /"(?:[^"\\]|\\.)*"|;/g
let match: RegExpMatchArray | null = null,
found = false
while ((match = quotesRegex.exec(contentDisposition)) !== null) {
if (match[0] === ";") {
found = true
if (contentDisposition) {
const quotesRegex = /"(?:[^"\\]|\\.)*"|;/g
let match: RegExpMatchArray | null = null,
found = false
while ((match = quotesRegex.exec(contentDisposition)) !== null) {
if (match[0] === ";") {
found = true
}
}
}
if (!found) {
return {
contentDisposition: `attachment; ${contentDisposition}`,
contentType,
if (!found) {
return {
contentDisposition: `attachment; ${contentDisposition}`,
contentType,
}
}
}