54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\App\Http\Controllers\Bo;
|
|
|
|
use App\Jobs\FetchAndUpsertArcadiaEmployees;
|
|
use App\Models\User;
|
|
use Domain\Enums\UserRole;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Queue;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
use function Pest\Laravel\post;
|
|
|
|
describe('EmployeesController', function (): void {
|
|
beforeEach(function (): void {
|
|
// GIVEN
|
|
$user = User::factory()->createOne(['role' => UserRole::SuperAdmin]);
|
|
actingAs($user, 'backend');
|
|
});
|
|
|
|
it('forbids launching employee sync job while EmployeePolicy is disabled', function (): void {
|
|
// WHEN
|
|
$response = post('/bo/settings/employees/sync');
|
|
|
|
// THEN
|
|
$response->assertForbidden();
|
|
});
|
|
|
|
it('can launch employee sync job', function (): void {
|
|
// GIVEN
|
|
Queue::fake();
|
|
|
|
// WHEN
|
|
$response = post('/bo/settings/employees/sync');
|
|
|
|
// THEN
|
|
$response->assertSessionHasNoErrors();
|
|
$response->assertRedirect(route('bo.dashboard'));
|
|
Queue::assertPushed(FetchAndUpsertArcadiaEmployees::class);
|
|
})->skip('Arcadia API is offline; SettingPolicy and EmployeePolicy currently return false.');
|
|
|
|
it('redirects unauthenticated users to login', function (): void {
|
|
// GIVEN
|
|
Auth::guard('backend')->logout();
|
|
|
|
// WHEN
|
|
$response = post('/bo/settings/employees/sync');
|
|
|
|
// THEN
|
|
$response->assertRedirect('/bo/login');
|
|
});
|
|
});
|