Skip to content

refactor: split testing seeders into complete store and network fixtures - #98

Merged
roncodes merged 2 commits into
release/v0.4.21from
refactor/testing-seeders
Sep 4, 2026
Merged

refactor: split testing seeders into complete store and network fixtures#98
roncodes merged 2 commits into
release/v0.4.21from
refactor/testing-seeders

Conversation

@roncodes

@roncodes roncodes commented Sep 3, 2026

Copy link
Copy Markdown
Member

Summary

Refactors the Storefront testing seeders into two complete, idempotent fixtures built on a shared concern:

  • StoreSeeder seeds one complete standalone store: order config, store location with weekly hours, sandbox Stripe gateway, 3 product categories, 10 products (variants, addons, sale/unavailable/draft cases), a published catalog, 20 customers, an open cart, a pending checkout, 30 captured orders spread over the last month (cash and Stripe, delivery and pickup, seven lifecycle statuses), and reviews.
  • NetworkSeeder seeds a complete marketplace: a network with its own sandbox Stripe gateway, 3 network categories, 5 member stores (grocer, restaurant, wet market, pharmacy, and an uncategorised florist) each built the same way, and 46 network-tagged orders across them.

TestingSeeder runs both. Each seeder tags and purges only its own fixtures, and still cleans up data from the previous storefront-testing seeders.

Problems in the old seeders this fixes:

  • No gateway, store location, or hours were ever seeded, so Stripe checkout and delivery quoting could not be exercised.
  • Core product categories were never purged, so every run added duplicates.
  • Addon categories had no owner_uuid, so the console never listed them for the store.
  • Every order ended up created because FleetOps resets the status column when the tracking number is generated; statuses are now re-applied after creation.
  • All records shared one timestamp; orders now span the last 30 days for dashboards and analytics.
  • Column existence was checked with a schema query per attribute per record; listings are now cached per table.

Also fixes three Network model defects found while seeding:

  • Network::setOptionsAttribute stored a raw array (bypassing the JSON cast), so any network save with options failed. It now encodes JSON like Store.
  • Network::categories() filtered on for = 'network_category', a value nothing writes, so the relation was always empty. It now matches the storefront_network categories the console and v1 API use.
  • Network::createCategory derived the owner type from network:storefront, which resolves to a nonexistent class. It now resolves to the Network model.

Tests that had locked in the broken behaviour were updated, and the category behaviour test now asserts the relation and owner type.

Related Issue

N/A

Type of Change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Test
  • Chore

Implementation Notes

  • Concerns/SeedsStorefrontFixtures.php holds all builders (store, location/hours, gateway, categories, products, variants, addons, catalog, network, network categories, customers, carts, checkouts, orders, reviews) plus one purge routine covering both databases. The seeders are declarative definition arrays on top of it.
  • Concerns/SeedsTestingData.php now exposes seedName() per seeder (storefront-testing-store / storefront-testing-network), matches legacy storefront-testing records when purging, caches table column listings, and wraps purges in withoutForeignKeyConstraints().
  • Stripe keys come from SEED_STRIPE_SECRET_KEY / SEED_STRIPE_PUBLISHABLE_KEY; otherwise obvious sk_test_…placeholder values are stored so the gateway is selectable and the missing-secret path can be tested. SEED_COMPANY_UUID / SEED_COMPANY_PUBLIC_ID pick the company as before.
  • Runs print the seeded store/network public ids and API keys so testers can hit the storefront API immediately.

Validation

  • Tests
  • Lint
  • Build
  • Manual validation

Command output / summary:

composer test:lint   -> Found 0 of 249 files that can be fixed
pest (server/tests)  -> Tests: 440 passed (2782 assertions)

TestingSeeder run twice against the dev database (application container):
  StoreSeeder   -> 1 store, 10 products, 1 Stripe gateway, 7 store hours, 32 carts, 31 checkouts (15 with Stripe intents), 30 orders
  NetworkSeeder -> 1 network, 3 network categories, 5 stores (1 uncategorised), 21 products, 4 gateways, 56 carts, 51 checkouts, 46 orders
  Second run produced identical counts, no duplicate order/contact keys, no legacy leftovers.
  Order statuses: created/preparing/ready/dispatched/started/completed/pickup_ready, dates 2026-08-05 .. 2026-09-02.

Note: composer test:types currently fails locally because phpstan.neon.dist points at src rather than server/src (pre-existing); the seeders directory is not in its scope either way.

Documentation Impact

  • No documentation changes needed
  • Documentation updated in fleetbase/fleetbase.io
  • Documentation needed but not included

API Reference Impact

  • No API reference changes needed
  • Updated fleetbase/postman
  • API reference updates required but not included

API reference notes:

None. Seeders are development tooling; the Network options change only affects persistence of an already-documented attribute.

Documentation Notes

None.

Risk

  • Seeders only touch records tagged with their seed name (plus legacy storefront-testing tags), so re-running against a developer database is safe. They are not meant for production.
  • Network::setOptionsAttribute now persists a JSON string. Reads are unchanged because the options attribute is cast with Json::class; any code that inspected getAttributes()['options'] directly and expected an array would need updating (only the two tests did).
  • Network::categories() will now return rows where it previously returned none. Existing categories created through createCategory carry the old Fleetbase\Network\Models\Storefront owner type string; nothing filters on that column, so they keep working, but a data cleanup could normalise it.

Screenshots / Recordings

N/A

Replace CatalogAndProductsSeeder and CheckoutOrdersSeeder with two
declarative seeders built on a shared fixtures concern:

- StoreSeeder seeds one complete store: order config, location with
  weekly hours, sandbox Stripe gateway, categories, products with
  variants and addons, published catalog, customers, an open cart, a
  pending checkout, a month of cash and Stripe orders across statuses,
  and reviews.
- NetworkSeeder seeds a marketplace: network gateway, network
  categories, five member stores (one uncategorised) and network-tagged
  orders across them.

Fixes carried over from the old seeders: core product categories are
now purged between runs, addon categories carry their store owner so
they show in the console, order statuses survive the FleetOps tracking
reset, orders are spread over the last month, and schema column lookups
are cached per table. Each seeder tags and purges only its own fixtures
while still cleaning up legacy storefront-testing data.

Also fix Network::setOptionsAttribute, which stored a raw array and made
any network save with options fail; it now encodes JSON like Store.
@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7f0ba99) to head (b368230).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #98   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity      1775      1775           
===========================================
  Files            135       135           
  Lines           7785      7785           
===========================================
  Hits            7785      7785           
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…etwork

Network::categories() filtered on 'network_category', a value nothing
writes, so the relation was always empty; it now matches the
'storefront_network' categories the console and v1 API use.
Network::createCategory set the owner type from 'network:storefront',
which resolves to a nonexistent class; it now resolves to the Network
model. Covered by the network category behaviour test.
@roncodes roncodes mentioned this pull request Sep 4, 2026
@roncodes
roncodes changed the base branch from main to release/v0.4.21 September 4, 2026 10:40
roncodes added a commit that referenced this pull request Sep 4, 2026
Cuts the patch release carrying the QPay authentication fix (#99) and the
network model repairs and testing seeder split (#98).

The release/v* workflow gate is deliberately NOT changed here — #97 owns
that, with fleetbase/fleetbase#641 behind it. Both must land before this
branch is merged, or the tag job either skips (old gate) or is refused by
the reusable workflow (gate updated, reusable workflow not yet).
@roncodes
roncodes merged commit b49c535 into release/v0.4.21 Sep 4, 2026
11 checks passed
@roncodes
roncodes deleted the refactor/testing-seeders branch September 4, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant