113 lines
3.3 KiB
PHP
113 lines
3.3 KiB
PHP
<?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));
|
|
}
|
|
});
|