Skip to content

test: add unit tests for useSettings hook and formatAmountWithPreference utility - #932

Merged
ogazboiz merged 4 commits into
LabsCrypt:mainfrom
Nursca:test/useSetting
Jun 29, 2026
Merged

test: add unit tests for useSettings hook and formatAmountWithPreference utility#932
ogazboiz merged 4 commits into
LabsCrypt:mainfrom
Nursca:test/useSetting

Conversation

@Nursca

@Nursca Nursca commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Closes #882

Here is a summary of the changes made:

Created frontend/src/hooks/useSettings.test.ts:
Simulated the global localStorage environment properly for vitest to support the tests.
Settings State and Storage Test: Validated that setTheme, setDisplayCurrency, setAmountFormat, and setDecimalPlaces all correctly update both the hook's returned state as well as their respective STORAGE_KEYS in localStorage.
Hydration Test: Validated that if localStorage has existing seeded values, the useSettings hook correctly hydrates state from them on mount.
Formatting Tests: Added specific test scenarios for formatAmountWithPreference():
Tested that the function correctly truncates based on predefined decimals (2, 4, 7).
Ensured trailing zeros after decimal truncation are effectively trimmed.
Confirmed it appropriately resolves and calculates against various input primitive types (bigint, number, and string).

Closes #884
Here's a breakdown of the implementation:

Created frontend/src/lib/api/streams.test.ts:
Mocked the global fetch via vi.fn() to observe API calls without triggering live network requests.
Endpoint Fallback: Added tests to ensure that the function accurately loops to the next getStreamsEndpointCandidates endpoint if a 404 status occurs, and verified it appropriately handles throwing the last captured error if all candidates fail.
Payload Shapes: Included coverage guaranteeing that responses in both the direct array format [ ... ] and object property format { data: [ ... ] } are successfully parsed and flattened.
Mapping (mapBackendStream): Created specialized tests confirming logic handling in:
Token Label Resolution: Correctly assigns known token labels based on the mapping (e.g. USDC to its address) and checks that it defaults to address substring truncating correctly (XXX...YYY) as a fallback for unknown addresses.
Stroop Scaling: Verified that values output by toTokenAmount() are being processed accurately for ratePerSecond, deposited, and withdrawn token amounts.
Stream Status: Ensured toIncomingStreamStatus successfully routes conditions for Active, Paused, and Completed.

Closes #889
Here is a summary of the implemented changes:

Added backend-docker job in .github/workflows/ci.yml:
The job uses dorny/paths-filter to selectively run whenever there are changes targeting backend/** or docker-compose.yml via PRs, or on normal pushes to the repository.
It executes docker build -f backend/Dockerfile backend and docker compose build.
It performs the regression health check by starting Postgres, executing database schema pushes through npx -y prisma db push, booting the backend image, and verifying availability via curl --fail http://localhost:3001/health.
Fixed backend/Dockerfile Regressions:
Swapped npm ci with npm install in the container configuration since the package-lock.json lives at the workspace root and is inaccessible within the localized backend build context.
Inserted a COPY prisma ./prisma command. Before this, the missing schema.prisma in the container meant npm run build's prisma generate step was failing silently or ignoring critical generated schema clients for the production runner.
Enhanced docker-compose.yml:
Injected a localized healthcheck script using wget --spider to natively verify http://localhost:3001/health in Docker. This establishes robust dependencies for local startups and avoids downstream failures when waiting for the backend to become active.

Closes #895
Here's what was addressed:

Pinned Mutable Base Images: Updated backend/Dockerfile to pin node:20-alpine explicitly to its precise digest (sha256:fb4cd12c85ee03686f6af5362a0b0d56d50c58a04632e6c0fb8363f609372293), preventing silent upstream changes from invalidating the build integrity.
Added Docker to Dependabot: Extended .github/dependabot.yml with the docker package-ecosystem. Dependabot is now configured to automatically bump digest tags when upstream fixes are released across both the /backend directory (for the Dockerfile) and the root / (for docker-compose.yml).
Postgres Version Alignment & Pinning: Updated the CI Postgres service in .github/workflows/ci.yml from postgres:15 to align with the rest of the application's environment (postgres:16-alpine). Furthermore, I also explicitly pinned both the CI service and the docker-compose.yml service to the specific digest hash for postgres:16-alpine to maintain strict reproducibility everywhere.

@Nursca
Nursca marked this pull request as ready for review June 29, 2026 18:22
@ogazboiz
ogazboiz merged commit 6f02d20 into LabsCrypt:main Jun 29, 2026
7 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment