Skip to content

test(unit): add InvoiceRepository and UserRepository unit tests#551

Merged
cameri merged 3 commits intocameri:mainfrom
CKodidela:test/invoice-user-repos
Apr 21, 2026
Merged

test(unit): add InvoiceRepository and UserRepository unit tests#551
cameri merged 3 commits intocameri:mainfrom
CKodidela:test/invoice-user-repos

Conversation

@CKodidela
Copy link
Copy Markdown
Collaborator

@CKodidela CKodidela commented Apr 20, 2026

Description

Add unit tests for InvoiceRepository and UserRepository — two data-access layer components that had ~21% statement
coverage 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?

  • 20 new tests for InvoiceRepository under test/unit/repositories/invoice-repository.spec.ts
  • 21 new tests for UserRepository under test/unit/repositories/user-repository.spec.ts
  • Full test suite (1002 tests) passes with no regressions
  • DB client stubbed via sinon throughout — no real DB connections used

Coverage after this PR:

File Statements Branches
invoice-repository.ts 21% → 88% 0% → 44%
user-repository.ts 21% → 93% 0% → 67%

Types of changes

  • Non-functional change (docs, style, minor refactor)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Copilot AI review requested due to automatic review settings April 20, 2026 06:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 UserRepository unit tests covering lookups, upserts, vanish-state hydration, balance reads, and stored-procedure calls.
  • Add InvoiceRepository unit 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.

Comment thread test/unit/repositories/invoice-repository.spec.ts Outdated
it('encodes pubkey as hex buffer in SQL', () => {
const sql = repository.setVanished(pubkeyHex, false).toString()

expect(sql).to.include(pubkeyHex)
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
expect(sql).to.include(pubkeyHex)
expect(sql).to.match(new RegExp(`(?:X'${pubkeyHex}'|E'\\\\\\\\x${pubkeyHex}')`, 'i'))

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread test/unit/repositories/invoice-repository.spec.ts
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 20, 2026

Coverage Status

coverage: 74.365% (+0.6%) from 73.743% — CKodidela:test/invoice-user-repos into cameri:main

@CKodidela CKodidela requested a review from cameri April 20, 2026 06:33
@cameri cameri self-assigned this Apr 21, 2026
@cameri cameri merged commit 7fc0552 into cameri:main Apr 21, 2026
12 checks passed
@CKodidela CKodidela deleted the test/invoice-user-repos branch April 21, 2026 01:40
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.

test: add unit tests for invoice and user repositories

4 participants