Skip to content

Commit

Permalink
refactor: move database test to its own
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Jan 2, 2024
1 parent 9262bea commit c2233a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
27 changes: 27 additions & 0 deletions packages/verrou/tests/drivers/database.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import knex from 'knex'
import { test } from '@japa/runner'

import { DatabaseStore } from '../../src/drivers/database.js'
import { configureDatabaseGroupHooks } from '../../test_helpers/index.js'

const db = knex({ client: 'pg', connection: { user: 'postgres', password: 'postgres' } })
test.group('Database Driver', (group) => {
configureDatabaseGroupHooks(db, group)

test('create table with specified tableName', async ({ assert, cleanup }) => {
const store = new DatabaseStore({
connection: db,
dialect: 'pg',
tableName: 'verrou_my_locks',
})

cleanup(async () => {
await db.schema.dropTable('verrou_my_locks')
})

await store.save('foo', 'bar')

const locks = await db.table('verrou_my_locks').select('*')
assert.lengthOf(locks, 1)
})
})
18 changes: 0 additions & 18 deletions packages/verrou/tests/drivers/postgres.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,9 @@ const db = knex({

test.group('Postgres Driver', (group) => {
configureDatabaseGroupHooks(db, group)

registerStoreTestSuite({
test,
store: DatabaseStore,
config: { dialect: 'pg', connection: db },
})

test('create table with specified tableName', async ({ assert, cleanup }) => {
const store = new DatabaseStore({
connection: db,
dialect: 'pg',
tableName: 'verrou_my_locks',
})

cleanup(async () => {
await db.schema.dropTable('verrou_my_locks')
})

await store.save('foo', 'bar')

const locks = await db.table('verrou_my_locks').select('*')
assert.lengthOf(locks, 1)
})
})

0 comments on commit c2233a5

Please sign in to comment.