add notifications logic and add support of both JWT and Sanctum
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Attendance;
|
||||
|
||||
use App\Services\Attendance\AttendanceDailySummaryService;
|
||||
use App\Services\EmailService;
|
||||
use App\Services\Notifications\UserNotificationDispatchService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AttendanceDailySummaryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_send_absentees_summary_notifies_parent(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2025-02-10 08:00:00'));
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 5,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'One',
|
||||
'email' => 'parent@example.com',
|
||||
'status' => 'Active',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 10,
|
||||
'school_id' => 1,
|
||||
'parent_id' => 5,
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'dob' => '2015-01-01',
|
||||
'age' => 10,
|
||||
'gender' => 'Male',
|
||||
'is_active' => 1,
|
||||
'photo_consent' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2024-2025',
|
||||
]);
|
||||
|
||||
DB::table('attendance_data')->insert([
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'student_id' => 10,
|
||||
'school_id' => 'S1',
|
||||
'date' => '2025-02-10',
|
||||
'status' => 'absent',
|
||||
'semester' => 'Spring',
|
||||
'school_year' => '2024-2025',
|
||||
]);
|
||||
|
||||
$notifier = Mockery::mock(UserNotificationDispatchService::class);
|
||||
$notifier->shouldReceive('notifyUser')->once();
|
||||
|
||||
$email = Mockery::mock(EmailService::class);
|
||||
$email->shouldReceive('send')->once()->andReturn(true);
|
||||
|
||||
$service = new AttendanceDailySummaryService($notifier, $email);
|
||||
|
||||
$count = $service->sendAbsenteesSummary();
|
||||
|
||||
$this->assertSame(1, $count);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user