Stop relying on config.request and create a supertest instance per request.
This commit is contained in:
parent
b84bbd6003
commit
1eae212f83
|
@ -2,6 +2,8 @@ import { GenericContainer, Wait } from "testcontainers"
|
|||
|
||||
export default async function setup() {
|
||||
await new GenericContainer("budibase/couchdb")
|
||||
.withName("budibase-test-couchdb")
|
||||
.withReuse()
|
||||
.withExposedPorts(5984)
|
||||
.withEnvironment({
|
||||
COUCHDB_PASSWORD: "budibase",
|
||||
|
|
|
@ -227,7 +227,7 @@ describe.each([
|
|||
|
||||
view = await config.api.viewV2.create({
|
||||
tableId: table._id!,
|
||||
name: "View A",
|
||||
name: generator.guid(),
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -303,12 +303,13 @@ describe.each([
|
|||
|
||||
it("can update an existing view name", async () => {
|
||||
const tableId = table._id!
|
||||
await config.api.viewV2.update({ ...view, name: "View B" })
|
||||
const newName = generator.guid()
|
||||
await config.api.viewV2.update({ ...view, name: newName })
|
||||
|
||||
expect(await config.api.table.get(tableId)).toEqual(
|
||||
expect.objectContaining({
|
||||
views: {
|
||||
"View B": { ...view, name: "View B", schema: expect.anything() },
|
||||
[newName]: { ...view, name: newName, schema: expect.anything() },
|
||||
},
|
||||
})
|
||||
)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import TestConfiguration from "../TestConfiguration"
|
||||
import { SuperTest, Test, Response } from "supertest"
|
||||
import request, { SuperTest, Test, Response } from "supertest"
|
||||
import { ReadStream } from "fs"
|
||||
import { getServer } from "../../../app"
|
||||
|
||||
type Headers = Record<string, string | string[] | undefined>
|
||||
type Method = "get" | "post" | "put" | "patch" | "delete"
|
||||
|
@ -107,26 +108,29 @@ export abstract class TestAPI {
|
|||
const headersFn = publicUser
|
||||
? this.config.publicHeaders.bind(this.config)
|
||||
: this.config.defaultHeaders.bind(this.config)
|
||||
let request = this.request[method](url).set(
|
||||
|
||||
const app = getServer()
|
||||
let req = request(app)[method](url)
|
||||
req = req.set(
|
||||
headersFn({
|
||||
"x-budibase-include-stacktrace": "true",
|
||||
})
|
||||
)
|
||||
if (headers) {
|
||||
request = request.set(headers)
|
||||
req = req.set(headers)
|
||||
}
|
||||
if (body) {
|
||||
request = request.send(body)
|
||||
req = req.send(body)
|
||||
}
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
request = request.field(key, value)
|
||||
req = req.field(key, value)
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(files)) {
|
||||
if (isAttachedFile(value)) {
|
||||
request = request.attach(key, value.file, value.name)
|
||||
req = req.attach(key, value.file, value.name)
|
||||
} else {
|
||||
request = request.attach(key, value as any)
|
||||
req = req.attach(key, value as any)
|
||||
}
|
||||
}
|
||||
if (expectations?.headers) {
|
||||
|
@ -136,11 +140,11 @@ export abstract class TestAPI {
|
|||
`Got an undefined expected value for header "${key}", if you want to check for the absence of a header, use headersNotPresent`
|
||||
)
|
||||
}
|
||||
request = request.expect(key, value as any)
|
||||
req = req.expect(key, value as any)
|
||||
}
|
||||
}
|
||||
|
||||
return await request
|
||||
return await req
|
||||
}
|
||||
|
||||
protected _checkResponse = (
|
||||
|
|
Loading…
Reference in New Issue