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", "url": "string",
"value": "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 () => { it("check that it automatically retries on fail with cached dynamics", async () => {
@ -396,7 +396,7 @@ describe("/queries", () => {
"queryHdr": userDetails.firstName, "queryHdr": userDetails.firstName,
"secondHdr" : "1234" "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 () => { it("should bind the current user to query parameters", async () => {
@ -413,7 +413,7 @@ describe("/queries", () => {
"testParam" : "1234" "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") "&testName=" + userDetails.firstName + "&testParam=1234")
}) })

View File

@ -14,6 +14,7 @@ import {
BearerAuthConfig, BearerAuthConfig,
} from "../definitions/datasource" } from "../definitions/datasource"
import { get } from "lodash" import { get } from "lodash"
import qs from "querystring"
const BodyTypes = { const BodyTypes = {
NONE: "none", 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 let complete = main
if (this.config.url && !main.startsWith("http")) { if (this.config.url && !main.startsWith("http")) {
complete = !this.config.url ? main : `${this.config.url}/${main}` complete = !this.config.url ? main : `${this.config.url}/${main}`

View File

@ -50,7 +50,7 @@ describe("REST Integration", () => {
name: "test", name: "test",
}), }),
} }
const response = await config.integration.create(query) await config.integration.create(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, { expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
method: "POST", method: "POST",
body: '{"name":"test"}', body: '{"name":"test"}',
@ -295,7 +295,7 @@ describe("REST Integration", () => {
} }
await config.integration.read(query) await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith( expect(fetch).toHaveBeenCalledWith(
`${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}&`, `${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}`,
{ {
headers: {}, headers: {},
method: "GET", method: "GET",
@ -420,7 +420,7 @@ describe("REST Integration", () => {
} }
const res = await config.integration.read(query) const res = await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith( expect(fetch).toHaveBeenCalledWith(
`${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}&`, `${BASE_URL}/api?${pageParam}=${pageValue}&${sizeParam}=${sizeValue}`,
{ {
headers: {}, headers: {},
method: "GET", method: "GET",
@ -528,5 +528,23 @@ describe("REST Integration", () => {
expect(sentData.get(sizeParam)).toEqual(sizeValue.toString()) expect(sentData.get(sizeParam)).toEqual(sizeValue.toString())
expect(res.pagination.cursor).toEqual(123) 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,
})
})
}) })
}) })