Updating test cases.
This commit is contained in:
parent
223d301366
commit
62c407d846
|
@ -168,7 +168,7 @@ class RestIntegration implements IntegrationBase {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
return handleFileResponse(response, filename, this.startTimeMs)
|
return handleFileResponse(response, filename, this.startTimeMs)
|
||||||
} else {
|
} else {
|
||||||
responseTxt = hasContent ? await response.text() : ""
|
responseTxt = hasContent && response.text ? await response.text() : ""
|
||||||
if (response.status === 204) {
|
if (response.status === 204) {
|
||||||
data = []
|
data = []
|
||||||
raw = ""
|
raw = ""
|
||||||
|
|
|
@ -1,19 +1,27 @@
|
||||||
jest.mock("node-fetch", () => {
|
jest.mock("node-fetch", () => {
|
||||||
|
const obj = {
|
||||||
|
my_next_cursor: 123,
|
||||||
|
}
|
||||||
|
const str = JSON.stringify(obj)
|
||||||
return jest.fn(() => ({
|
return jest.fn(() => ({
|
||||||
headers: {
|
headers: {
|
||||||
raw: () => {
|
raw: () => {
|
||||||
return { "content-type": ["application/json"] }
|
return {
|
||||||
|
"content-type": ["application/json"],
|
||||||
|
"content-length": str.length,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
get: (name: string) => {
|
get: (name: string) => {
|
||||||
if (name.toLowerCase() === "content-type") {
|
const lcName = name.toLowerCase()
|
||||||
|
if (lcName === "content-type") {
|
||||||
return ["application/json"]
|
return ["application/json"]
|
||||||
|
} else if (lcName === "content-length") {
|
||||||
|
return str.length
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
json: jest.fn(() => ({
|
json: jest.fn(() => obj),
|
||||||
my_next_cursor: 123,
|
text: jest.fn(() => str),
|
||||||
})),
|
|
||||||
text: jest.fn(),
|
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -231,7 +239,8 @@ describe("REST Integration", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should be able to parse JSON response", async () => {
|
it("should be able to parse JSON response", async () => {
|
||||||
const input = buildInput({ a: 1 }, null, "application/json")
|
const obj = { a: 1 }
|
||||||
|
const input = buildInput(obj, JSON.stringify(obj), "application/json")
|
||||||
const output = await config.integration.parseResponse(input)
|
const output = await config.integration.parseResponse(input)
|
||||||
expect(output.data).toEqual({ a: 1 })
|
expect(output.data).toEqual({ a: 1 })
|
||||||
expect(output.info.code).toEqual(200)
|
expect(output.info.code).toEqual(200)
|
||||||
|
@ -261,7 +270,7 @@ describe("REST Integration", () => {
|
||||||
test.each([...contentTypes, undefined])(
|
test.each([...contentTypes, undefined])(
|
||||||
"should not throw an error on 204 no content",
|
"should not throw an error on 204 no content",
|
||||||
async contentType => {
|
async contentType => {
|
||||||
const input = buildInput(undefined, null, contentType, 204)
|
const input = buildInput(undefined, "", contentType, 204)
|
||||||
const output = await config.integration.parseResponse(input)
|
const output = await config.integration.parseResponse(input)
|
||||||
expect(output.data).toEqual([])
|
expect(output.data).toEqual([])
|
||||||
expect(output.extra.raw).toEqual("")
|
expect(output.extra.raw).toEqual("")
|
||||||
|
|
Loading…
Reference in New Issue