test: add unit tests for API route error conditions#652
Open
JosephOnuh wants to merge 1 commit into
Open
Conversation
Set up vitest 3.2.4 with path aliases (@/ and @solarproof/stellar). 20 tests across two suites: POST /api/readings (14 tests): - invalid payload: missing fields, bad uuid, non-positive kwh, bad timestamp, wrong signature length, non-JSON body - meter not found (404) - invalid / throwing Ed25519 signature (401) - DB insert failure (500) - on-chain anchor failure (500) - mint failure (500) - missing cooperative admin address (500) GET /api/verify (6 tests): - missing id param (400) - empty id (400) - certificate not found (404) - full chain returned (200) - null meter_proof when reading missing (200) - Stellar explorer URLs present Closes AnnabelJoe#523
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #523
Sets up vitest and adds 20 unit tests covering every validation failure and external dependency error path across both API routes.
Test setup
vitest@3.2.4+@vitest/coverage-v8vitest.config.tswith@path alias and@solarproof/stellarsource aliaspnpm testscript added toapps/web/package.jsonTest coverage
POST /api/readings— 14 testsGET /api/verify— 6 testsidparam → 400idparam → 400Acceptance criteria