Skip to content

Commit 10fc899

Browse files
committed
fix: tests
1 parent ff98ade commit 10fc899

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

packages/backend/src/graphql/__tests__/mutations/tiles/create-table.itest.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ describe('create table mutation', () => {
4343
it('should be able create tables with the same name', async () => {
4444
const table = await createTable(
4545
null,
46-
{ input: { name: 'Test Table', isBlank: false } },
46+
{ input: { name: 'Test Table', isBlank: false, databaseType: 'ddb' } },
4747
context,
4848
)
4949

5050
const table2 = await createTable(
5151
null,
52-
{ input: { name: 'Test Table', isBlank: false } },
52+
{ input: { name: 'Test Table', isBlank: false, databaseType: 'ddb' } },
5353
context,
5454
)
5555
expect(table.name).toBe('Test Table')
@@ -58,7 +58,11 @@ describe('create table mutation', () => {
5858

5959
it('should throw an error when table name is empty', async () => {
6060
await expect(
61-
createTable(null, { input: { name: '', isBlank: false } }, context),
61+
createTable(
62+
null,
63+
{ input: { name: '', isBlank: false, databaseType: 'ddb' } },
64+
context,
65+
),
6266
).rejects.toThrow()
6367
})
6468
})

packages/backend/test/pg-global-setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export async function setup() {
2424
`PostgreSQL container started at port ${process.env.POSTGRES_PORT}`,
2525
)
2626

27-
const config = await import('../knexfile')
28-
const client = knex(config.default)
27+
const config = await (await import('../knexfile')).default
28+
const client = knex(config)
2929

3030
// manually running migrations since the programmatic API doesn't work
3131
// see issue here: https://github.com/knex/knex/issues/5323

packages/backend/test/pg-reset-db-setup.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ import { afterEach, beforeEach } from 'vitest'
88

99
import config from '../knexfile'
1010

11-
const client = knex(config as Knex.Config)
12-
1311
beforeEach(async () => {
12+
const client = knex(config as Knex.Config)
13+
1414
// manually running seeds for the same reasons
1515
const seedsToRun = readdirSync(config.seeds.directory)
1616
for (const seedFile of seedsToRun) {
1717
const { seed } = await import(join(config.seeds.directory, seedFile))
1818
await seed(client)
1919
}
20+
await client.destroy()
2021
console.info(`vite: PostgreSQL seeds run`)
2122
})
2223

2324
afterEach(async () => {
25+
const client = knex(config as Knex.Config)
26+
2427
// truncate all tables
2528
const tables = await client('pg_catalog.pg_tables')
2629
.select('tablename')
@@ -31,4 +34,7 @@ afterEach(async () => {
3134
await client.raw(`TRUNCATE TABLE "${table}" CASCADE`)
3235
}
3336
console.info(`vite: PostgreSQL tables truncated`)
37+
38+
// Close the database connection
39+
await client.destroy()
3440
})

0 commit comments

Comments
 (0)