70 lines
2.6 KiB
PHP
70 lines
2.6 KiB
PHP
<?php
|
|
|
|
use App\Models\Department;
|
|
use App\Models\DepartmentProfile;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('authenticated users can open the departments reference page', function () {
|
|
$user = User::factory()->create();
|
|
$departmentProfile = DepartmentProfile::factory()->create([
|
|
'name' => 'Диагностический профиль',
|
|
]);
|
|
$department = Department::factory()->create([
|
|
'name' => 'Рентген-отделение',
|
|
'department_profile_id' => $departmentProfile->id,
|
|
]);
|
|
|
|
$response = $this
|
|
->actingAs($user)
|
|
->get(route('references.departments.index', ['current_team' => $user->currentTeam->slug]));
|
|
|
|
$response
|
|
->assertOk()
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->component('references/departments/Index')
|
|
->where('departmentProfiles.0.name', 'Диагностический профиль')
|
|
->where('departments.0.name', 'Рентген-отделение')
|
|
->where('departments.0.departmentProfile.name', 'Диагностический профиль'));
|
|
});
|
|
|
|
test('authenticated users can create a department profile', function () {
|
|
$user = User::factory()->create();
|
|
|
|
$response = $this
|
|
->actingAs($user)
|
|
->post(route('references.department-profiles.store', ['current_team' => $user->currentTeam->slug]), [
|
|
'name' => 'Хирургический профиль',
|
|
]);
|
|
|
|
$response->assertRedirect(route('references.departments.index', ['current_team' => $user->currentTeam->slug]));
|
|
|
|
$this->assertDatabaseHas('department_profiles', [
|
|
'name' => 'Хирургический профиль',
|
|
]);
|
|
});
|
|
|
|
test('authenticated users can create a department', function () {
|
|
$user = User::factory()->create();
|
|
$departmentProfile = DepartmentProfile::factory()->create();
|
|
|
|
$response = $this
|
|
->actingAs($user)
|
|
->post(route('references.departments.store', ['current_team' => $user->currentTeam->slug]), [
|
|
'name' => 'Терапевтическое отделение',
|
|
'department_profile_id' => $departmentProfile->id,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$response->assertRedirect(route('references.departments.index', ['current_team' => $user->currentTeam->slug]));
|
|
|
|
$this->assertDatabaseHas('departments', [
|
|
'name' => 'Терапевтическое отделение',
|
|
'department_profile_id' => $departmentProfile->id,
|
|
'is_active' => true,
|
|
]);
|
|
});
|