test(unit): add InvoiceRepository and UserRepository unit tests#551
test(unit): add InvoiceRepository and UserRepository unit tests#551cameri merged 3 commits intocameri:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds unit test coverage for two previously under-tested data-access repositories (InvoiceRepository, UserRepository) by stubbing the DB client and asserting query behavior without real database connections.
Changes:
- Add
UserRepositoryunit tests covering lookups, upserts, vanish-state hydration, balance reads, and stored-procedure calls. - Add
InvoiceRepositoryunit tests covering stored-procedure confirmation, retrieval, pending-invoice paging, status updates, and upserts. - Add a changeset entry documenting the test-only change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/unit/repositories/user-repository.spec.ts | New unit tests for UserRepository methods and query behavior using sinon-stubbed DB client. |
| test/unit/repositories/invoice-repository.spec.ts | New unit tests for InvoiceRepository methods, including stored procedures and SQL generation. |
| .changeset/invoice-user-repo-unit-tests.md | Changeset noting the added unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('encodes pubkey as hex buffer in SQL', () => { | ||
| const sql = repository.setVanished(pubkeyHex, false).toString() | ||
|
|
||
| expect(sql).to.include(pubkeyHex) |
There was a problem hiding this comment.
This test claims to verify that pubkey is encoded as a hex buffer, but it only asserts the SQL contains the hex substring. That would still pass if pubkey were inserted as a plain string. Consider asserting for the specific Postgres buffer literal format Knex generates (e.g., X'…' / E'\\x…') to make the test actually validate the encoding.
| expect(sql).to.include(pubkeyHex) | |
| expect(sql).to.match(new RegExp(`(?:X'${pubkeyHex}'|E'\\\\\\\\x${pubkeyHex}')`, 'i')) |
Description
Add unit tests for
InvoiceRepositoryandUserRepository— two data-access layer components that had ~21% statementcoverage and 0% branch coverage. All public methods are now covered using a sinon-stubbed DB client with no real
database connections.
Related Issue
Closes #491
Motivation and Context
Both repositories lacked meaningful test coverage, making regressions in DB query logic hard to catch. These tests
cover all public CRUD methods and edge cases (missing rows, error propagation, default values, query structure).
How Has This Been Tested?
InvoiceRepositoryundertest/unit/repositories/invoice-repository.spec.tsUserRepositoryundertest/unit/repositories/user-repository.spec.tsCoverage after this PR:
invoice-repository.tsuser-repository.tsTypes of changes
Checklist: