fixed tests
This commit is contained in:
@@ -4,16 +4,23 @@ namespace Tests\Browser\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
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;
|
||||
use Modules\Warehouse\app\Models\WarehouseValidationRule;
|
||||
|
||||
trait InteractsWithWmsData
|
||||
{
|
||||
protected string $browserPassword = '987400Kmh';
|
||||
|
||||
/**
|
||||
* Create or update the MPBA platform administrator used by browser tests.
|
||||
*
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
protected function platformAdminUser(array $overrides = []): User
|
||||
{
|
||||
$company = Company::query()->updateOrCreate(
|
||||
@@ -27,8 +34,11 @@ trait InteractsWithWmsData
|
||||
],
|
||||
);
|
||||
|
||||
$email = $overrides['email'] ?? 'platform.admin@example.test';
|
||||
unset($overrides['email']);
|
||||
|
||||
return User::query()->updateOrCreate(
|
||||
['email' => $overrides['email'] ?? 'platform.admin@example.test'],
|
||||
['email' => $email],
|
||||
[
|
||||
'company_id' => $company->id,
|
||||
'name' => $overrides['name'] ?? 'Platform Admin',
|
||||
@@ -42,10 +52,16 @@ trait InteractsWithWmsData
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
protected function tenantCompany(array $overrides = []): Company
|
||||
{
|
||||
$slug = $overrides['slug'] ?? 'test-company';
|
||||
unset($overrides['slug']);
|
||||
|
||||
$company = Company::query()->updateOrCreate(
|
||||
['slug' => $overrides['slug'] ?? 'test-company'],
|
||||
['slug' => $slug],
|
||||
[
|
||||
'name' => $overrides['name'] ?? 'Test Company',
|
||||
'status' => $overrides['status'] ?? 'active',
|
||||
@@ -62,12 +78,19 @@ trait InteractsWithWmsData
|
||||
return $company->refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $overrides
|
||||
*/
|
||||
protected function tenantUser(array $overrides = []): User
|
||||
{
|
||||
$company = $this->tenantCompany();
|
||||
$company = $overrides['company'] ?? $this->tenantCompany();
|
||||
unset($overrides['company']);
|
||||
|
||||
$email = $overrides['email'] ?? 'tenant.user@example.test';
|
||||
unset($overrides['email']);
|
||||
|
||||
return User::query()->updateOrCreate(
|
||||
['email' => $overrides['email'] ?? 'tenant.user@example.test'],
|
||||
['email' => $email],
|
||||
[
|
||||
'company_id' => $company->id,
|
||||
'name' => $overrides['name'] ?? 'Tenant User',
|
||||
@@ -90,19 +113,7 @@ trait InteractsWithWmsData
|
||||
] 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,
|
||||
],
|
||||
$this->platformPriceAttributes($name, $strapline, $description, $monthly, $annual, $sortOrder, $featured, $active, $features),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -116,25 +127,10 @@ trait InteractsWithWmsData
|
||||
'company_id' => $company->id,
|
||||
'code' => $code,
|
||||
],
|
||||
[
|
||||
'name' => $name,
|
||||
'address' => 'Main Road',
|
||||
'timezone' => 'Europe/London',
|
||||
],
|
||||
$this->warehouseAttributes($name),
|
||||
);
|
||||
|
||||
$warehouse->validationRules()->updateOrCreate(
|
||||
[
|
||||
'rule_key' => 'batch-required',
|
||||
],
|
||||
[
|
||||
'name' => 'Require batch number',
|
||||
'severity' => 'error',
|
||||
'configuration' => [
|
||||
'field' => 'batch_number',
|
||||
],
|
||||
],
|
||||
);
|
||||
$this->seedWarehouseValidationRule($warehouse, 'Require batch number', 'batch-required');
|
||||
|
||||
return $warehouse->refresh();
|
||||
}
|
||||
@@ -162,4 +158,114 @@ trait InteractsWithWmsData
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $features
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function platformPriceAttributes(
|
||||
string $name,
|
||||
string $strapline,
|
||||
string $description,
|
||||
int $monthly,
|
||||
int $annual,
|
||||
int $sortOrder,
|
||||
bool $featured,
|
||||
bool $active,
|
||||
array $features,
|
||||
): array {
|
||||
$attributes = [
|
||||
'name' => $name,
|
||||
'strapline' => $strapline,
|
||||
'description' => $description,
|
||||
'monthly_amount' => $monthly,
|
||||
'currency' => 'gbp',
|
||||
'badge_label' => $featured ? 'Popular' : null,
|
||||
'features' => $features,
|
||||
'sort_order' => $sortOrder,
|
||||
'is_featured' => $featured,
|
||||
];
|
||||
|
||||
if (Schema::hasColumn('platform_prices', 'annual_amount')) {
|
||||
$attributes['annual_amount'] = $annual;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('platform_prices', 'yearly_amount')) {
|
||||
$attributes['yearly_amount'] = $annual;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('platform_prices', 'is_active')) {
|
||||
$attributes['is_active'] = $active;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('platform_prices', 'active')) {
|
||||
$attributes['active'] = $active;
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function warehouseAttributes(string $name): array
|
||||
{
|
||||
$attributes = [
|
||||
'name' => $name,
|
||||
'timezone' => 'Europe/London',
|
||||
];
|
||||
|
||||
if (Schema::hasColumn('warehouses', 'address')) {
|
||||
$attributes['address'] = 'Main Road';
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouses', 'status')) {
|
||||
$attributes['status'] = 'active';
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
private function seedWarehouseValidationRule(Warehouse $warehouse, string $name, string $key): void
|
||||
{
|
||||
$attributes = [
|
||||
'warehouse_id' => $warehouse->id,
|
||||
];
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'company_id')) {
|
||||
$attributes['company_id'] = $warehouse->company_id;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'rule_key')) {
|
||||
$attributes['rule_key'] = $key;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'key')) {
|
||||
$attributes['key'] = $key;
|
||||
}
|
||||
|
||||
$values = ['name' => $name];
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'severity')) {
|
||||
$values['severity'] = 'error';
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'rule_type')) {
|
||||
$values['rule_type'] = 'validation';
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'value')) {
|
||||
$values['value'] = 'required';
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'configuration')) {
|
||||
$values['configuration'] = ['field' => 'batch_number'];
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('warehouse_validation_rules', 'is_active')) {
|
||||
$values['is_active'] = true;
|
||||
}
|
||||
|
||||
WarehouseValidationRule::query()->updateOrCreate($attributes, $values);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user