Skip to content

Commit 37152c2

Browse files
cursoragentRJK134
andcommitted
test(seed-demo): assert demo-inv-001 outcome shares customer ownership
The Copilot Autofix in 3c1c097 weakened the guard test to only check the demo-outcome-NNN format, which would silently allow a regression back to demo-outcome-001 (owned by demo-cust-marie) on the demo-cust-jeanluc invoice. Strengthen the test to derive the outcome's owning customer from customerDefs using the deterministic seed mapping (demo-outcome-NNN -> demo-appt-NNN -> demo-visit-NNN -> customerDefs[(NNN-1) % len]) and assert it matches the invoice's customerId. Add an explicit regression guard naming demo-outcome-001 so the original bug cannot return unnoticed. Co-authored-by: Richard Knapp <RJK134@users.noreply.github.com>
1 parent 3c1c097 commit 37152c2

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

__tests__/unit/seed.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,36 @@ describe('prisma/seed-demo.ts (demo)', () => {
4848
expect(demoContent).toContain('postcode');
4949
});
5050

51-
it('links the first demo invoice to a valid generated customer visit outcome', () => {
51+
it('links the first demo invoice to a visit outcome owned by the same customer', () => {
52+
// The invoice on line 1322 of seed-demo.ts: demo-inv-001 belongs to
53+
// demo-cust-jeanluc and references a visitOutcomeId. The referenced
54+
// outcome MUST belong to the same customer or the visit-outcome →
55+
// invoice 1:1 link surfaces cross-customer data in the dashboard.
5256
const invoiceMatch = demoContent.match(
5357
/id: 'demo-inv-001'[\s\S]*?customerId: 'demo-cust-jeanluc'[\s\S]*?visitOutcomeId: '([^']+)'/
5458
);
5559

5660
expect(invoiceMatch).not.toBeNull();
61+
const outcomeId = invoiceMatch![1];
62+
expect(outcomeId).toMatch(/^demo-outcome-\d{3}$/);
63+
64+
// Resolve the outcome's owning customer using the deterministic seed
65+
// logic: demo-outcome-NNN is created for demo-appt-NNN, which uses
66+
// demo-visit-NNN, whose customerId = customerDefs[(NNN-1) % len].id.
67+
const customerDefIds = Array.from(
68+
demoContent.matchAll(/\{ id: '(demo-cust-[a-z]+)',/g),
69+
(m) => m[1]
70+
);
71+
expect(customerDefIds.length).toBeGreaterThanOrEqual(15);
72+
73+
const outcomeIndex = parseInt(outcomeId.slice('demo-outcome-'.length), 10) - 1;
74+
const ownerCustomerId = customerDefIds[outcomeIndex % customerDefIds.length];
75+
expect(ownerCustomerId).toBe('demo-cust-jeanluc');
76+
77+
// Explicit regression guard for the original bug: the invoice
78+
// pointed at demo-outcome-001, which is owned by demo-cust-marie.
79+
expect(invoiceMatch![0]).not.toContain("visitOutcomeId: 'demo-outcome-001'");
5780
expect(invoiceMatch![0]).not.toContain("visitOutcomeId: 'demo-outcome-completed'");
58-
expect(invoiceMatch![1]).toMatch(/^demo-outcome-\d{3}$/);
5981
});
6082

6183
it('creates horses linked to customers and yards', () => {

0 commit comments

Comments
 (0)