major update
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Modules;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ModulePlaceholderPageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* @return array<string, array{route:string, heading:string, expected:array<int,string>}>
|
||||
*/
|
||||
public static function modulePages(): array
|
||||
{
|
||||
return [
|
||||
'analytics' => ['route' => 'analytics.index', 'heading' => 'Analytics', 'expected' => ['KPI1 Bar', 'OTTC', 'Warehouse Performance']],
|
||||
'audit' => ['route' => 'audit.index', 'heading' => 'Audit', 'expected' => ['Audit Trail', 'User Activity', 'Stock Adjustments']],
|
||||
'carrier-management' => ['route' => 'carrier-management.index', 'heading' => 'Carrier Management', 'expected' => ['Carrier Master', 'Service Levels']],
|
||||
'configuration' => ['route' => 'configuration.index', 'heading' => 'Configuration', 'expected' => ['System Parameters', 'Reference Data']],
|
||||
'document-archive' => ['route' => 'document-archive.index', 'heading' => 'Document Archive', 'expected' => ['POD Archive', 'Document Lookup']],
|
||||
'inventory-management' => ['route' => 'inventory-management.index', 'heading' => 'Inventory Management', 'expected' => ['Stock Enquiry', 'Stock Adjustments']],
|
||||
'm3-integration' => ['route' => 'm3-integration.index', 'heading' => 'M3 Integration', 'expected' => ['Inbound Interfaces', 'Outbound Interfaces']],
|
||||
'replenishment' => ['route' => 'replenishment.index', 'heading' => 'Replenishment', 'expected' => ['Shortage Monitor', 'Replenishment Tasks']],
|
||||
'reporting' => ['route' => 'reporting.index', 'heading' => 'Reporting', 'expected' => ['Operational Reports', 'Export Packs']],
|
||||
'security' => ['route' => 'security.index', 'heading' => 'Security', 'expected' => ['Users', 'Roles', 'Permissions']],
|
||||
'sentinel-integration' => ['route' => 'sentinel-integration.index', 'heading' => 'Sentinel Integration', 'expected' => ['Sentinel Sync', 'Message Queue']],
|
||||
'shipping' => ['route' => 'shipping.index', 'heading' => 'Shipping', 'expected' => ['Open Shipments', 'Dispatch Exceptions']],
|
||||
'transportation' => ['route' => 'transportation.index', 'heading' => 'Transportation', 'expected' => ['Pending Truck Closure', 'Freight Terms']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider modulePages
|
||||
*
|
||||
* @param array<int,string> $expected
|
||||
*/
|
||||
public function test_module_placeholder_page_renders(string $route, string $heading, array $expected): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)->get(route($route));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee($heading);
|
||||
$response->assertSee('Replacement module');
|
||||
$response->assertSee('workbench');
|
||||
|
||||
foreach ($expected as $text) {
|
||||
$response->assertSee($text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider modulePages
|
||||
*
|
||||
* @param array<int,string> $expected
|
||||
*/
|
||||
public function test_module_placeholder_page_requires_authentication(string $route, string $heading, array $expected): void
|
||||
{
|
||||
$this->get(route($route))->assertRedirect(route('login'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Modules;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Platform\app\Models\Company;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PlatformAdminUiFlowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_platform_admin_can_view_and_manage_platform_records(): void
|
||||
{
|
||||
$admin = User::factory()->mpbaPlatformAdmin()->create();
|
||||
$company = Company::query()->create([
|
||||
'name' => 'Feature Tenant',
|
||||
'slug' => 'feature-tenant',
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
'is_system_company' => false,
|
||||
'billing_email' => 'billing@feature-tenant.example',
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)->get(route('platform.dashboard'))
|
||||
->assertOk()
|
||||
->assertSee('Platform administration')
|
||||
->assertSee('Feature Tenant');
|
||||
|
||||
$this->actingAs($admin)->post(route('platform.companies.store'), [
|
||||
'name' => 'Created Feature Co',
|
||||
'billing_email' => 'accounts@created-feature.example',
|
||||
'status' => 'active',
|
||||
])->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas('companies', [
|
||||
'slug' => 'created-feature-co',
|
||||
'billing_email' => 'accounts@created-feature.example',
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)->post(route('platform.licenses.store'), [
|
||||
'company_id' => $company->id,
|
||||
'label' => 'Feature Licence',
|
||||
'plan' => 'enterprise',
|
||||
'max_users' => 250,
|
||||
])->assertSessionHas('plain_license_key');
|
||||
|
||||
$this->assertDatabaseHas('license_keys', [
|
||||
'company_id' => $company->id,
|
||||
'label' => 'Feature Licence',
|
||||
'plan' => 'enterprise',
|
||||
'max_users' => 250,
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($admin)->post(route('platform.payments.store'), [
|
||||
'company_id' => $company->id,
|
||||
'amount' => 99900,
|
||||
'currency' => 'gbp',
|
||||
'status' => 'paid',
|
||||
'description' => 'Feature payment',
|
||||
])->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'company_id' => $company->id,
|
||||
'amount' => 99900,
|
||||
'currency' => 'gbp',
|
||||
'status' => 'paid',
|
||||
'description' => 'Feature payment',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_normal_user_cannot_access_platform_admin(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)->get(route('platform.dashboard'))->assertForbidden();
|
||||
$this->actingAs($user)->get(route('platform.companies.index'))->assertForbidden();
|
||||
$this->actingAs($user)->get(route('platform.licenses.index'))->assertForbidden();
|
||||
$this->actingAs($user)->get(route('platform.payments.index'))->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_guest_is_redirected_from_platform_admin(): void
|
||||
{
|
||||
$this->get(route('platform.dashboard'))->assertRedirect(route('login'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Modules;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Platform\app\Models\Company;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WarehouseUiFlowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_licensed_user_can_view_dashboard_warehouses_and_rules(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$warehouse = Warehouse::query()->create([
|
||||
'company_id' => $user->company_id,
|
||||
'code' => 'MAIN',
|
||||
'name' => 'Main Warehouse',
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
'settings' => [],
|
||||
]);
|
||||
|
||||
$this->actingAs($user)->get(route('dashboard'))
|
||||
->assertOk()
|
||||
->assertSee($user->company->name)
|
||||
->assertSee('Main Warehouse');
|
||||
|
||||
$this->actingAs($user)->get(route('warehouses.index'))
|
||||
->assertOk()
|
||||
->assertSee('Warehouses')
|
||||
->assertSee('MAIN')
|
||||
->assertSee('Main Warehouse');
|
||||
|
||||
$this->actingAs($user)->post(route('warehouse-rules.store'), [
|
||||
'warehouse_id' => $warehouse->id,
|
||||
'name' => 'Location required',
|
||||
'rule_key' => 'stock.location.required',
|
||||
'severity' => 'error',
|
||||
])->assertRedirect();
|
||||
|
||||
$this->actingAs($user)->get(route('warehouse-rules.index'))
|
||||
->assertOk()
|
||||
->assertSee('Warehouse validation rules')
|
||||
->assertSee('Location required')
|
||||
->assertSee('stock.location.required');
|
||||
}
|
||||
|
||||
public function test_user_can_create_warehouse_for_own_tenant_only(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)->post(route('warehouses.store'), [
|
||||
'code' => 'PICK',
|
||||
'name' => 'Picking Warehouse',
|
||||
'status' => 'active',
|
||||
'address' => 'Rack 1',
|
||||
])->assertRedirect();
|
||||
|
||||
$this->assertDatabaseHas('warehouses', [
|
||||
'company_id' => $user->company_id,
|
||||
'code' => 'PICK',
|
||||
'name' => 'Picking Warehouse',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_unlicensed_tenant_gets_payment_required(): void
|
||||
{
|
||||
$company = Company::query()->create([
|
||||
'name' => 'Unlicensed Co',
|
||||
'slug' => 'unlicensed-co',
|
||||
'status' => 'active',
|
||||
'timezone' => 'Europe/London',
|
||||
'is_system_company' => false,
|
||||
]);
|
||||
|
||||
$user = User::factory()->create(['company_id' => $company->id]);
|
||||
|
||||
$this->actingAs($user)->get(route('dashboard'))->assertStatus(402);
|
||||
$this->actingAs($user)->get(route('warehouses.index'))->assertStatus(402);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user