1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00

Fixing test cases.

This commit is contained in:
mike12345567 2022-09-09 17:18:19 +01:00
parent c61a4df998
commit 92a1d709b8
3 changed files with 27 additions and 7 deletions

View file

@ -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")
})

View file

@ -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}`

View file

@ -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,
})
})
})
})