test(branch): prove each widget filters by the branch selected, not merely by a branch
The previous check asked whether a dashboard query mentions branch_id. That is
the weaker half of the question. A widget that hardcoded the main branch, or read
a stale id off the URL, or took auth()->user()->branch_id instead of the session,
would mention branch_id on every query and still show the wrong branch's numbers
— and it would look perfectly correct in testing, because the main branch is the
one usually selected.
So the assertion is now on the bound value, not the SQL text. Laravel's bindings
are positional, so the value belonging to a `branch_id = ?` predicate is found by
counting the placeholders before it. Every dashboard is rendered under each
branch that carries data, and every branch id bound into a branch_id comparison
must equal the branch the session selected.
The seven widget components are also mounted directly, rather than only through
the pages that embed them. Two of them — EnrollmentTrends and RevenueWidget —
are written but on no view today, so page-level coverage alone would have said
nothing about either.
Measured on the live tenant: with branch 1 selected, 536 branch bindings, all of
them 1. With branch 2, 1,182 bindings, all of them 2. No dashboard binds a branch
other than the selected one.
Co-Authored-By:
Claude Opus 5 (1M context) <noreply@anthropic.com>
Showing
Please register or sign in to comment