Description
In backend/src/routes/campaigns.test.ts (lines 14-29), the test mocks return total_spent_stroops: '100000000' as a string, but the test assertion expects response.body.total_spent_xlm to equal 10 (a number):
// Mock returns string stroops
mockPool.query.mockResolvedValueOnce({
rows: [{
total_campaigns: '5',
active_campaigns: '3',
total_spent_stroops: '100000000' // String
}]
});
// Test expects numeric XLM
expect(response.body.total_spent_xlm).toBe(10); // Number
Problem
The test validates that 100000000 stroops = 10 XLM, which is correct math. But:
- The mock returns a string (
'100000000'), matching how PostgreSQL returns bigint columns
- If the route handler doesn't explicitly convert the string to a number before division,
'100000000' / 10000000 gives 10 in JS (implicit coercion), but this masks the type issue
- If the handler returns the raw string without conversion, the test would fail with
'100000000' !== 10
The test doesn't verify the actual transformation logic — it assumes the route handler converts correctly without testing the conversion path.
Impact
- Test could pass even if the conversion is accidentally removed (if mock data changes)
- Doesn't test edge cases: very large stroops values, zero, negative
- String vs number type mismatch may surface in production with real PostgreSQL data
Suggested Fix
Test should explicitly verify the type and value:
expect(typeof response.body.total_spent_xlm).toBe('number');
expect(response.body.total_spent_xlm).toBeCloseTo(10, 7);
File
backend/src/routes/campaigns.test.ts — Lines 14-29
Description
In
backend/src/routes/campaigns.test.ts(lines 14-29), the test mocks returntotal_spent_stroops: '100000000'as a string, but the test assertion expectsresponse.body.total_spent_xlmto equal10(a number):Problem
The test validates that
100000000 stroops = 10 XLM, which is correct math. But:'100000000'), matching how PostgreSQL returnsbigintcolumns'100000000' / 10000000gives10in JS (implicit coercion), but this masks the type issue'100000000' !== 10The test doesn't verify the actual transformation logic — it assumes the route handler converts correctly without testing the conversion path.
Impact
Suggested Fix
Test should explicitly verify the type and value:
File
backend/src/routes/campaigns.test.ts— Lines 14-29