1
0
Fork 0
mirror of synced 2024-10-04 12:03:31 +13:00

Clean up correctly after Postgres integration tests.

This commit is contained in:
Sam Rose 2023-10-13 15:59:07 +01:00
parent e1af1a5be3
commit 0b8c829ed1

View file

@ -1060,48 +1060,41 @@ describe("postgres integrations", () => {
describe("POST /api/datasources/:datasourceId/schema", () => { describe("POST /api/datasources/:datasourceId/schema", () => {
let client: Client let client: Client
beforeAll(async () => { beforeEach(async () => {
client = new Client( client = new Client(
(await databaseTestProviders.postgres.getDsConfig()).config! (await databaseTestProviders.postgres.getDsConfig()).config!
) )
await client.connect() await client.connect()
}) })
afterAll(async () => { afterEach(async () => {
await client.query(`DROP TABLE IF EXISTS "table"`)
await client.end() await client.end()
}) })
it("recognises when a table has no primary key", async () => { it("recognises when a table has no primary key", async () => {
await client.query(` await client.query(`CREATE TABLE "table" (id SERIAL)`)
CREATE TABLE table_without_primary_key (
id SERIAL
)
`)
const response = await makeRequest( const response = await makeRequest(
"post", "post",
`/api/datasources/${postgresDatasource._id}/schema` `/api/datasources/${postgresDatasource._id}/schema`
) )
expect(response.body.errors).toMatchObject({ expect(response.body.errors).toEqual({
table_without_primary_key: "Table must have a primary key.", table: "Table must have a primary key.",
}) })
}) })
it("recognises when a table is using a reserved column name", async () => { it("recognises when a table is using a reserved column name", async () => {
await client.query(` await client.query(`CREATE TABLE "table" (_id SERIAL PRIMARY KEY) `)
CREATE TABLE table_with_reserved_column_name (
_id SERIAL
)
`)
const response = await makeRequest( const response = await makeRequest(
"post", "post",
`/api/datasources/${postgresDatasource._id}/schema` `/api/datasources/${postgresDatasource._id}/schema`
) )
expect(response.body.errors).toMatchObject({ expect(response.body.errors).toEqual({
table_without_primary_key: "Table must have a primary key.", table: "Table contains invalid columns.",
}) })
}) })
}) })