1
0
Fork 0
mirror of synced 2024-07-05 22:40:39 +12:00

Stop relying on config.request and create a supertest instance per request.

This commit is contained in:
Sam Rose 2024-03-26 15:41:51 +00:00
parent b84bbd6003
commit 1eae212f83
No known key found for this signature in database
3 changed files with 19 additions and 12 deletions

View file

@ -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",

View file

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

View file

@ -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 = (