auditionadmin/tests/Feature/app/Http/Controllers/StudentControllerTest.php

53 lines
1.9 KiB
PHP

<?php
use App\Models\Audition;
use App\Models\School;
use App\Models\Student;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
describe('Test the index method of the student controller', function () {
it('redirects to the dashboard if the user does not have a school', function () {
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get(route('students.index'));
$response->assertRedirect(route('dashboard'));
actAsAdmin();
$response = $this->get(route('students.index'));
$response->assertRedirect(route('dashboard'));
});
it('redirects to the students index if the user has a school', function () {
$user = User::factory()->create();
$school = School::factory()->create();
$user->school_id = $school->id;
$user->save();
$this->actingAs($user);
$response = $this->get(route('students.index'));
$response->assertOk();
});
it('returns the view students.index', function () {
$user = User::factory()->create();
$school = School::factory()->create();
$audition = Audition::factory()->create();
$student = Student::factory()->forSchool($school)->create();
$user->school_id = $school->id;
$user->save();
$this->actingAs($user);
$response = $this->get(route('students.index'));
$response->assertViewIs('students.index')
->assertViewHas('students', function ($students) use ($student) {
return $students->contains($student);
})
->assertViewHas('auditions', function ($auditions) use ($audition) {
return $auditions->contains($audition);
})
->assertSee(route('students.store'));
});
});
describe('Test the store method of the student controller', function () {
});