166 lines
5.8 KiB
PHP
166 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Browser\Concerns;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Modules\Platform\app\Models\Company;
|
|
use Modules\Platform\app\Models\LicenseKey;
|
|
use Modules\Platform\app\Models\Payment;
|
|
use Modules\Platform\app\Models\PlatformPrice;
|
|
use Modules\Warehouse\app\Models\Warehouse;
|
|
|
|
trait InteractsWithWmsData
|
|
{
|
|
protected string $browserPassword = 'Password1!';
|
|
|
|
protected function platformAdminUser(array $overrides = []): User
|
|
{
|
|
$company = Company::query()->updateOrCreate(
|
|
['slug' => 'mpba-limited'],
|
|
[
|
|
'name' => 'MPBA Limited',
|
|
'status' => 'active',
|
|
'timezone' => 'Europe/London',
|
|
'is_system_company' => true,
|
|
'billing_email' => 'mark.gregory@mpba.co.uk',
|
|
],
|
|
);
|
|
|
|
return User::query()->updateOrCreate(
|
|
['email' => $overrides['email'] ?? 'platform.admin@example.test'],
|
|
[
|
|
'company_id' => $company->id,
|
|
'name' => $overrides['name'] ?? 'Platform Admin',
|
|
'password' => Hash::make($this->browserPassword),
|
|
'email_verified_at' => now(),
|
|
'is_platform_admin' => true,
|
|
'is_company_admin' => true,
|
|
'status' => 'active',
|
|
...$overrides,
|
|
],
|
|
);
|
|
}
|
|
|
|
protected function tenantCompany(array $overrides = []): Company
|
|
{
|
|
$company = Company::query()->updateOrCreate(
|
|
['slug' => $overrides['slug'] ?? 'test-company'],
|
|
[
|
|
'name' => $overrides['name'] ?? 'Test Company',
|
|
'status' => $overrides['status'] ?? 'active',
|
|
'timezone' => 'Europe/London',
|
|
'is_system_company' => false,
|
|
'billing_email' => $overrides['billing_email'] ?? 'billing@test-company.example',
|
|
...$overrides,
|
|
],
|
|
);
|
|
|
|
LicenseKey::query()->where('company_id', $company->id)->delete();
|
|
LicenseKey::issueFor($company, 'Browser Test Licence', 'enterprise', 250);
|
|
|
|
return $company->refresh();
|
|
}
|
|
|
|
protected function tenantUser(array $overrides = []): User
|
|
{
|
|
$company = $this->tenantCompany();
|
|
|
|
return User::query()->updateOrCreate(
|
|
['email' => $overrides['email'] ?? 'tenant.user@example.test'],
|
|
[
|
|
'company_id' => $company->id,
|
|
'name' => $overrides['name'] ?? 'Tenant User',
|
|
'password' => Hash::make($this->browserPassword),
|
|
'email_verified_at' => now(),
|
|
'is_platform_admin' => false,
|
|
'is_company_admin' => true,
|
|
'status' => 'active',
|
|
...$overrides,
|
|
],
|
|
);
|
|
}
|
|
|
|
protected function seedPlatformPrices(): void
|
|
{
|
|
foreach ([
|
|
['basic', 'Basic', 'Starter WMS access', 'Core warehouse management for small teams.', 4900, 49000, 10, false, true, ['2 warehouses', '10 users', 'Standard support']],
|
|
['advanced', 'Advanced', 'Growing WMS operations', 'More users, warehouses and automation controls.', 14900, 149000, 20, true, true, ['5 warehouses', '100 users', 'Advanced support']],
|
|
['pro', 'Pro', 'Professional WMS command centre', 'Full operational visibility for larger teams.', 29900, 299000, 30, false, true, ['15 warehouses', '1000 users', 'Priority support']],
|
|
] as [$code, $name, $strapline, $description, $monthly, $annual, $sortOrder, $featured, $active, $features]) {
|
|
PlatformPrice::query()->updateOrCreate(
|
|
['code' => $code],
|
|
[
|
|
'name' => $name,
|
|
'strapline' => $strapline,
|
|
'description' => $description,
|
|
'monthly_amount' => $monthly,
|
|
'annual_amount' => $annual,
|
|
'currency' => 'gbp',
|
|
'badge_label' => $featured ? 'Popular' : null,
|
|
'features' => $features,
|
|
'sort_order' => $sortOrder,
|
|
'is_featured' => $featured,
|
|
'is_active' => $active,
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
protected function seedWarehouse(?Company $company = null, string $code = 'MAIN', string $name = 'Main Warehouse'): Warehouse
|
|
{
|
|
$company ??= $this->tenantCompany();
|
|
|
|
$warehouse = Warehouse::query()->updateOrCreate(
|
|
[
|
|
'company_id' => $company->id,
|
|
'code' => $code,
|
|
],
|
|
[
|
|
'name' => $name,
|
|
'address' => 'Main Road',
|
|
'timezone' => 'Europe/London',
|
|
],
|
|
);
|
|
|
|
$warehouse->validationRules()->updateOrCreate(
|
|
[
|
|
'rule_key' => 'batch-required',
|
|
],
|
|
[
|
|
'name' => 'Require batch number',
|
|
'severity' => 'error',
|
|
'configuration' => [
|
|
'field' => 'batch_number',
|
|
],
|
|
],
|
|
);
|
|
|
|
return $warehouse->refresh();
|
|
}
|
|
|
|
protected function seedPlatformDashboardData(): void
|
|
{
|
|
$company = $this->tenantCompany([
|
|
'name' => 'Customer One',
|
|
'slug' => 'customer-one',
|
|
]);
|
|
|
|
$this->seedWarehouse($company);
|
|
$this->seedPlatformPrices();
|
|
|
|
Payment::query()->updateOrCreate(
|
|
['stripe_payment_intent_id' => 'pi_browser_paid'],
|
|
[
|
|
'company_id' => $company->id,
|
|
'amount' => 12345,
|
|
'currency' => 'gbp',
|
|
'status' => 'paid',
|
|
'description' => 'Browser test payment',
|
|
'paid_at' => now(),
|
|
'metadata' => ['source' => 'dusk'],
|
|
],
|
|
);
|
|
}
|
|
}
|