mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
Six delete dialogs ask for a name typed exactly, as z.literal(name, {
errorMap: () => ({ message }) }). zod 4 took errorMap out of a schema's
params — it is `error` now — and ignores what it does not know, so since
the version sweep a wrong entry has shown zod's default, `Invalid input:
expected "delete acme"`, instead of "You must enter 'delete acme' to
proceed". The types caught it: the object literal no longer matched, and the
failed overload left the field's value typed as any literal, which the
input would not take.
The six build the field with createConfirmationSchema(name, message), which
spells it the zod 4 way. confirmation.test.ts checks the exact text passes
and near misses fail with the given message; with the errorMap spelling put
back, the second case fails on zod's default. zod 3 kept the message, so
this is the behaviour from before the sweep.
Co-authored-by: Hanzo Dev <[email protected]>
31 lines
924 B
TypeScript
31 lines
924 B
TypeScript
/**
|
|
* Typing a name to confirm a delete.
|
|
*
|
|
* Run: npx tsx --test packages/lib/__tests__/confirmation.test.ts
|
|
*/
|
|
import assert from 'node:assert/strict';
|
|
import { describe, test } from 'node:test';
|
|
|
|
import { createConfirmationSchema } from '../types/confirmation';
|
|
|
|
const message = "You must enter 'delete acme' to proceed";
|
|
const schema = createConfirmationSchema('delete acme', message);
|
|
|
|
describe('createConfirmationSchema', () => {
|
|
test('accepts the text, exactly', () => {
|
|
assert.equal(schema.safeParse('delete acme').success, true);
|
|
});
|
|
|
|
test('refuses anything else with the message it was given', () => {
|
|
for (const typed of ['', 'delete', 'Delete Acme', 'delete acme ']) {
|
|
const result = schema.safeParse(typed);
|
|
|
|
assert.equal(result.success, false, typed);
|
|
assert.deepEqual(
|
|
result.error?.issues.map((issue) => issue.message),
|
|
[message],
|
|
);
|
|
}
|
|
});
|
|
});
|