v0.1.5: detect free windows in the estimate fallback + add API tests
All checks were successful
build-apk / build (push) Successful in 49m41s
All checks were successful
build-apk / build (push) Successful in 49m41s
App: - When the single-estimate fallback sees MaxTime 0 (or an all-$0.00 ladder), show "Parking is currently free" instead of a bogus $0.00 purchase ladder. Free-detection extracted to tested client helpers (isFreeEstimate/ladderAllFree). Client + tests (node:test, zero deps): - src/estimates.ts: pure isFreeEstimate/ladderAllFree helpers (exported). - test/estimates + test/http (mocked fetch): headers, query serialization, error->ParkSmarterApiError, rolling Auth_Token refresh, 401 clears token. - test/integration: live checks against the Sandpoint (DSB) zones; targets the `test` instance by default and SKIPS when it's unreachable (non-prod is IP-restricted -> 403). Verified 3/3 green against prodv2 read-only. - CI runs `npm test` as a build gate. Note: dev/stage/test instances return 403 "Web App - Unavailable" from the public internet (IP-restricted). API schema is otherwise unchanged vs Jul 6. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
f8d9e2970c
commit
7212badd2d
9 changed files with 276 additions and 13 deletions
32
parksmarter-client/test/estimates.test.mjs
Normal file
32
parksmarter-client/test/estimates.test.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Pure unit tests for the estimate-classification helpers (no network).
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { isFreeEstimate, ladderAllFree } from '../dist/index.js';
|
||||
|
||||
test('isFreeEstimate: MaxTime 0 is a free window', () => {
|
||||
assert.equal(isFreeEstimate({ MaxTime: 0 }), true);
|
||||
assert.equal(isFreeEstimate({ MaxTime: '0' }), true); // API sends numbers as strings
|
||||
});
|
||||
|
||||
test('isFreeEstimate: positive MaxTime is a paid zone', () => {
|
||||
assert.equal(isFreeEstimate({ MaxTime: 33 }), false);
|
||||
assert.equal(isFreeEstimate({ MaxTime: '33' }), false);
|
||||
});
|
||||
|
||||
test('isFreeEstimate: missing/null MaxTime => no paid time => free', () => {
|
||||
assert.equal(isFreeEstimate({}), true);
|
||||
assert.equal(isFreeEstimate(null), true);
|
||||
assert.equal(isFreeEstimate(undefined), true);
|
||||
});
|
||||
|
||||
test('ladderAllFree: every rung $0.00 => true', () => {
|
||||
assert.equal(ladderAllFree([{ ParkingCost: '0.00' }, { ParkingCost: 0 }]), true);
|
||||
});
|
||||
|
||||
test('ladderAllFree: any priced rung => false', () => {
|
||||
assert.equal(ladderAllFree([{ ParkingCost: '0.00' }, { ParkingCost: '0.10' }]), false);
|
||||
});
|
||||
|
||||
test('ladderAllFree: empty ladder => false (nothing to conclude)', () => {
|
||||
assert.equal(ladderAllFree([]), false);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue