89 lines
3.0 KiB
PHP
89 lines
3.0 KiB
PHP
<?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'));
|
|
}
|
|
}
|