# Testing

```bash
php artisan test            # full suite (SQLite in-memory, array cache/mail, sync queue)
php artisan test --filter=Inventory
```

No external service is ever called: Paystack and AI providers are faked (from Phases 2 and 4).

| Suite | Covers |
|---|---|
| `tests/Unit/MoneyTest` | naira parsing, formatting, basis-point maths, immutability |
| `Feature/Auth/AuthenticationTest` | register (role injection ignored), login/logout, suspension, password reset, address ownership & state validation |
| `Feature/Admin/AuthorizationTest` | guest/customer/staff/admin access matrix |
| `Feature/Inventory/InventoryServiceTest` | ledger, reasons, no negatives, reservations vs. overselling, commit/restore, bundles |
| `Feature/Pricing/PriceResolverTest` | scheduled windows, lowest-price-wins, rule targets, history + audit |
| `Feature/Catalog/StorefrontTest` | visibility, product page, structured data, search/filter/sort, Livewire shop, sitemap, headers, safe Markdown |
| `Feature/Admin/CatalogAdminTest` | product editor, duplicate SKUs, price audit, stock adjustment, scheduled sale, coupons, settings, staff restrictions |

| `Feature/Checkout/CartTest` | add/merge, stock caps, drafts, variant tampering, live prices, delivery by state & free threshold, coupons, guest→account merge |
| `Feature/Checkout/CheckoutPaymentTest` | order snapshot + reservation, idempotent token, overselling, Paystack initialize, no-keys state, callback verify, failed payment keeps cart, amount tampering → review, webhook signature + idempotency, concurrent confirmations, expiry, late payment |
| `Feature/Orders/OrderManagementTest` | fulfilment + emails, invalid transitions, cancel unpaid/paid, full & partial refunds, staff can't refund, Paystack refund failure, order page access, admin screens |

| `Feature/Loyalty/PointsTest` | sign-up points, purchase + first-order points once, guests, tier multiplier, full/partial refund reversal, negative balance, FIFO spend, expiry, switch-off, admin adjust (staff blocked) |
| `Feature/Loyalty/RewardsTest` | redeem → personal code, insufficient points, stock/per-customer/tier limits, code used at checkout, personal-only, free-product discount, code expiry, rewards page |
| `Feature/Loyalty/ReferralTest` | link visit + friend code, conversion, minimum order, self-referral by phone, refund reversal, guest attribution, admin reject, referral page |
| `Feature/Loyalty/QuizTest` | weighted scoring + tie, answer validation/tampering, guest flow with contact capture, API, admin builder |
| `Feature/Loyalty/AccountApiTest` | Sanctum token, me/orders/rewards/redeem/referrals, 401 without token |

| `Feature/AI/TryOnTest` | upload → result → get this look, upload validation, consent, failures (not counted), daily/IP limits, disabled/unconfigured/production states, budget cap, signed + owned image URLs, admin results-only, cleanup, saved/shared looks, cross-account access, colour board, purchase attribution, guest→account claim, Replicate webhook signature, OpenAI mapping, admin dashboard + settings |

| `Feature/Community/WallTest` | submit → review, validation, inactive colours, pending/daily limits + switch-off, private photos until approved, approval points once, reject with reason + reversal, featured ordering, colour filter + product/home sections, deletes (own/others/moderator), bulk approve + access, events, API |
| `Feature/Community/ChallengeTest` | join once + event, closed/upcoming/draft, purchase requirement, entry limit (rejections free a slot), challenge points once, voting rules, winner after close + protection, public pages + drafts, admin editor validation |

| `Feature/Creators/CreatorProgrammeTest` | apply + validation + re-apply rules, approval (code coupon, link, event, email, audit), rejection, staff blocked, own code refused, suspension, audited rate changes, open-redirect-proof links, encrypted bank details, API |
| `Feature/Creators/CreatorCommissionTest` | code sale maths (after discount, ex. delivery), link clicks (dedupe, session, cookie), account/cookie fallback + window, code beats link, self-referral, duplicate conversions, partial/full refund + cancel, hold period, payouts + minimum + bank details, clawbacks, cancelled payout, campaign boost, leaderboard, creator Wall posts |

| `Feature/Automation/CampaignEngineTest` | first-purchase coupon + email with merge fields, conditions, once-per-event idempotency, loop guard, caps/schedules, messages/audiences/free reward/webhook, creator milestone, guest events, marketing consent + unsubscribe, failing action isolation, admin builder + preview |
| `Feature/Automation/CrmTest` | outbox + signed delivery, dedupe, backoff/fail/retry, no-CRM mode, FluentCRM request, inbound webhook (signature, replay, tags, stale timestamp), access |
| `Feature/Automation/EmailTest` | welcome (+ switch-off), reward code, slow try-on email, email log + mail theme |
| `Feature/Admin/AnalyticsTest` | sales/refunds/AOV/units, buyers/first-time/repeat, series, products, previous period, filters, CSV export, access |

| `Feature/Hardening/RouteSweepTest` | every parameterless page × guest/customer/staff/admin: no 500s; admin pages follow the gate matrix automatically |
| `Feature/Hardening/HardeningTest` | security headers/CSP, HTTPS redirect + secure cookies in production, branded error pages without leaks, Livewire debug flag, log redaction, auth throttling, robots/sitemap |
| `Feature/Hardening/OpsTest` | doctor, backup contents (DB + media, no AI originals, no plain .env), **SQL dump restore round-trip**, AES-256 archives, off-site copy + retention, admin-only downloads, maintenance mode |
| `Feature/Hardening/SchedulerJobsTest` | everything the spec lists is scheduled, abandoned-bag campaign once, paid bags ignored, rollups equal live numbers, campaign housekeeping, responsive image renditions, catalogue cache invalidation |
| `Feature/Hardening/PerformanceBudgetTest` | query budgets for key pages on the seeded catalogue; hashed assets; no homepage video |
| `Feature/Hardening/MigrationsTest` | every migration rolls back and re-applies (rollback plan) |

Tests log to the `null` channel so test runs never pollute `storage/logs`.

AI uses `FakeImageProvider` with `ai.dispatch=sync`; set `FakeImageProvider::$forceFailure` or `$async` to simulate failures and webhooks.

`Tests\Concerns\PlacesPaidOrders` runs the real cart → order → confirmed-payment pipeline for loyalty tests.

Paystack is faked with `Tests\Concerns\FakesPaystack` (`Http::fake`); set `$this->paystackVerify[$reference]` or `$this->paystackRefundError` to simulate failures.

`Model::shouldBeStrict()` is on outside production, so lazy-loading (N+1) and missing-attribute bugs fail tests.
