ESLint blanket-exempted every *.spec.ts from the any ban, and no gate type-checked spec files at all (ng test is transpile-only), so a wrong cast in a test could never fail the build. 76 `as any` + 12 `as Extract<>` state-narrowing casts in the three biggest wizard specs read one variant's fields off a whole-union value: if the reducer returned the wrong variant, the assertion silently read undefined instead of failing. expectTag(state, tag) (libs/shared/src/testing/expect-tag.ts) asserts and narrows in one call, replacing every one of those casts. Removes the spec-file any exemption, adds `npm run typecheck` (tsc --noEmit over each project's tsconfig.spec.json) to CI, and forbids production code from importing libs/shared/src/testing via dependency-cruiser. Backend: AanvraagBuilder now models ZaakUrl (closing the last post-Build() mutation) and guards AtStep; null-forgiving `!` on endpoint assertions replaced with Assert.NotNull so a null DTO fails by name, not NullReferenceException. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { expectTag } from '@shared/testing/expect-tag';
|
|
import { BesluitState, reduce, initial } from './besluit.machine';
|
|
|
|
const editingWith = (besluit: string, toelichting = ''): BesluitState => ({
|
|
tag: 'Editing',
|
|
draft: { besluit, toelichting },
|
|
errors: {},
|
|
});
|
|
|
|
describe('besluit reduce', () => {
|
|
it('SetField updates the draft while editing', () => {
|
|
const s = reduce(initial, { tag: 'SetField', key: 'besluit', value: 'Goedkeuren' });
|
|
expect(expectTag(s, 'Editing').draft.besluit).toBe('Goedkeuren');
|
|
});
|
|
|
|
it('Submit with no besluit chosen stays Editing and reports a field error', () => {
|
|
const s = reduce(editingWith(''), { tag: 'Submit' });
|
|
expect(expectTag(s, 'Editing').errors.besluit).toBeTruthy();
|
|
});
|
|
|
|
it('Submit Afwijzen without a toelichting stays Editing and reports a field error', () => {
|
|
const s = reduce(editingWith('Afwijzen'), { tag: 'Submit' });
|
|
expect(expectTag(s, 'Editing').errors.toelichting).toBeTruthy();
|
|
});
|
|
|
|
it('Submit Goedkeuren with no toelichting moves to Submitting (optional there)', () => {
|
|
const s = reduce(editingWith('Goedkeuren'), { tag: 'Submit' });
|
|
expect(expectTag(s, 'Submitting').data).toEqual({
|
|
besluit: 'Goedkeuren',
|
|
toelichting: undefined,
|
|
});
|
|
});
|
|
|
|
it('Submit Afwijzen with a toelichting moves to Submitting with the trimmed value', () => {
|
|
const s = reduce(editingWith('Afwijzen', ' niet erkend '), { tag: 'Submit' });
|
|
expect(expectTag(s, 'Submitting').data).toEqual({
|
|
besluit: 'Afwijzen',
|
|
toelichting: 'niet erkend',
|
|
});
|
|
});
|
|
|
|
it('SubmitConfirmed maps Submitting to Submitted', () => {
|
|
const submitting = reduce(editingWith('Goedkeuren'), { tag: 'Submit' });
|
|
expect(reduce(submitting, { tag: 'SubmitConfirmed' }).tag).toBe('Submitted');
|
|
});
|
|
|
|
it('SubmitFailed maps Submitting to Failed with the error', () => {
|
|
const submitting = reduce(editingWith('Goedkeuren'), { tag: 'Submit' });
|
|
const failed = reduce(submitting, { tag: 'SubmitFailed', error: 'boom' });
|
|
expect(failed).toMatchObject({ tag: 'Failed', error: 'boom' });
|
|
});
|
|
|
|
it('Retry re-submits a failure', () => {
|
|
const submitting = reduce(editingWith('Goedkeuren'), { tag: 'Submit' });
|
|
const failed = reduce(submitting, { tag: 'SubmitFailed', error: 'boom' });
|
|
expect(reduce(failed, { tag: 'Retry' }).tag).toBe('Submitting');
|
|
});
|
|
|
|
it('Reset returns to the initial editing state', () => {
|
|
const submitting = reduce(editingWith('Goedkeuren'), { tag: 'Submit' });
|
|
expect(reduce(submitting, { tag: 'Reset' })).toEqual(initial);
|
|
});
|
|
});
|