test: add feature tests for attendance delivery status and lecturer submission toggling
This commit is contained in:
parent
ff04c8486b
commit
61125f6d28
@ -2,6 +2,7 @@
|
||||
|
||||
use App\Enums\RoleEnum;
|
||||
use App\Filament\Resources\Learning\Attendances\Pages\ManageAttendances;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Pages\ListCourseSessions;
|
||||
use App\Models\Attendance;
|
||||
use App\Models\ClassSession;
|
||||
use App\Models\Course;
|
||||
@ -25,6 +26,9 @@
|
||||
'ViewAny:Attendance',
|
||||
'Create:Attendance',
|
||||
'Delete:Attendance',
|
||||
'ViewAny:Course',
|
||||
'ViewAny:ClassSession',
|
||||
'View:ClassSession',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
@ -168,3 +172,91 @@
|
||||
->assertCanNotSeeTableRecords([$att2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Attendance Delivery Status', function () {
|
||||
beforeEach(function () {
|
||||
$this->user = User::factory()->create();
|
||||
$this->user->assignRole(RoleEnum::Student);
|
||||
$this->user->givePermissionTo(['ViewAny:Attendance']);
|
||||
$this->student = Student::factory()->create(['user_id' => $this->user->id]);
|
||||
$this->actingAs($this->user);
|
||||
$this->currentSemester = app(GeneralSettings::class)->current_semester;
|
||||
});
|
||||
|
||||
it('allows attendance for past sessions if not yet sent to lecturer', function () {
|
||||
$course = Course::factory()->create(['semester' => $this->currentSemester]);
|
||||
$yesterday = now()->subDay();
|
||||
|
||||
$session = ClassSession::factory()->create([
|
||||
'course_id' => $course->id,
|
||||
'date' => $yesterday->toDateString(),
|
||||
'start_time' => $yesterday->copy()->setTime(8, 0),
|
||||
'end_time' => $yesterday->copy()->setTime(10, 0),
|
||||
'is_sent_to_lecturer' => false,
|
||||
]);
|
||||
|
||||
$schedule = CourseSchedule::factory()->create([
|
||||
'course_id' => $course->id,
|
||||
'day_of_week' => $yesterday->dayOfWeekIso,
|
||||
]);
|
||||
|
||||
Livewire::test(ManageAttendances::class)
|
||||
->call('attend', $session->id)
|
||||
->assertHasNoErrors();
|
||||
|
||||
$this->assertDatabaseHas('attendances', [
|
||||
'student_id' => $this->student->id,
|
||||
'class_session_id' => $session->id,
|
||||
]);
|
||||
});
|
||||
|
||||
it('prevents attendance if session is already sent to lecturer', function () {
|
||||
$course = Course::factory()->create(['semester' => $this->currentSemester]);
|
||||
$now = now();
|
||||
|
||||
$session = ClassSession::factory()->create([
|
||||
'course_id' => $course->id,
|
||||
'date' => $now->toDateString(),
|
||||
'start_time' => $now->copy()->subHours(1),
|
||||
'is_sent_to_lecturer' => true,
|
||||
]);
|
||||
|
||||
Livewire::test(ManageAttendances::class)
|
||||
->call('attend', $session->id);
|
||||
|
||||
$this->assertDatabaseMissing('attendances', [
|
||||
'student_id' => $this->student->id,
|
||||
'class_session_id' => $session->id,
|
||||
]);
|
||||
});
|
||||
|
||||
it('allows Kosma/Developer to toggle delivery status', function () {
|
||||
$kosmaUser = User::factory()->create();
|
||||
$kosmaUser->assignRole(RoleEnum::Kosma);
|
||||
$kosmaUser->givePermissionTo(['ViewAny:Course', 'ViewAny:ClassSession', 'ViewAny:Attendance']);
|
||||
$this->actingAs($kosmaUser);
|
||||
|
||||
$course = Course::factory()->create(['semester' => $this->currentSemester]);
|
||||
$session = ClassSession::factory()->create([
|
||||
'course_id' => $course->id,
|
||||
'is_sent_to_lecturer' => false,
|
||||
]);
|
||||
|
||||
// Using ListCourseSessions page to trigger the action
|
||||
Livewire::test(ListCourseSessions::class, [
|
||||
'course' => $course,
|
||||
])
|
||||
->callAction('markAsSentAction', [], ['record' => $session->id])
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($session->fresh()->is_sent_to_lecturer)->toBeTrue();
|
||||
|
||||
Livewire::test(ListCourseSessions::class, [
|
||||
'course' => $course,
|
||||
])
|
||||
->callAction('markAsSentAction', [], ['record' => $session->id])
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($session->fresh()->is_sent_to_lecturer)->toBeFalse();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user