Skip to content

test: unit tests for all repositories#66

Merged
greatest0fallt1me merged 2 commits intoCalloraOrg:mainfrom
Code-Paragon:test/repository-tests
Feb 26, 2026
Merged

test: unit tests for all repositories#66
greatest0fallt1me merged 2 commits intoCalloraOrg:mainfrom
Code-Paragon:test/repository-tests

Conversation

@Code-Paragon
Copy link
Copy Markdown
Contributor

Summary

This PR introduces the foundational data access layer and its corresponding isolated unit test suite, ensuring strict database parity by running against a real PostgreSQL instance instead of an in-memory SQLite mock.

Related Issue

Closes #46

Changes Implemented

  • Database Connection: Implemented a pg connection pool in src/db.ts configurable via DATABASE_URL.
  • Repository Pattern: Built the ApiRepository class with standard CRUD operations (create, findById, findAll, update).
  • Test Infrastructure: Configured vitest with @vitest/coverage-v8 to enforce a strict 95% minimum coverage threshold globally on the src/repositories directory.
  • State Isolation: Engineered the test suite to dynamically create the schema in beforeAll and execute a TRUNCATE TABLE apis RESTART IDENTITY CASCADE; in beforeEach to guarantee zero data bleeding between tests.
  • Edge Case Coverage: Explicitly asserted duplicate key constraint violations and null-returns for non-existent IDs.

Verification

  • Vitest coverage report confirms 100% coverage across all statements, branches, functions, and lines.
  • Tests executed successfully against an ephemeral PostgreSQL 15 container.
image image

@greatest0fallt1me
Copy link
Copy Markdown
Contributor

please resolve the conflicts

1 similar comment
@greatest0fallt1me
Copy link
Copy Markdown
Contributor

please resolve the conflicts

@Code-Paragon
Copy link
Copy Markdown
Contributor Author

@greatest0fallt1me I have a few merge conflicts here, mostly in the package.json and lockfile. My laptop is currently dead and I'm waiting for power/charge to get back online.

I’ll resolve these as soon as I’m back at my desk to ensure the lockfile stays perfectly in sync and the JSON remains valid. Thanks for your patience!

@greatest0fallt1me greatest0fallt1me merged commit af9e033 into CalloraOrg:main Feb 26, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Unit Tests for Repositories

2 participants