74 lines
3.8 KiB
PHP
74 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Company\Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Modules\Company\Models\Company;
|
|
use Modules\Countries\Models\Country;
|
|
use Modules\Warehouse\app\Models\Warehouse;
|
|
use Tests\TestCase;
|
|
|
|
class CompanyAdministrationRoutesTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_platform_admin_can_update_company_address_create_division_and_assign_director(): void
|
|
{
|
|
$system = Company::create(['name' => 'MPBA Limited', 'is_system_company' => true]);
|
|
$tenant = Company::create(['name' => 'Sentinel', 'billing_email' => 'sentinel@example.test']);
|
|
$country = Country::create(['alpha2' => 'GB', 'alpha3' => 'GBR', 'numeric' => '826', 'name' => 'United Kingdom', 'is_active' => true]);
|
|
$admin = User::create(['company_id' => $system->id, 'name' => 'Platform Admin', 'email' => 'admin@example.test', 'password' => 'password', 'is_platform_admin' => true]);
|
|
$director = User::create(['company_id' => $tenant->id, 'name' => 'Division Director', 'email' => 'director@example.test', 'password' => 'password']);
|
|
|
|
$this->actingAs($admin)->put(route('platform.companies.address.update', $tenant), [
|
|
'line_1' => '1 Example Street',
|
|
'locality' => 'London',
|
|
'postal_code' => 'SW1A 1AA',
|
|
'country_id' => $country->id,
|
|
])->assertRedirect(route('platform.companies.show', $tenant));
|
|
|
|
$this->actingAs($admin)->post(route('platform.companies.divisions.store', $tenant), [
|
|
'name' => 'Northern Operations',
|
|
'code' => 'NORTH',
|
|
'status' => 'active',
|
|
])->assertRedirect(route('platform.companies.show', $tenant));
|
|
|
|
$division = $tenant->divisions()->where('code', 'NORTH')->firstOrFail();
|
|
|
|
$this->actingAs($admin)->post(route('platform.companies.director-assignments.store', $tenant), [
|
|
'user_id' => $director->id,
|
|
'coverage_type' => 'division',
|
|
'company_division_id' => $division->id,
|
|
])->assertRedirect(route('platform.companies.show', $tenant));
|
|
|
|
$this->assertDatabaseHas('company_addresses', ['line_1' => '1 Example Street', 'country_id' => $country->id]);
|
|
$this->assertDatabaseHas('company_divisions', ['company_id' => $tenant->id, 'code' => 'NORTH']);
|
|
$this->assertDatabaseHas('company_director_assignments', ['company_id' => $tenant->id, 'company_division_id' => $division->id, 'user_id' => $director->id]);
|
|
}
|
|
public function test_platform_admin_can_update_warehouse_address(): void
|
|
{
|
|
$system = Company::create(['name' => 'MPBA Limited', 'is_system_company' => true]);
|
|
$tenant = Company::create(['name' => 'Sentinel', 'billing_email' => 'sentinel@example.test']);
|
|
$country = Country::create(['alpha2' => 'GB', 'alpha3' => 'GBR', 'numeric' => '826', 'name' => 'United Kingdom', 'is_active' => true]);
|
|
$warehouse = Warehouse::create(['company_id' => $tenant->id, 'code' => 'MAIN', 'name' => 'Main Warehouse']);
|
|
$admin = User::create(['company_id' => $system->id, 'name' => 'Platform Admin', 'email' => 'warehouse-admin@example.test', 'password' => 'password', 'is_platform_admin' => true]);
|
|
|
|
$this->actingAs($admin)->put(route('platform.companies.warehouses.address.update', [$tenant, $warehouse]), [
|
|
'label' => 'Warehouse address',
|
|
'line_1' => '100 Distribution Park',
|
|
'locality' => 'Birmingham',
|
|
'postal_code' => 'B1 1AA',
|
|
'country_id' => $country->id,
|
|
])->assertRedirect(route('platform.companies.show', $tenant));
|
|
|
|
$this->assertDatabaseHas('company_addresses', [
|
|
'addressable_type' => Warehouse::class,
|
|
'addressable_id' => $warehouse->id,
|
|
'line_1' => '100 Distribution Park',
|
|
'country_id' => $country->id,
|
|
]);
|
|
}
|
|
|
|
}
|