Skip to content

Commit af9e510

Browse files
committed
test(objectql): field-address the progress-bounds code assertions (#20386)
check:error-code-casing reads a bare `{ code: 'max_value' }` as an error.code emission; naming the field makes it the field-addressed validator code it is. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N8TPEsoJxPsdSdNKGnNGEN
1 parent 5c41482 commit af9e510

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎packages/objectql/src/validation/record-validator.progress-bounds.test.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ describe('validateRecord — a `progress` field\'s `min` / `max` are enforced (#
7676

7777
it('one bound declared alone binds alone', () => {
7878
const maxOnly = { fields: { v: { type: 'progress', label: 'Done', max: 100 } } };
79-
expect(fieldsOf(maxOnly, { v: 101 })?.[0]).toMatchObject({ code: 'max_value' });
79+
expect(fieldsOf(maxOnly, { v: 101 })?.[0]).toMatchObject({ field: 'v', code: 'max_value' });
8080
expect(fieldsOf(maxOnly, { v: -1000 })).toBeNull();
8181
const minOnly = { fields: { v: { type: 'progress', label: 'Done', min: 0 } } };
82-
expect(fieldsOf(minOnly, { v: -0.5 })?.[0]).toMatchObject({ code: 'min_value' });
82+
expect(fieldsOf(minOnly, { v: -0.5 })?.[0]).toMatchObject({ field: 'v', code: 'min_value' });
8383
expect(fieldsOf(minOnly, { v: 1e6 })).toBeNull();
8484
// No bound declared: nothing is invented for the type (no implicit 0..100).
8585
const unbounded = { fields: { v: { type: 'progress', label: 'Done' } } };
@@ -88,9 +88,9 @@ describe('validateRecord — a `progress` field\'s `min` / `max` are enforced (#
8888
});
8989

9090
it('refuses on update too, judges a string-carried number after coercion, and never re-reads an omitted field', () => {
91-
expect(fieldsOf(BOUNDED('progress'), { v: 150 }, 'update')?.[0]).toMatchObject({ code: 'max_value' });
92-
expect(fieldsOf(BOUNDED('progress'), { v: '150' })?.[0]).toMatchObject({ code: 'max_value' });
93-
expect(fieldsOf(BOUNDED('progress'), { v: '-5' })?.[0]).toMatchObject({ code: 'min_value' });
91+
expect(fieldsOf(BOUNDED('progress'), { v: 150 }, 'update')?.[0]).toMatchObject({ field: 'v', code: 'max_value' });
92+
expect(fieldsOf(BOUNDED('progress'), { v: '150' })?.[0]).toMatchObject({ field: 'v', code: 'max_value' });
93+
expect(fieldsOf(BOUNDED('progress'), { v: '-5' })?.[0]).toMatchObject({ field: 'v', code: 'min_value' });
9494
expect(fieldsOf(BOUNDED('progress'), { v: '50' })).toBeNull();
9595
// The WRITTEN value only: an update that does not carry the field is not judged.
9696
expect(fieldsOf(BOUNDED('progress'), { other: 1 }, 'update')).toBeNull();
@@ -100,16 +100,16 @@ describe('validateRecord — a `progress` field\'s `min` / `max` are enforced (#
100100
describe('validateRecord — ⛔ `progress` takes the bounds only, never `scale` or `precision` (#20386)', () => {
101101
it('`scale: 0` is not read on `progress` — the same declaration on `slider` refuses', () => {
102102
expect(fieldsOf(BOUNDED('progress', { scale: 0 }), { v: 33.5 })).toBeNull();
103-
expect(fieldsOf(BOUNDED('slider', { scale: 0 }), { v: 33.5 })?.[0]).toMatchObject({ code: 'max_scale' });
103+
expect(fieldsOf(BOUNDED('slider', { scale: 0 }), { v: 33.5 })?.[0]).toMatchObject({ field: 'v', code: 'max_scale' });
104104
});
105105

106106
it('`precision: 2` is not read on `progress` — the same declaration on `slider` refuses', () => {
107107
expect(fieldsOf(BOUNDED('progress', { precision: 2 }), { v: 99.5 })).toBeNull();
108-
expect(fieldsOf(BOUNDED('slider', { precision: 2 }), { v: 99.5 })?.[0]).toMatchObject({ code: 'max_precision' });
108+
expect(fieldsOf(BOUNDED('slider', { precision: 2 }), { v: 99.5 })?.[0]).toMatchObject({ field: 'v', code: 'max_precision' });
109109
});
110110

111111
it('a bound still answers first when `scale` / `precision` are declared beside it', () => {
112-
expect(fieldsOf(BOUNDED('progress', { scale: 0, precision: 2 }), { v: 150.5 })?.[0]).toMatchObject({ code: 'max_value' });
112+
expect(fieldsOf(BOUNDED('progress', { scale: 0, precision: 2 }), { v: 150.5 })?.[0]).toMatchObject({ field: 'v', code: 'max_value' });
113113
});
114114
});
115115

0 commit comments

Comments
 (0)