Skip to content

Commit 3ffa21c

Browse files
committed
test(objectql): pin the multi-value non-array sentence at the validator and the lone-scalar wrap on the write path (#29244)
Claude-Session: https://claude.ai/code/session_01ADHkmPFEXGDQbc7fNcM24e Co-authored-by: Claude <noreply@anthropic.com>
1 parent 542d69a commit 3ffa21c

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎packages/objectql/src/validation/record-validator.select-shape.test.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,15 @@ describe('#29244 — what the rule leaves alone', () => {
126126
expect(errorsOf({ decl_multi: ['z'] }).map((e) => e.code)).toEqual(['invalid_option']);
127127
});
128128

129-
it('a lone scalar on a multi-value select is still wrapped, and a lone object still answers invalid_type_array', () => {
130-
expect(errorsOf({ free_multi: 'x' })).toEqual([]);
131-
const errs = errorsOf({ free_multi: { a: 1 } });
132-
expect(errs.map((e) => e.code)).toEqual(['invalid_type']);
133-
expect(errs[0].message).toMatch(/array/i);
134-
expect(errs[0].message).not.toContain('option values');
129+
it('a value that is not an array on a multi-value select keeps its existing invalid_type_array sentence', () => {
130+
// (The engine wraps a lone scalar before this validator runs; the write
131+
// path test below lands one.)
132+
for (const value of ['x', { a: 1 }]) {
133+
const errs = errorsOf({ free_multi: value });
134+
expect(errs.map((e) => e.code)).toEqual(['invalid_type']);
135+
expect(errs[0].message).toMatch(/must be an array/i);
136+
expect(errs[0].message).not.toContain('option values');
137+
}
135138
});
136139

137140
it('null and undefined are unchanged', () => {
@@ -194,9 +197,13 @@ describe('#29244 — write path end to end: no object or array reaches the drive
194197
expect(rows.get('rec_1')).toEqual({ id: 'rec_1', stage: 'orig' });
195198
});
196199

197-
it('a scalar and an array of scalars on the same path still land', async () => {
200+
it('a scalar, an array of scalars and a lone scalar (wrapped) on the same path still land', async () => {
198201
const { engine, writes } = await boot();
199202
await engine.update('shape_deal', { stage: 'won', labels: ['x', 'y'] } as any, { where: { id: 'rec_1' } } as any);
200-
expect(writes).toEqual([expect.objectContaining({ stage: 'won', labels: ['x', 'y'] })]);
203+
await engine.insert('shape_deal', { stage: 'open', labels: 'x' } as any);
204+
expect(writes).toEqual([
205+
expect.objectContaining({ stage: 'won', labels: ['x', 'y'] }),
206+
expect.objectContaining({ stage: 'open', labels: ['x'] }),
207+
]);
201208
});
202209
});

0 commit comments

Comments
 (0)