feat(fp): WP-05 — parse-don't-validate closure + MDX
Close the three remaining unvalidated `as <DomainType>` casts at the wire boundary (intake-policy, big-register aantekening type, brief passage scope), each replaced by a Result-returning parser with a rejection-case spec, plus the Foundations/Parse, don't validate curriculum page.
This commit is contained in:
@@ -42,6 +42,11 @@ export interface ValidIntake {
|
||||
fallback; the server value wins. */
|
||||
export const SCHOLING_THRESHOLD_DEFAULT = 1000;
|
||||
|
||||
/** The server-owned intake policy (domain-side, parsed from the wire at the boundary). */
|
||||
export interface IntakePolicy {
|
||||
readonly scholingThreshold: number;
|
||||
}
|
||||
|
||||
/** True when NL-hours are low enough that the scholing question must be answered.
|
||||
The threshold is passed in (server-owned), not hardcoded. */
|
||||
export function lageUren(a: Answers, scholingThreshold = SCHOLING_THRESHOLD_DEFAULT): boolean {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { parseIntakePolicy } from './intake-policy.adapter';
|
||||
|
||||
describe('intake-policy.adapter parse boundary', () => {
|
||||
it('parses a well-formed policy', () => {
|
||||
const r = parseIntakePolicy({ scholingThreshold: 800 });
|
||||
expect(r).toEqual({ ok: true, value: { scholingThreshold: 800 } });
|
||||
});
|
||||
|
||||
it('rejects a missing or non-numeric threshold', () => {
|
||||
expect(parseIntakePolicy({}).ok).toBe(false);
|
||||
expect(parseIntakePolicy({ scholingThreshold: '800' }).ok).toBe(false);
|
||||
expect(parseIntakePolicy(null).ok).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Injectable, inject, resource } from '@angular/core';
|
||||
import { Result, ok, err } from '@shared/kernel/fp';
|
||||
import { IntakePolicy } from '@herregistratie/domain/intake.machine';
|
||||
import { ApiClient } from '@shared/infrastructure/api-client';
|
||||
|
||||
/**
|
||||
@@ -11,6 +13,21 @@ export class IntakePolicyAdapter {
|
||||
private client = inject(ApiClient);
|
||||
|
||||
policyResource() {
|
||||
return resource({ loader: () => this.client.policy() });
|
||||
return resource({
|
||||
loader: async () => {
|
||||
const parsed = parseIntakePolicy(await this.client.policy());
|
||||
if (!parsed.ok) throw new Error(parsed.error);
|
||||
return parsed.value;
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Trust-boundary parse: an unrecognized/missing threshold is an explicit Failure. */
|
||||
export function parseIntakePolicy(json: unknown): Result<string, IntakePolicy> {
|
||||
if (typeof json !== 'object' || json === null) return err('intake-policy: not an object');
|
||||
const dto = json as { scholingThreshold?: unknown };
|
||||
if (typeof dto.scholingThreshold !== 'number')
|
||||
return err('intake-policy: missing scholingThreshold');
|
||||
return ok({ scholingThreshold: dto.scholingThreshold });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user