Respond to PR feedback.

This commit is contained in:
Sam Rose 2024-02-05 14:26:19 +00:00
parent 871e1f3806
commit 1573242031
No known key found for this signature in database
4 changed files with 27 additions and 55 deletions

View File

@ -6,7 +6,6 @@ import { MongoClient } from "mongodb"
jest.unmock("mongodb")
describe("/queries", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let datasource: Datasource
@ -21,18 +20,7 @@ describe("/queries", () => {
transformer: "return data",
readable: true,
}
const res = await request
.post(`/api/queries`)
.set(config.defaultHeaders())
.send({ ...defaultQuery, ...query })
.expect("Content-Type", /json/)
if (res.status !== 200) {
throw new Error(JSON.stringify(res.body))
}
return res.body as Query
return await config.api.query.create({ ...defaultQuery, ...query })
}
afterAll(async () => {

View File

@ -25,7 +25,6 @@ DROP TABLE test_table;
`
describe("/queries", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let datasource: Datasource
@ -40,18 +39,7 @@ describe("/queries", () => {
transformer: "return data",
readable: true,
}
const res = await request
.post(`/api/queries`)
.set(config.defaultHeaders())
.send({ ...defaultQuery, ...query })
.expect("Content-Type", /json/)
if (res.status !== 200) {
throw new Error(JSON.stringify(res.body))
}
return res.body as Query
return await config.api.query.create({ ...defaultQuery, ...query })
}
afterAll(async () => {

View File

@ -4,25 +4,22 @@ import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
let container: StartedTestContainer | undefined
export async function start(): Promise<StartedTestContainer> {
if (!container) {
container = await new GenericContainer("mongo:7.0-jammy")
.withExposedPorts(27017)
.withEnvironment({
MONGO_INITDB_ROOT_USERNAME: "mongo",
MONGO_INITDB_ROOT_PASSWORD: "password",
})
.withWaitStrategy(
Wait.forSuccessfulCommand(
`mongosh --eval "db.version()"`
).withStartupTimeout(10000)
)
.start()
}
return container
return await new GenericContainer("mongo:7.0-jammy")
.withExposedPorts(27017)
.withEnvironment({
MONGO_INITDB_ROOT_USERNAME: "mongo",
MONGO_INITDB_ROOT_PASSWORD: "password",
})
.withWaitStrategy(
Wait.forSuccessfulCommand(`mongosh --eval "db.version()"`)
)
.start()
}
export async function datasource(): Promise<Datasource> {
const container = await start()
if (!container) {
container = await start()
}
const host = container.getHost()
const port = container.getMappedPort(27017)
return {

View File

@ -4,22 +4,21 @@ import { GenericContainer, Wait, StartedTestContainer } from "testcontainers"
let container: StartedTestContainer | undefined
export async function start(): Promise<StartedTestContainer> {
if (!container) {
container = await new GenericContainer("postgres:16.1-bullseye")
.withExposedPorts(5432)
.withEnvironment({ POSTGRES_PASSWORD: "password" })
.withWaitStrategy(
Wait.forSuccessfulCommand(
"pg_isready -h localhost -p 5432"
).withStartupTimeout(10000)
)
.start()
}
return container
return await new GenericContainer("postgres:16.1-bullseye")
.withExposedPorts(5432)
.withEnvironment({ POSTGRES_PASSWORD: "password" })
.withWaitStrategy(
Wait.forSuccessfulCommand(
"pg_isready -h localhost -p 5432"
).withStartupTimeout(10000)
)
.start()
}
export async function datasource(): Promise<Datasource> {
const container = await start()
if (!container) {
container = await start()
}
const host = container.getHost()
const port = container.getMappedPort(5432)