.gemini/skills/integration-testing/SKILL.md
Database integration testing patterns in LivestockAI
npx skillsauth add captjay98/gemini-livestockai Integration TestingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Integration tests verify database operations and constraints using a separate test database.
# Create database named: livestockai_test
# Via Neon Console or CLI
# .env.test or .env
DATABASE_URL_TEST=postgres://user:[email protected]/livestockai_test?sslmode=require
DATABASE_URL=$DATABASE_URL_TEST bun run db:migrate
bun run test:integration
Located in tests/helpers/db-integration.ts:
import {
getTestDb,
truncateAllTables,
seedTestUser,
seedTestFarm,
seedTestBatch,
closeTestDb,
} from '../helpers/db-integration'
import { describe, it, expect, beforeEach, afterAll } from 'vitest'
import {
getTestDb,
truncateAllTables,
seedTestUser,
seedTestFarm,
seedTestBatch,
closeTestDb,
} from '../helpers/db-integration'
describe('Batch Integration Tests', () => {
beforeEach(async () => {
await truncateAllTables()
})
afterAll(async () => {
await closeTestDb()
})
it('creates batch with correct data', async () => {
const { userId } = await seedTestUser({ email: '[email protected]' })
const { farmId } = await seedTestFarm(userId)
const { batchId } = await seedTestBatch(farmId, {
species: 'Broiler',
initialQuantity: 500,
})
const db = getTestDb()
const batch = await db
.selectFrom('batches')
.where('id', '=', batchId)
.executeTakeFirst()
expect(batch).toBeDefined()
expect(batch?.species).toBe('Broiler')
expect(batch?.initialQuantity).toBe(500)
})
it('enforces foreign key constraints', async () => {
const db = getTestDb()
await expect(
db
.insertInto('batches')
.values({
farmId: 'non-existent-uuid',
species: 'Broiler',
initialQuantity: 100,
})
.execute(),
).rejects.toThrow()
})
})
// Create user with auth
const { userId } = await seedTestUser({
email: '[email protected]',
password: 'password123',
name: 'Test User',
})
// Create farm with modules
const { farmId } = await seedTestFarm(userId, {
name: 'Test Farm',
modules: ['poultry', 'fish'],
})
// Create batch
const { batchId } = await seedTestBatch(farmId, {
species: 'Broiler',
initialQuantity: 500,
livestockType: 'poultry',
})
truncateAllTables() respects foreign key order:
vitest-patterns - Unit testingneon-database - Database patternsbetter-auth - User creationdata-ai
Input validation patterns with Zod in LivestockAI server functions
testing
Unit testing patterns with Vitest in LivestockAI
tools
Server → Service → Repository pattern for feature organization
data-ai
Server-side rendering and server functions with TanStack Start in LivestockAI