adminUser = User::factory()->admin()->create(); $this->nonAdminUser = User::factory()->create(); $this->tabUser = User::factory()->tab()->create(); $this->schools = School::factory()->count(5)->create(); $n = 10; $this->students = []; foreach ($this->schools as $school) { $newStus = Student::factory()->count($n)->create(['school_id' => $school->id]); foreach ($newStus as $student) { $this->students[] = $student; } $n = $n + 3; } $n = 0; foreach ($this->students as $student) { Entry::factory()->create(['student_id' => $student->id]); $n++; if ($n === 10) { Entry::factory()->create(['student_id' => $student->id]); $n = 0; } } }); it('only shows for an admin user', function () { // Act & Assert $checkRoute = 'admin.schools.index'; get(route($checkRoute))->assertRedirect(route('home')); actingAs($this->adminUser); get(route($checkRoute))->assertOk(); actingAs($this->nonAdminUser); get(route($checkRoute))->assertRedirect(route('dashboard')); }); it('has a new school link', function () { // Arrange actingAs($this->adminUser); // Act & Assert get(route('admin.schools.index')) ->assertOk() ->assertSeeInOrder([ 'href=', route('admin.schools.create'), 'New School', '/a', ]); }); it('shows school data', function () { // Arrange #$invoiceDataService = new App\Services\Invoice\InvoiceOneFeePerEntry(new App\Services\EntryService(new App\Services\AuditionService())); $invoiceDataService = App::make(InvoiceOneFeePerEntry::class); Settings::set('school_fees', 1000); Settings::set('late_fee', 2500); actingAs($this->adminUser); $this->schools->loadCount(['users', 'students', 'entries']); // Act & Assert $response = get(route('admin.schools.index')); $response->assertOk(); foreach ($this->schools as $school) { $response->assertSeeInOrder([ 'td', e($school->name), '/td', 'td', $invoiceDataService->getGrandTotal($school->id), '/td', 'td', $school->users_count, '/td', 'td', $school->students_count, '/td', 'td', $school->entries_count, '/td', ], false); } }); it('has a show link for each school', function () { // Arrange actingAs($this->adminUser); // Act & Assert $response = get(route('admin.schools.index')); $response->assertOk(); foreach ($this->schools as $school) { $response->assertSee(route('admin.schools.show', $school)); } }); it('has an invoice link for each school', function () { // Arrange actingAs($this->adminUser); // Act & Assert $response = get(route('admin.schools.index')); $response->assertOk(); foreach ($this->schools as $school) { $response->assertSee(route('admin.schools.invoice', $school)); } });