feat(spa): add typed API response mappers and contract guards
All checks were successful
CI / test-and-quality (push) Successful in 2m29s
CI / test-and-quality (pull_request) Successful in 2m20s

This commit is contained in:
2026-03-01 15:32:26 +00:00
parent 634bd617e7
commit de5007943e
5 changed files with 319 additions and 31 deletions

View File

@@ -189,6 +189,23 @@ describe('createAngularApiClient', () => {
);
});
it('returns parse error when successful payload breaks typed contract', async () => {
const http = {
get: vi.fn<AngularHttpClientLike['get']>(async <T>() => ({ ok: true } as T)),
post: vi.fn<AngularHttpClientLike['post']>(async <T>() => ({ ok: true } as T))
};
const client = createAngularApiClient(http as AngularHttpClientLike);
const session = await client.getSession('ABCD12');
expect(session.ok).toBe(false);
if (!session.ok) {
expect(session.status).toBe(200);
expect(session.error.kind).toBe('parse');
expect(session.error.message).toContain('Invalid API contract');
}
});
it('maps HttpErrorResponse-style failures to ApiResult errors', async () => {
const http = {
get: vi.fn<AngularHttpClientLike['get']>(async () => {