ldc-cocotte/tests/Feature/App/Http/Controllers/Bo/EmployeesControllerTest.php

52 lines
1.4 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use App\Models\User;
use Domain\Enums\UserRole;
use Illuminate\Http\UploadedFile;
describe('EmployeesController', function () {
beforeEach(function () {
// GIVEN
/** @var \Tests\TestCase $this */
$this->user = User::factory()->create(['role' => UserRole::SuperAdmin]);
$this->actingAs($this->user, 'backend');
});
it('can access import form', function () {
// WHEN
/** @var \Tests\TestCase $this */
$response = $this->get('/bo/settings/employees');
// THEN
$response->assertOk();
$response->assertViewHas('importColumns');
});
it('can download example file', function () {
// WHEN
/** @var \Tests\TestCase $this */
$response = $this->get('/bo/settings/employees/import-example');
// THEN
$response->assertOk();
});
it('can import employees file', function () {
// GIVEN
/** @var \Tests\TestCase $this */
$csvContent = "identifiant;nom;prenom;solde\nEMP001;Dupont;Jean;100.00\n";
$file = UploadedFile::fake()->createWithContent('employees.csv', $csvContent);
// WHEN
$response = $this->post('/bo/settings/employees/file', [
'import' => $file,
]);
// THEN
$response->assertSessionHasNoErrors();
$response->assertRedirect('/bo/settings/employees');
});
});