Skip to content

Commit 9b80c99

Browse files
committed
test(objectql): address the field on field-addressed rule_violation asserts
Claude-Session: https://claude.ai/code/session_01AHeUBbe6S3JRawcpbLejXD Co-authored-by: Claude <noreply@anthropic.com>
1 parent e5a2eec commit 9b80c99

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎packages/objectql/src/engine-predicate-relationship.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ describe('#18682 — engine-produced relationship bindings', () => {
323323
register([gate("record.account.type == 'partner'")]);
324324
const partner = await insert({ name: 'A', amount: 50000, account: 'acc_p' });
325325
expect(partner?.code).toBe('VALIDATION_FAILED');
326-
expect(partner?.fields).toEqual([expect.objectContaining({ code: 'rule_violation', message: THEN })]);
326+
expect(partner?.fields).toEqual([expect.objectContaining({ field: '_record', code: 'rule_violation', message: THEN })]);
327327
const direct = await insert({ name: 'B', amount: 50, account: 'acc_d' });
328328
expect(direct?.code).toBe('VALIDATION_FAILED');
329-
expect(direct?.fields).toEqual([expect.objectContaining({ code: 'rule_violation', message: OTHERWISE })]);
329+
expect(direct?.fields).toEqual([expect.objectContaining({ field: '_record', code: 'rule_violation', message: OTHERWISE })]);
330330
// Each branch admits what it does not refuse, and the other branch is not run.
331331
expect(await insert({ name: 'C', amount: 50, account: 'acc_p' })).toBeNull();
332332
expect(await insert({ name: 'D', amount: 50000, account: 'acc_d' })).toBeNull();
@@ -344,6 +344,7 @@ describe('#18682 — engine-produced relationship bindings', () => {
344344
const direct = await insert({ name: 'A', amount: 50000, account: 'acc_d' });
345345
expect(direct?.code).toBe('VALIDATION_FAILED');
346346
expect(direct?.fields).toEqual([expect.objectContaining({
347+
field: '_record',
347348
code: 'rule_violation',
348349
constraint: expect.objectContaining({ rule: 'sneaky_gate', reason: 'unevaluable' }),
349350
})]);

‎packages/objectql/src/validation/rule-relationship-traversal.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ describe('[#24512] a `conditional` rule\'s `when` reads one hop through a refere
549549
it('a partner account runs `then`', () => {
550550
const refused = verdict(schema, deal(50000), PARTNER);
551551
expect(refused?.code).toBe('VALIDATION_FAILED');
552-
expect(refused?.fields).toEqual([expect.objectContaining({ code: 'rule_violation', message: THEN })]);
552+
expect(refused?.fields).toEqual([expect.objectContaining({ field: '_record', code: 'rule_violation', message: THEN })]);
553553
expect(refused?.fields[0]?.constraint?.reason).toBeUndefined();
554554
// `then` admits what it does not refuse, and `otherwise` is not run.
555555
expect(verdict(schema, deal(50), PARTNER)).toBeNull();
@@ -558,7 +558,7 @@ describe('[#24512] a `conditional` rule\'s `when` reads one hop through a refere
558558
it('any other account runs `otherwise`', () => {
559559
const refused = verdict(schema, deal(50), DIRECT);
560560
expect(refused?.code).toBe('VALIDATION_FAILED');
561-
expect(refused?.fields).toEqual([expect.objectContaining({ code: 'rule_violation', message: OTHERWISE })]);
561+
expect(refused?.fields).toEqual([expect.objectContaining({ field: '_record', code: 'rule_violation', message: OTHERWISE })]);
562562
// `otherwise` admits what it does not refuse, and `then` is not run.
563563
expect(verdict(schema, deal(50000), DIRECT)).toBeNull();
564564
});
@@ -601,6 +601,7 @@ describe('[#24512] a `conditional` rule\'s `when` reads one hop through a refere
601601
expect(refused?.code).toBe('VALIDATION_FAILED');
602602
const gateError = refused?.fields.find((f) => f.constraint?.rule === 'partner_gate');
603603
expect(gateError).toMatchObject({
604+
field: '_record',
604605
code: 'rule_violation',
605606
constraint: { rule: 'partner_gate', reason: 'unevaluable', fault: 'reads more than one relationship hop' },
606607
});
@@ -619,7 +620,7 @@ describe('[#24512] a `conditional` rule\'s `when` reads one hop through a refere
619620
const refused = verdict(schema, deal(50000), related);
620621
expect(refused?.code).toBe('VALIDATION_FAILED');
621622
const gateError = refused?.fields.find((f) => f.constraint?.rule === 'partner_gate');
622-
expect(gateError).toMatchObject({ code: 'rule_violation', constraint: { rule: 'partner_gate', reason: 'unevaluable' } });
623+
expect(gateError).toMatchObject({ field: '_record', code: 'rule_violation', constraint: { rule: 'partner_gate', reason: 'unevaluable' } });
623624
expect(gateError?.message).toContain("'crm_account' declares no 'region'");
624625
// The sibling reading `type` through the same reference refuses with its own message…
625626
expect(messagesOf(refused)).toContain('Partner accounts are capped at 10000.');
@@ -631,7 +632,7 @@ describe('[#24512] a `conditional` rule\'s `when` reads one hop through a refere
631632
it('an empty reference is refused naming the guard, not as a fault in this object\'s columns', () => {
632633
const refused = verdict(schemaOf(gate("record.account.type == 'partner'")), { name: 'A', amount: 50, account: null },
633634
{ account: unavailable('no-reference') });
634-
expect(refused?.fields).toEqual([expect.objectContaining({ code: 'rule_violation', constraint: expect.objectContaining({ rule: 'partner_gate', reason: 'unevaluable' }) })]);
635+
expect(refused?.fields).toEqual([expect.objectContaining({ field: '_record', code: 'rule_violation', constraint: expect.objectContaining({ rule: 'partner_gate', reason: 'unevaluable' }) })]);
635636
expect(refused?.fields[0]?.message).toContain('`conditional` rule whose `when` is `record.account != null`');
636637
expect(refused?.fields[0]?.message).not.toContain('which this object does not declare');
637638
});

0 commit comments

Comments
 (0)