149 lines
4.3 KiB
PHP
149 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\App;
|
|
use App\Models\Onboarding;
|
|
use App\Models\Role;
|
|
use App\Models\Setting;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class OnboardingAndOffboardingTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->withoutMiddleware();
|
|
}
|
|
|
|
public function test_admin_can_toggle_onboarding_module_on_and_off(): void
|
|
{
|
|
$admin = User::create([
|
|
'name' => 'Admin User',
|
|
'email' => 'admin@company.com',
|
|
'role' => 'admin',
|
|
]);
|
|
|
|
$this->actingAs($admin)
|
|
->post(route('admin.settings.onboarding-toggle'), [
|
|
'onboarding_enabled' => '0',
|
|
])
|
|
->assertRedirect(route('admin.dashboard'));
|
|
|
|
$this->assertEquals('0', Setting::get('onboarding_enabled'));
|
|
|
|
$this->actingAs($admin)
|
|
->post(route('admin.settings.onboarding-toggle'), [
|
|
'onboarding_enabled' => '1',
|
|
])
|
|
->assertRedirect(route('admin.dashboard'));
|
|
|
|
$this->assertEquals('1', Setting::get('onboarding_enabled'));
|
|
}
|
|
|
|
public function test_hr_role_or_authorized_user_can_create_candidate_onboarding(): void
|
|
{
|
|
$hrRole = Role::create([
|
|
'name' => 'HR Manager',
|
|
'can_manage_onboarding' => true,
|
|
]);
|
|
|
|
$hrUser = User::create([
|
|
'name' => 'Jane HR',
|
|
'email' => 'hr@company.com',
|
|
'role' => 'user',
|
|
]);
|
|
$hrUser->roles()->attach($hrRole->id);
|
|
|
|
$app = App::create([
|
|
'name' => 'Convex CRM',
|
|
'url' => 'https://convexcrm.com',
|
|
]);
|
|
|
|
$response = $this->actingAs($hrUser)
|
|
->post(route('onboarding.store'), [
|
|
'name' => 'Alex Intern',
|
|
'email' => 'alex.intern@company.com',
|
|
'type' => 'intern',
|
|
'department' => 'Engineering',
|
|
'assigned_apps' => [$app->id],
|
|
]);
|
|
|
|
$response->assertRedirect(route('onboarding.index'));
|
|
|
|
$this->assertDatabaseHas('onboardings', [
|
|
'name' => 'Alex Intern',
|
|
'email' => 'alex.intern@company.com',
|
|
'type' => 'intern',
|
|
'status' => 'preboarding',
|
|
]);
|
|
}
|
|
|
|
public function test_day_1_activation_provisions_account_and_sso_access(): void
|
|
{
|
|
$admin = User::create([
|
|
'name' => 'System Admin',
|
|
'email' => 'sysadmin@company.com',
|
|
'role' => 'admin',
|
|
]);
|
|
|
|
$app = App::create([
|
|
'name' => 'GitLab',
|
|
'url' => 'https://gitlab.com',
|
|
]);
|
|
|
|
$ob = Onboarding::create([
|
|
'name' => 'David Candidate',
|
|
'email' => 'david@company.com',
|
|
'type' => 'candidate',
|
|
'status' => 'preboarding',
|
|
'assigned_apps' => [$app->id],
|
|
'created_by' => $admin->id,
|
|
]);
|
|
|
|
$this->actingAs($admin)
|
|
->post(route('onboarding.activate', $ob->id))
|
|
->assertRedirect(route('onboarding.index'));
|
|
|
|
$ob->refresh();
|
|
$this->assertEquals('active', $ob->status);
|
|
$this->assertNotNull($ob->user_id);
|
|
|
|
$activatedUser = User::find($ob->user_id);
|
|
$this->assertEquals('david@company.com', $activatedUser->email);
|
|
$this->assertTrue($activatedUser->authorizedApps()->pluck('id')->contains($app->id));
|
|
}
|
|
|
|
public function test_1_click_offboarding_blocks_account_and_revokes_access(): void
|
|
{
|
|
$admin = User::create([
|
|
'name' => 'System Admin',
|
|
'email' => 'sysadmin@company.com',
|
|
'role' => 'admin',
|
|
]);
|
|
|
|
$employee = User::create([
|
|
'name' => 'John Leaver',
|
|
'email' => 'john.leaver@company.com',
|
|
'role' => 'user',
|
|
'is_blocked' => false,
|
|
]);
|
|
|
|
$this->actingAs($admin)
|
|
->post(route('onboarding.offboard', $employee->id))
|
|
->assertRedirect(route('onboarding.index'));
|
|
|
|
$employee->refresh();
|
|
$this->assertTrue((bool) $employee->is_blocked);
|
|
|
|
$this->assertDatabaseHas('onboardings', [
|
|
'user_id' => $employee->id,
|
|
'status' => 'offboarded',
|
|
]);
|
|
}
|
|
}
|