added complex address and devisions to company
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Company\Tests\Browser;
|
||||
|
||||
use App\Models\User;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Countries\Models\Country;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class CompanyAdministrationBrowserTest extends DuskTestCase
|
||||
{
|
||||
public function test_platform_admin_can_see_company_address_divisions_and_director_sections(): void
|
||||
{
|
||||
$system = Company::query()->firstOrCreate(['slug' => 'mpba-limited'], ['name' => 'MPBA Limited', 'is_system_company' => true, 'status' => 'active']);
|
||||
$tenant = Company::query()->firstOrCreate(['slug' => 'sentinel'], ['name' => 'Sentinel', 'status' => 'active']);
|
||||
Country::query()->firstOrCreate(['alpha2' => 'GB'], ['alpha3' => 'GBR', 'numeric' => '826', 'name' => 'United Kingdom', 'is_active' => true]);
|
||||
$admin = User::query()->firstOrCreate(['email' => 'company-admin-browser@example.test'], [
|
||||
'company_id' => $system->id,
|
||||
'name' => 'Company Browser Admin',
|
||||
'password' => bcrypt('password'),
|
||||
'is_platform_admin' => true,
|
||||
'status' => 'active',
|
||||
]);
|
||||
|
||||
$this->browse(function (Browser $browser) use ($admin, $tenant): void {
|
||||
$browser->loginAs($admin)
|
||||
->visitRoute('platform.companies.show', $tenant)
|
||||
->assertSee('Company address')
|
||||
->assertSee('Create division')
|
||||
->assertSee('Director coverage')
|
||||
->assertSee('Warehouse division and address alignment')
|
||||
->assertSee('Divisions');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Company\Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Modules\Company\Models\Company;
|
||||
use Modules\Company\Models\CompanyAddress;
|
||||
use Modules\Company\Models\CompanyDirectorAssignment;
|
||||
use Modules\Company\Models\CompanyDivision;
|
||||
use Modules\Countries\Models\Country;
|
||||
use Modules\Warehouse\app\Models\Warehouse;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CompanyStructureTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_company_has_one_editable_country_backed_address(): void
|
||||
{
|
||||
$company = Company::create(['name' => 'Abbott Logistics Limited', 'billing_email' => 'billing@abbott.example']);
|
||||
$country = Country::create(['alpha2' => 'GB', 'alpha3' => 'GBR', 'numeric' => '826', 'name' => 'United Kingdom', 'is_active' => true]);
|
||||
|
||||
$company->address()->create([
|
||||
'line_1' => '1 Warehouse Way',
|
||||
'locality' => 'London',
|
||||
'postal_code' => 'SW1A 1AA',
|
||||
'country_id' => $country->id,
|
||||
]);
|
||||
|
||||
$company->address()->update(['line_1' => '2 Warehouse Way']);
|
||||
|
||||
$this->assertSame(1, CompanyAddress::count());
|
||||
$this->assertSame('2 Warehouse Way', $company->fresh()->address->line_1);
|
||||
$this->assertSame('United Kingdom', $company->fresh()->address->country->name);
|
||||
}
|
||||
|
||||
public function test_company_division_has_address_users_directors_and_optional_warehouses(): void
|
||||
{
|
||||
$company = Company::create(['name' => 'Sentinel', 'billing_email' => 'sentinel@example.test']);
|
||||
$country = Country::create(['alpha2' => 'GB', 'alpha3' => 'GBR', 'numeric' => '826', 'name' => 'United Kingdom', 'is_active' => true]);
|
||||
$user = User::create(['company_id' => $company->id, 'name' => 'Jane Director', 'email' => 'jane@example.test', 'password' => 'password']);
|
||||
$division = $company->divisions()->create(['name' => 'North Operations', 'code' => 'NORTH']);
|
||||
$warehouse = Warehouse::create(['company_id' => $company->id, 'division_id' => $division->id, 'code' => 'NTH', 'name' => 'North DC']);
|
||||
|
||||
$division->address()->create([
|
||||
'label' => 'Operating address',
|
||||
'line_1' => 'North Road',
|
||||
'locality' => 'Manchester',
|
||||
'country_id' => $country->id,
|
||||
]);
|
||||
$division->users()->attach($user->id, ['company_id' => $company->id, 'role' => 'director', 'is_director' => true]);
|
||||
CompanyDirectorAssignment::create(['company_id' => $company->id, 'company_division_id' => $division->id, 'user_id' => $user->id, 'coverage_type' => 'division']);
|
||||
|
||||
$this->assertTrue($company->fresh()->divisions()->exists());
|
||||
$this->assertSame('North Operations', $warehouse->fresh()->division->name);
|
||||
$this->assertSame('Manchester', $division->fresh()->address->locality);
|
||||
$this->assertTrue($user->fresh()->divisions()->whereKey($division->id)->exists());
|
||||
$this->assertTrue($user->fresh()->directorAssignments()->where('company_division_id', $division->id)->exists());
|
||||
}
|
||||
|
||||
public function test_warehouse_can_remain_at_company_level_without_division(): void
|
||||
{
|
||||
$company = Company::create(['name' => 'Company Level Warehousing']);
|
||||
$warehouse = Warehouse::create(['company_id' => $company->id, 'code' => 'MAIN', 'name' => 'Main Warehouse']);
|
||||
|
||||
$this->assertNull($warehouse->division_id);
|
||||
$this->assertSame('Company Level Warehousing', $warehouse->company->name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user