Some fixes for the rest test cases which mocked too widely.
This commit is contained in:
parent
fcb535efee
commit
a8e12dfb6b
|
@ -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 }),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue