Skip to content

Latest commit

 

History

History
180 lines (141 loc) · 4.57 KB

File metadata and controls

180 lines (141 loc) · 4.57 KB

Testing Setup Summary

This document summarizes what was set up for testing your Nexpo monorepo database and API.

What Was Created

1. Database Tests (pgTAP)

Location: supabase/tests/database/

Files Created:

  • schema.test.sql - Tests database schema (tables, columns, types, indexes)
  • rls.test.sql - Tests Row Level Security policies
  • triggers.test.sql - Tests database triggers
  • functions.test.sql - Tests database functions
  • README.md - Database testing documentation

Run with:

yarn test:db

2. API Tests (Vitest)

Location: packages/api/src/__tests__/

Files Created:

  • router.test.ts - Comprehensive tRPC router tests
  • helpers.ts - Test helper functions
  • setup.ts - Test environment setup
  • README_TESTING.md - API testing documentation

Mock Files:

  • packages/api/src/__mocks__/supabase.ts - Mock Supabase client

Configuration:

  • packages/api/vitest.config.ts - Vitest configuration

Run with:

yarn test:api
# or
cd packages/api && yarn test

3. Documentation

Files Created:

  • TESTING_PLAN.md - Comprehensive testing strategy and plan
  • TESTING_QUICKSTART.md - Quick start guide for testing
  • TESTING_SUMMARY.md - This file

4. Package Configuration

Updated Files:

  • package.json - Added test scripts:

    • test - Run all tests
    • test:db - Run database tests
    • test:api - Run API tests
    • test:watch - Watch mode
    • test:coverage - Coverage report
  • packages/api/package.json - Added:

    • Vitest dependencies (vitest, @vitest/ui, @vitest/coverage-v8)
    • Test scripts (test, test:watch, test:ui, test:coverage)

5. Bug Fixes

Fixed:

  • packages/api/src/index.ts - Fixed userCreate mutation to use input.name instead of input

Test Coverage

Database Tests

  • ✅ Schema structure (tables, columns, types, constraints)
  • ✅ Indexes
  • ✅ Row Level Security policies
  • ✅ Database triggers
  • ✅ Database functions

API Tests

  • hello procedure (with and without name)
  • userList procedure (success and error cases)
  • userById procedure (found, not found)
  • userCreate procedure (success and error cases)
  • testAuth procedure (authentication flow)

Next Steps

  1. Install dependencies:

    yarn install
  2. Start Supabase (if not running):

    yarn supabase:start
  3. Run tests to verify setup:

    # Database tests
    yarn test:db
    
    # API tests
    yarn test:api
  4. Add more tests as needed:

    • Add database tests for new tables/columns
    • Add API tests for new tRPC procedures
    • Add integration tests for end-to-end flows
  5. Set up CI/CD:

    • See TESTING_PLAN.md for GitHub Actions example
    • Configure test runs in your CI/CD pipeline

File Structure

.
├── supabase/
│   └── tests/
│       └── database/
│           ├── schema.test.sql
│           ├── rls.test.sql
│           ├── triggers.test.sql
│           ├── functions.test.sql
│           └── README.md
├── packages/
│   └── api/
│       ├── vitest.config.ts
│       ├── README_TESTING.md
│       └── src/
│           ├── __tests__/
│           │   ├── router.test.ts
│           │   ├── helpers.ts
│           │   └── setup.ts
│           └── __mocks__/
│               └── supabase.ts
├── TESTING_PLAN.md
├── TESTING_QUICKSTART.md
└── TESTING_SUMMARY.md

Available Commands

Root Level

yarn test              # Run all tests
yarn test:db           # Run database tests
yarn test:api          # Run API tests
yarn test:watch        # Watch mode
yarn test:coverage     # Coverage report

API Package

cd packages/api
yarn test              # Run tests once
yarn test:watch        # Watch mode
yarn test:ui           # Interactive UI
yarn test:coverage     # Coverage report

Resources

Support

If you encounter issues:

  1. Check the troubleshooting sections in the documentation
  2. Verify all dependencies are installed
  3. Ensure Supabase is running for database tests
  4. Check environment variables are set correctly