1
0
Fork 0
mirror of synced 2024-07-03 05:20:32 +12:00

Merge branch 'master' into security/yarn-audit

This commit is contained in:
Adria Navarro 2023-12-20 12:03:09 +01:00 committed by GitHub
commit 06c5733298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View file

@ -131,7 +131,10 @@ class RestIntegration implements IntegrationBase {
let data, raw, headers
const contentType = response.headers.get("content-type") || ""
try {
if (contentType.includes("application/json")) {
if (response.status === 204) {
data = []
raw = []
} else if (contentType.includes("application/json")) {
data = await response.json()
raw = JSON.stringify(data)
} else if (

View file

@ -186,9 +186,15 @@ describe("REST Integration", () => {
})
describe("response", () => {
function buildInput(json: any, text: any, header: any) {
const contentTypes = ["application/json", "text/plain", "application/xml"]
function buildInput(
json: any,
text: any,
header: any,
status: number = 200
) {
return {
status: 200,
status,
json: json ? async () => json : undefined,
text: text ? async () => text : undefined,
headers: {
@ -225,6 +231,18 @@ describe("REST Integration", () => {
expect(output.extra.raw).toEqual(text)
expect(output.extra.headers["content-type"]).toEqual("application/xml")
})
test.each(contentTypes)(
"should not throw an error on 204 no content",
async contentType => {
const input = buildInput(undefined, null, contentType, 204)
const output = await config.integration.parseResponse(input)
expect(output.data).toEqual([])
expect(output.extra.raw).toEqual([])
expect(output.info.code).toEqual(204)
expect(output.extra.headers["content-type"]).toEqual(contentType)
}
)
})
describe("authentication", () => {