AdminSchoolsIndex test
This commit is contained in:
parent
f1a0f08f44
commit
71b4c245f9
|
|
@ -22,9 +22,9 @@
|
||||||
<x-table.body>
|
<x-table.body>
|
||||||
@foreach($schools as $school)
|
@foreach($schools as $school)
|
||||||
<tr>
|
<tr>
|
||||||
<x-table.td><a href="/admin/schools/{{ $school->id }}">{{ $school->name }}</a></x-table.td>
|
<x-table.td><a href="{{ route('admin.schools.edit',$school) }}">{{ $school->name }}</a></x-table.td>
|
||||||
<x-table.td>
|
<x-table.td>
|
||||||
<a href="{{ route('admin.schools.invoice',$school->id) }}">
|
<a href="{{ route('admin.schools.invoice',$school) }}">
|
||||||
${{ number_format($schoolTotalFees[$school->id],2) }}
|
${{ number_format($schoolTotalFees[$school->id],2) }}
|
||||||
</a>
|
</a>
|
||||||
</x-table.td>
|
</x-table.td>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\School;
|
||||||
|
use App\Models\Student;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Settings;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
|
||||||
|
use function Pest\Laravel\actingAs;
|
||||||
|
use function Pest\Laravel\get;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->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()));
|
||||||
|
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',
|
||||||
|
$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 an edit 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.edit', $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));
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue