add notifications logic and add support of both JWT and Sanctum

This commit is contained in:
root
2026-03-11 01:20:31 -04:00
parent f6be51576c
commit 182036cc41
141 changed files with 8685 additions and 648 deletions
@@ -0,0 +1,102 @@
<?php
namespace Tests\Unit\Services\School;
use App\Services\EmailService;
use App\Services\Notifications\UserNotificationDispatchService;
use App\Services\School\AccountEventService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Mockery;
use Tests\TestCase;
class AccountEventServiceTest extends TestCase
{
use RefreshDatabase;
public function test_new_account_added_creates_family_links(): void
{
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '5551112222',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
'id' => 5,
'school_id' => 1,
'parent_id' => 1,
'firstname' => 'Student',
'lastname' => 'One',
'dob' => '2015-01-01',
'age' => 10,
'gender' => 'Male',
'is_active' => 1,
'photo_consent' => 1,
'year_of_registration' => '2025',
'school_year' => '2025-2026',
]);
$email = Mockery::mock(EmailService::class);
$email->shouldReceive('send')->twice()->andReturn(true);
$notifier = Mockery::mock(UserNotificationDispatchService::class);
$service = new AccountEventService($email, $notifier);
$result = $service->newAccountAdded([
'id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'cellphone' => '5551112222',
]);
$this->assertTrue($result['ok']);
$this->assertDatabaseHas('families', [
'family_code' => 'FAM-1',
]);
$this->assertDatabaseHas('family_guardians', [
'user_id' => 1,
'is_primary' => 1,
]);
$this->assertDatabaseHas('family_students', [
'student_id' => 5,
]);
}
public function test_delete_unverified_user_handles_missing_admin_emails(): void
{
$email = Mockery::mock(EmailService::class);
$email->shouldReceive('send')->andReturn(true);
$notifier = Mockery::mock(UserNotificationDispatchService::class);
$notifier->shouldReceive('notifyUser')->once();
$service = new AccountEventService($email, $notifier);
$result = $service->deleteUnverifiedUser([
'id' => 2,
'email' => 'inactive@example.com',
]);
$this->assertTrue($result['ok']);
}
}
@@ -0,0 +1,49 @@
<?php
namespace Tests\Unit\Services\School;
use App\Services\EmailService;
use App\Services\Notifications\UserNotificationDispatchService;
use App\Services\School\EnrollmentEventService;
use Mockery;
use Tests\TestCase;
class EnrollmentEventServiceTest extends TestCase
{
public function test_admission_under_review_sends_email(): void
{
$email = Mockery::mock(EmailService::class);
$email->shouldReceive('send')->once()->andReturn(true);
$notifier = Mockery::mock(UserNotificationDispatchService::class);
$notifier->shouldReceive('notifyUser')->once();
$service = new EnrollmentEventService($email, $notifier);
$result = $service->admissionUnderReview([
'user_id' => 1,
'email' => 'parent@example.com',
'firstname' => 'Parent',
'lastname' => 'User',
], [
['firstname' => 'Student', 'lastname' => 'One'],
]);
$this->assertTrue($result['ok']);
}
public function test_admission_under_review_requires_email(): void
{
$email = Mockery::mock(EmailService::class);
$notifier = Mockery::mock(UserNotificationDispatchService::class);
$notifier->shouldReceive('notifyUser')->once();
$service = new EnrollmentEventService($email, $notifier);
$result = $service->admissionUnderReview([
'user_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
], []);
$this->assertFalse($result['ok']);
}
}
@@ -0,0 +1,61 @@
<?php
namespace Tests\Unit\Services\School;
use App\Services\EmailService;
use App\Services\Notifications\UserNotificationDispatchService;
use App\Services\School\PaymentEventService;
use Mockery;
use Tests\TestCase;
class PaymentEventServiceTest extends TestCase
{
public function test_payment_received_sends_email(): void
{
$email = Mockery::mock(EmailService::class);
$email->shouldReceive('send')->once()->andReturn(true);
$notifier = Mockery::mock(UserNotificationDispatchService::class);
$notifier->shouldReceive('notifyUser')->once();
$service = new PaymentEventService($email, $notifier);
$result = $service->paymentReceived([
'user_id' => 1,
'email' => 'parent@example.com',
'firstname' => 'Parent',
'lastname' => 'User',
'amount' => 25,
'invoice_id' => 10,
'payment_date' => now()->toDateTimeString(),
'installment_seq' => 1,
'pre_balance' => 50,
'post_balance' => 25,
'invoice_total' => 100,
]);
$this->assertTrue($result['ok']);
}
public function test_extra_charge_requires_email(): void
{
$email = Mockery::mock(EmailService::class);
$notifier = Mockery::mock(UserNotificationDispatchService::class);
$notifier->shouldReceive('notifyUser')->once();
$service = new PaymentEventService($email, $notifier);
$result = $service->extraCharge([
'user_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'amount_signed' => 10,
'amount_abs' => 10,
'pre_balance' => 0,
'post_balance' => 10,
'invoice_total' => 100,
'charge_title' => 'Fee',
'charge_type' => 'add',
]);
$this->assertFalse($result['ok']);
}
}