36 lines
1018 B
TypeScript
36 lines
1018 B
TypeScript
import { describe, it, expect } from 'vitest'
|
|||
|
|
import { eq } from 'drizzle-orm'
|
||
|
|
import { createTestDb, insertTestBot } from './db.js'
|
||
|
|
|
||
|
|
describe('test helpers', () => {
|
||
|
|
it('creates in-memory DB, inserts a bot, and queries it back', () => {
|
||
|
|
const { db, schema } = createTestDb()
|
||
|
|
|
||
|
|
const bot = insertTestBot(db, { name: 'SatoshiBot' })
|
||
|
|
|
||
|
|
const found = db
|
||
|
|
.select()
|
||
|
|
.from(schema.bots)
|
||
|
|
.where(eq(schema.bots.id, bot.id))
|
||
|
|
.get()
|
||
|
|
|
||
|
|
expect(found).toBeDefined()
|
||
|
|
expect(found!.name).toBe('SatoshiBot')
|
||
|
|
expect(found!.eloRating).toBe(1200)
|
||
|
|
expect(found!.webhookUrl).toBe('http://test.local/webhook')
|
||
|
|
})
|
||
|
|
|
||
|
|
it('each createTestDb is isolated', () => {
|
||
|
|
const { db: db1, schema: s1 } = createTestDb()
|
||
|
|
const { db: db2, schema: s2 } = createTestDb()
|
||
|
|
|
||
|
|
insertTestBot(db1, { name: 'BotInDb1' })
|
||
|
|
|
||
|
|
const inDb1 = db1.select().from(s1.bots).all()
|
||
|
|
const inDb2 = db2.select().from(s2.bots).all()
|
||
|
|
|
||
|
|
expect(inDb1).toHaveLength(1)
|
||
|
|
expect(inDb2).toHaveLength(0)
|
||
|
|
})
|
||
|
|
})
|