Layer Test Reports Specification

Comprehensive test strategy for each architectural layer. Each layer defines the exact tests required, the test report format, and completeness metrics to verify validity.

Test Requirement Legend

πŸ”΄

Required β€” Must add/update tests for every feature

🟑

Optional β€” Only when feature specifically modifies this area

⚫

Disabled β€” Not currently supported

Architecture Flow

β†’

β†’

β†’

β†’

β†’

β†’

β†’

1. Database Layer

lib/db/schema.ts, lib/db/migrations/

What This Layer Does

The foundation of data persistence using Drizzle ORM with Neon Postgres. Tables are defined with TypeScript, and Row Level Security (RLS) policies are specified inline using pgPolicy() to enforce multi-tenancy at the database level.

Why Test This Layer

Testing at this layer ensures your data model is correct before any application code runs. RLS policies act as a security backstopβ€”even if application code has bugs, the database itself prevents unauthorized data access across organizations.

Related Skills

Required Tests

πŸ”΄

Schema Validation Tests

Verify Drizzle schema definitions match database state

Test Types

  • β€’

    Table existence verification

  • β€’

    Column type validation

  • β€’

    Constraint verification (NOT NULL, UNIQUE, FK)

  • β€’

    Index existence checks

  • β€’

    Default value verification

Vitest

neon-testing

Drizzle Kit

$ pnpm vitest run --project integration tests/integration/schema/

πŸ”΄

Migration Tests

Ensure migrations apply cleanly and are reversible

Test Types

  • β€’

    Forward migration success

  • β€’

    Migration idempotency (re-run safety)

  • β€’

    Data preservation during migration

  • β€’

    Schema state after migration matches expected

Drizzle Kit

neon-testing

$ pnpm db:migrate && pnpm db:check

πŸ”΄

RLS Policy Tests

Verify Row Level Security policies enforce access control

Test Types

  • β€’

    Organization isolation (user A cannot see user B's data)

  • β€’

    Authenticated vs anonymous access

  • β€’

    CRUD operation permissions per role

  • β€’

    Cross-organization data leakage prevention

Vitest

neon-testing

Real database branches

$ pnpm vitest run --project integration tests/integration/rls/

Test Report Output

JSON report with table verification counts, migration status, RLS policy test results per table, constraint coverage percentage, and index verification status. HTML report provides visual diff of expected vs actual schema state.

Test Report: 1. Database Layer

MetricDescriptionValue
tables_verifiedNumber of tables with passing schema tests8/8 tables
migrations_statusAll migrations applied successfullyβœ“ 42 migrations
rls_policies_testedRLS policies verified per table32/32 policies
constraint_coverageFK, UNIQUE, NOT NULL constraints verified100%
index_verificationAll indexes exist and are used8/8 indexes

Completeness Checklist

  • Every table in schema.ts has corresponding test file

  • All RLS policies (SELECT, INSERT, UPDATE, DELETE) tested for each table

  • All foreign key relationships verified with referential integrity tests

  • Default values tested for all columns with defaults

Test Coverage Summary

LayerTest CategoriesPrimary ToolReport Type
1. Database Layer3

Vitest

JSON + HTML
2. Data Access / Schema Layer3

Vitest

JSON + HTML
3. Service / Business Logic Layer3

Vitest

JSON + HTML
4. API Layer3

Vitest

JSON + HTML
5. State Management Layer3

Vitest

JSON + HTML
6. UI Component Layer4

Storybook

JSON + HTML
7. Pages / Views Layer4

Playwright

JSON + HTML
8. Observability Layer (Cross-cutting)3

Vitest

JSON + HTML

Quick Reference: Test Commands

# Run all tests

pnpm check

# Run by project

pnpm vitest run --project unit

pnpm vitest run --project integration

pnpm vitest run --project storybook

# Run E2E tests

pnpm playwright test

# Generate reports

pnpm vitest run --reporter=json --outputFile=test-results.json

pnpm playwright test --reporter=html