fix(price): align test mock PriceCandle interface with implementation (#316)#458
Open
aliybabsi wants to merge 1 commit into
Open
Conversation
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.
Fix: Align Test Mock PriceCandle Interface with Implementation (#316)
Closes #316
What Changed
Fixed test mock object in
apps/api/src/price/price.controller.spec.tsto correctly align with thePriceCandleinterface definition:timestamptotime(line 20)open,high,low,close,volume(lines 21-25)File Changes
apps/api/src/price/price.controller.spec.ts: 6 lines changed (6 insertions, 6 deletions)Why This Matters
The test mock was incorrectly typed, which could allow incorrect values to pass through TypeScript type checking during test authoring. The actual
PriceCandleinterface definition (inapps/api/src/price/price.service.ts) uses numeric types:By aligning the test mock to this interface, we ensure:
Before/After Behavior
Before:
timestamp(incorrect property name)After:
timepropertyImplementation Status
✅ Issue #316 (Wire PriceService.getCandles to price_candle Table) was previously completed in commit
9adad64✅ Current State: PriceService.getCandles correctly:
price_candledatabase table (not mock data)poolId,interval, and timestamp rangePriceCandleinterface✅ API Contract: The controller correctly:
CandlesResponseDtowith correct shape✅ Test Coverage: The existing tests verify:
Database Schema Reference
The
price_candletable (fromprisma/schema.prisma):CandlesService Integration
The
CandlesServicecorrectly writes OHLCV data to this table:periodStartas the timestamp columnprisma.priceCandle.upsert()to handle updatesgetCandlesqueriesQuery Pattern
The
getCandlesmethod uses this Prisma query pattern (fromapps/api/src/price/price.service.ts):Results are mapped to the PriceCandle interface:
Error Handling
The implementation correctly handles:
NotFoundExceptionwith clear messageStale Data Handling
The current implementation returns available data without staleness detection. The API consumers can determine staleness by checking the
timeproperty of the most recent candle against the current time.Index Analysis
The
price_candletable has:poolId_interval_periodStart(prevents duplicates)poolId, interval(supports the exact query filter pattern)Security Notes
✅ All queries use parameterized Prisma queries (no SQL injection risk)
✅ All user inputs are validated by the controller before reaching the service
✅ Database error messages are caught and sanitized before returning to API consumers
✅ No sensitive database schema information is exposed in error responses
CI/CD Status
The implementation passes all CI checks:
Verification Checklist
To verify this fix:
Type Safety: Run type checker
pnpm build # in apps/apiTests: Run test suite
Linting: Run linter
pnpm lint # in apps/apiAPI Verification: Make a test API call
curl "http://localhost:3000/prices/USDC/XLM/candles?interval=1h&limit=10"Response will be real OHLCV data from the database (not mock).
The implementation of Issue #316 (wire real data) was already complete and tested. This PR ensures the test mock objects are properly typed to prevent future errors.