Files
WMS/tests/Browser/Concerns/CreatesWmsBrowserData.php
T
2026-06-10 14:56:43 +01:00

99 lines
3.7 KiB
PHP

<?php
namespace Tests\Browser\Concerns;
use App\Models\User;
use Modules\Platform\app\Models\Company;
use Modules\Platform\app\Models\LicenseKey;
use Modules\Platform\app\Models\Payment;
use Modules\Warehouse\app\Models\Warehouse;
use Modules\Warehouse\app\Models\WarehouseValidationRule;
trait CreatesWmsBrowserData
{
/**
* Create a normal tenant user with an active licence.
*/
protected function createLicensedUser(array $attributes = []): User
{
return User::factory()->create($attributes);
}
/**
* Create an MPBA platform administrator attached to the system tenant.
*/
protected function createPlatformAdmin(array $attributes = []): User
{
return User::factory()->mpbaPlatformAdmin()->create($attributes);
}
/**
* Create a warehouse for the user's company tenant.
*/
protected function createWarehouseFor(User $user, array $attributes = []): Warehouse
{
return Warehouse::query()->create([
'company_id' => $user->company_id,
'code' => $attributes['code'] ?? 'MAIN',
'name' => $attributes['name'] ?? 'Main Warehouse',
'status' => $attributes['status'] ?? 'active',
'address' => $attributes['address'] ?? 'Unit 1, Test Estate',
'timezone' => $attributes['timezone'] ?? 'Europe/London',
'settings' => $attributes['settings'] ?? [],
]);
}
/**
* Create a validation rule for a warehouse.
*/
protected function createWarehouseRule(Warehouse $warehouse, array $attributes = []): WarehouseValidationRule
{
return WarehouseValidationRule::query()->create([
'warehouse_id' => $warehouse->id,
'name' => $attributes['name'] ?? 'Location required',
'rule_key' => $attributes['rule_key'] ?? 'stock.location.required',
'severity' => $attributes['severity'] ?? 'error',
'is_active' => $attributes['is_active'] ?? true,
'configuration' => $attributes['configuration'] ?? ['required' => true],
]);
}
/**
* Create a non-system tenant company for admin screens.
*/
protected function createTenantCompany(array $attributes = []): Company
{
$company = Company::query()->create([
'name' => $attributes['name'] ?? 'Browser Tenant Ltd',
'slug' => $attributes['slug'] ?? 'browser-tenant-ltd',
'status' => $attributes['status'] ?? 'active',
'timezone' => $attributes['timezone'] ?? 'Europe/London',
'is_system_company' => $attributes['is_system_company'] ?? false,
'billing_email' => $attributes['billing_email'] ?? 'billing@browser-tenant.example',
'settings' => $attributes['settings'] ?? [],
]);
LicenseKey::issueFor($company, 'Browser Test Licence', 'enterprise', 100);
return $company;
}
/**
* Create a payment row for platform payment tables.
*/
protected function createPaymentFor(Company $company, array $attributes = []): Payment
{
return Payment::query()->create([
'company_id' => $company->id,
'stripe_payment_intent_id' => $attributes['stripe_payment_intent_id'] ?? null,
'stripe_invoice_id' => $attributes['stripe_invoice_id'] ?? null,
'amount' => $attributes['amount'] ?? 129900,
'currency' => $attributes['currency'] ?? 'gbp',
'status' => $attributes['status'] ?? 'paid',
'description' => $attributes['description'] ?? 'Annual platform licence',
'paid_at' => $attributes['paid_at'] ?? now(),
'metadata' => $attributes['metadata'] ?? ['source' => 'browser_test'],
]);
}
}