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: () => {
|
raw: () => {
|
||||||
return { "content-type": ["application/json"] }
|
return { "content-type": ["application/json"] }
|
||||||
},
|
},
|
||||||
get: () => ["application/json"],
|
get: (name: string) => {
|
||||||
|
if (name.toLowerCase() === "content-type") {
|
||||||
|
return ["application/json"]
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
json: jest.fn(() => ({
|
json: jest.fn(() => ({
|
||||||
my_next_cursor: 123,
|
my_next_cursor: 123,
|
||||||
|
@ -211,7 +215,16 @@ describe("REST Integration", () => {
|
||||||
json: json ? async () => json : undefined,
|
json: json ? async () => json : undefined,
|
||||||
text: text ? async () => text : undefined,
|
text: text ? async () => text : undefined,
|
||||||
headers: {
|
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 }),
|
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
|
// 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
|
// 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
|
// but some APIs do not provide a type, causing the parse below to fail - add one to fix this
|
||||||
const quotesRegex = /"(?:[^"\\]|\\.)*"|;/g
|
if (contentDisposition) {
|
||||||
let match: RegExpMatchArray | null = null,
|
const quotesRegex = /"(?:[^"\\]|\\.)*"|;/g
|
||||||
found = false
|
let match: RegExpMatchArray | null = null,
|
||||||
while ((match = quotesRegex.exec(contentDisposition)) !== null) {
|
found = false
|
||||||
if (match[0] === ";") {
|
while ((match = quotesRegex.exec(contentDisposition)) !== null) {
|
||||||
found = true
|
if (match[0] === ";") {
|
||||||
|
found = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!found) {
|
||||||
if (!found) {
|
return {
|
||||||
return {
|
contentDisposition: `attachment; ${contentDisposition}`,
|
||||||
contentDisposition: `attachment; ${contentDisposition}`,
|
contentType,
|
||||||
contentType,
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue