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() {
|
export default async function setup() {
|
||||||
await new GenericContainer("budibase/couchdb")
|
await new GenericContainer("budibase/couchdb")
|
||||||
|
.withName("budibase-test-couchdb")
|
||||||
|
.withReuse()
|
||||||
.withExposedPorts(5984)
|
.withExposedPorts(5984)
|
||||||
.withEnvironment({
|
.withEnvironment({
|
||||||
COUCHDB_PASSWORD: "budibase",
|
COUCHDB_PASSWORD: "budibase",
|
||||||
|
|
|
@ -227,7 +227,7 @@ describe.each([
|
||||||
|
|
||||||
view = await config.api.viewV2.create({
|
view = await config.api.viewV2.create({
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
name: "View A",
|
name: generator.guid(),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -303,12 +303,13 @@ describe.each([
|
||||||
|
|
||||||
it("can update an existing view name", async () => {
|
it("can update an existing view name", async () => {
|
||||||
const tableId = table._id!
|
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(await config.api.table.get(tableId)).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
views: {
|
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 TestConfiguration from "../TestConfiguration"
|
||||||
import { SuperTest, Test, Response } from "supertest"
|
import request, { SuperTest, Test, Response } from "supertest"
|
||||||
import { ReadStream } from "fs"
|
import { ReadStream } from "fs"
|
||||||
|
import { getServer } from "../../../app"
|
||||||
|
|
||||||
type Headers = Record<string, string | string[] | undefined>
|
type Headers = Record<string, string | string[] | undefined>
|
||||||
type Method = "get" | "post" | "put" | "patch" | "delete"
|
type Method = "get" | "post" | "put" | "patch" | "delete"
|
||||||
|
@ -107,26 +108,29 @@ export abstract class TestAPI {
|
||||||
const headersFn = publicUser
|
const headersFn = publicUser
|
||||||
? this.config.publicHeaders.bind(this.config)
|
? this.config.publicHeaders.bind(this.config)
|
||||||
: this.config.defaultHeaders.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({
|
headersFn({
|
||||||
"x-budibase-include-stacktrace": "true",
|
"x-budibase-include-stacktrace": "true",
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
if (headers) {
|
if (headers) {
|
||||||
request = request.set(headers)
|
req = req.set(headers)
|
||||||
}
|
}
|
||||||
if (body) {
|
if (body) {
|
||||||
request = request.send(body)
|
req = req.send(body)
|
||||||
}
|
}
|
||||||
for (const [key, value] of Object.entries(fields)) {
|
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)) {
|
for (const [key, value] of Object.entries(files)) {
|
||||||
if (isAttachedFile(value)) {
|
if (isAttachedFile(value)) {
|
||||||
request = request.attach(key, value.file, value.name)
|
req = req.attach(key, value.file, value.name)
|
||||||
} else {
|
} else {
|
||||||
request = request.attach(key, value as any)
|
req = req.attach(key, value as any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (expectations?.headers) {
|
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`
|
`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 = (
|
protected _checkResponse = (
|
||||||
|
|
Loading…
Reference in New Issue