Agent skill
Integration Testing
Database integration testing patterns in LivestockAI
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/integration-testing-captjay98-livestockai
SKILL.md
Integration Testing
Integration tests verify database operations and constraints using a separate test database.
Setup
1. Create Test Database
# Create database named: livestockai_test
# Via Neon Console or CLI
2. Set Environment Variable
# .env.test or .env
DATABASE_URL_TEST=postgres://user:[email protected]/livestockai_test?sslmode=require
3. Run Migrations
DATABASE_URL=$DATABASE_URL_TEST bun run db:migrate
4. Run Tests
bun run test:integration
Test Helpers
Located in tests/helpers/db-integration.ts:
import {
getTestDb,
truncateAllTables,
seedTestUser,
seedTestFarm,
seedTestBatch,
closeTestDb,
} from '../helpers/db-integration'
Example Integration Test
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()
})
})
Seeding Helpers
// 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',
})
Truncation Order
truncateAllTables() respects foreign key order:
- Dependent tables first (sales, mortality_records, etc.)
- Parent tables last (users, farms)
Related Skills
vitest-patterns- Unit testingneon-database- Database patternsbetter-auth- User creation
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?