Fixing test cases.
This commit is contained in:
parent
c61a4df998
commit
92a1d709b8
|
@ -311,7 +311,7 @@ describe("/queries", () => {
|
|||
"url": "string",
|
||||
"value": "string"
|
||||
})
|
||||
expect(res.body.rows[0].url).toContain("doctype html")
|
||||
expect(res.body.rows[0].url).toContain("doctype%20html")
|
||||
})
|
||||
|
||||
it("check that it automatically retries on fail with cached dynamics", async () => {
|
||||
|
@ -396,7 +396,7 @@ describe("/queries", () => {
|
|||
"queryHdr": userDetails.firstName,
|
||||
"secondHdr" : "1234"
|
||||
})
|
||||
expect(res.body.rows[0].url).toEqual("http://www.google.com?email=" + userDetails.email)
|
||||
expect(res.body.rows[0].url).toEqual("http://www.google.com?email=" + userDetails.email.replace("@", "%40"))
|
||||
})
|
||||
|
||||
it("should bind the current user to query parameters", async () => {
|
||||
|
@ -413,7 +413,7 @@ describe("/queries", () => {
|
|||
"testParam" : "1234"
|
||||
})
|
||||
|
||||
expect(res.body.rows[0].url).toEqual("http://www.google.com?test=" + userDetails.email +
|
||||
expect(res.body.rows[0].url).toEqual("http://www.google.com?test=" + userDetails.email.replace("@", "%40") +
|
||||
"&testName=" + userDetails.firstName + "&testParam=1234")
|
||||
})
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import {
|
|||
BearerAuthConfig,
|
||||
} from "../definitions/datasource"
|
||||
import { get } from "lodash"
|
||||
import qs from "querystring"
|
||||
|
||||
const BodyTypes = {
|
||||
NONE: "none",
|
||||
|
@ -215,7 +216,8 @@ module RestModule {
|
|||
}
|
||||
}
|
||||
|
||||
const main = `${path}?${encodeURIComponent(queryString)}`
|
||||
// make sure the query string is fully encoded
|
||||
const main = `${path}?${qs.encode(qs.decode(queryString))}`
|
||||
let complete = main
|
||||
if (this.config.url && !main.startsWith("http")) {
|
||||
complete = !this.config.url ? main : `${this.config.url}/${main}`
|
||||
|
|
|
@ -50,7 +50,7 @@ describe("REST Integration", () => {
|
|||
name: "test",
|
||||
}),
|
||||
}
|
||||
const response = await config.integration.create(query)
|
||||
await config.integration.create(query)
|
||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
||||
method: "POST",
|
||||
body: '{"name":"test"}',
|
||||
|
@ -295,7 +295,7 @@ describe("REST Integration", () => {
|
|||
}
|
||||
await config.integration.read(query)
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
`${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}&`,
|
||||
`${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}`,
|
||||
{
|
||||
headers: {},
|
||||
method: "GET",
|
||||
|
@ -420,7 +420,7 @@ describe("REST Integration", () => {
|
|||
}
|
||||
const res = await config.integration.read(query)
|
||||
expect(fetch).toHaveBeenCalledWith(
|
||||
`${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}&`,
|
||||
`${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}`,
|
||||
{
|
||||
headers: {},
|
||||
method: "GET",
|
||||
|
@ -528,5 +528,23 @@ describe("REST Integration", () => {
|
|||
expect(sentData.get(sizeParam)).toEqual(sizeValue.toString())
|
||||
expect(res.pagination.cursor).toEqual(123)
|
||||
})
|
||||
|
||||
it("should encode query string correctly", async () => {
|
||||
const query = {
|
||||
path: "api",
|
||||
queryString: "test=1 2",
|
||||
headers: HEADERS,
|
||||
bodyType: "json",
|
||||
requestBody: JSON.stringify({
|
||||
name: "test",
|
||||
}),
|
||||
}
|
||||
await config.integration.create(query)
|
||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1%202`, {
|
||||
method: "POST",
|
||||
body: '{"name":"test"}',
|
||||
headers: HEADERS,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue