add notifications logic and add support of both JWT and Sanctum
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Payments;
|
||||
|
||||
use App\Services\EmailService;
|
||||
use App\Services\Notifications\UserNotificationDispatchService;
|
||||
use App\Services\Payments\PaymentMissedCheckService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentMissedCheckServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_find_users_with_missed_payments(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2025-03-01'));
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'Late',
|
||||
'email' => 'late@example.com',
|
||||
'status' => 'Active',
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 1,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100,
|
||||
'balance' => 50,
|
||||
'paid_amount' => 50,
|
||||
'status' => 'Unpaid',
|
||||
'school_year' => '2024-2025',
|
||||
'semester' => 'Spring',
|
||||
'issue_date' => '2025-01-01',
|
||||
'due_date' => '2025-02-01',
|
||||
]);
|
||||
|
||||
$service = new PaymentMissedCheckService(
|
||||
Mockery::mock(UserNotificationDispatchService::class),
|
||||
Mockery::mock(EmailService::class)
|
||||
);
|
||||
|
||||
$users = $service->findUsersWithMissedPayments();
|
||||
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertSame(1, (int) $users[0]['user_id']);
|
||||
}
|
||||
|
||||
public function test_send_reminders_sends_email_and_notification(): void
|
||||
{
|
||||
$notifier = Mockery::mock(UserNotificationDispatchService::class);
|
||||
$notifier->shouldReceive('notifyUser')->once();
|
||||
|
||||
$email = Mockery::mock(EmailService::class);
|
||||
$email->shouldReceive('send')->once()->andReturn(true);
|
||||
|
||||
$service = new PaymentMissedCheckService($notifier, $email);
|
||||
|
||||
$result = $service->sendReminders([
|
||||
[
|
||||
'user_id' => 5,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'email' => 'parent@example.com',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(1, $result['sent']);
|
||||
$this->assertSame(0, $result['failed']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Payments;
|
||||
|
||||
use App\Services\EmailService;
|
||||
use App\Services\Payments\PaymentTestNotificationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentTestNotificationServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_send_logs_and_sends_email(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2024-2025'],
|
||||
['config_key' => 'installment_date', 'config_value' => '2025-06-01'],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
['id' => 10, 'firstname' => 'Primary', 'lastname' => 'Parent', 'email' => 'primary@example.com', 'status' => 'Active'],
|
||||
['id' => 11, 'firstname' => 'Secondary', 'lastname' => 'Parent', 'email' => 'secondary@example.com', 'status' => 'Active'],
|
||||
]);
|
||||
|
||||
DB::table('families')->insert([
|
||||
'id' => 1,
|
||||
'family_code' => 'FAM-1',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('family_guardians')->insert([
|
||||
[
|
||||
'family_id' => 1,
|
||||
'user_id' => 10,
|
||||
'relation' => 'guardian',
|
||||
'is_primary' => 1,
|
||||
'receive_emails' => 1,
|
||||
'receive_sms' => 0,
|
||||
],
|
||||
[
|
||||
'family_id' => 1,
|
||||
'user_id' => 11,
|
||||
'relation' => 'guardian',
|
||||
'is_primary' => 0,
|
||||
'receive_emails' => 1,
|
||||
'receive_sms' => 0,
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 200.00,
|
||||
'balance' => 150.00,
|
||||
'paid_amount' => 50.00,
|
||||
'status' => 'Partially Paid',
|
||||
'school_year' => '2024-2025',
|
||||
'semester' => 'Spring',
|
||||
'issue_date' => '2025-01-01',
|
||||
]);
|
||||
|
||||
$email = Mockery::mock(EmailService::class);
|
||||
$email->shouldReceive('send')->twice()->andReturn(true);
|
||||
|
||||
$service = new PaymentTestNotificationService($email);
|
||||
$result = $service->send('primary@example.com', 'no_payment');
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertDatabaseHas('payment_notification_logs', [
|
||||
'parent_id' => 10,
|
||||
'type' => 'no_payment',
|
||||
'to_email' => 'primary@example.com',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Payments;
|
||||
|
||||
use App\Services\EmailService;
|
||||
use App\Services\Payments\PaypalPaymentSyncService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaypalPaymentSyncServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_sync_applies_payment_and_marks_synced(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2024-2025'],
|
||||
['config_key' => 'semester', 'config_value' => 'Spring'],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 123,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'email' => 'parent@example.com',
|
||||
'status' => 'Active',
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 1,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100,
|
||||
'balance' => 100,
|
||||
'paid_amount' => 0,
|
||||
'status' => 'Unpaid',
|
||||
'school_year' => '2024-2025',
|
||||
'semester' => 'Spring',
|
||||
'issue_date' => '2025-01-01',
|
||||
]);
|
||||
|
||||
DB::table('paypal_payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_school_id' => 123,
|
||||
'transaction_id' => 'TXN-1',
|
||||
'status' => 'COMPLETED',
|
||||
'amount' => 50,
|
||||
'synced' => 0,
|
||||
'sync_attempts' => 0,
|
||||
'created_at' => '2025-01-15 10:00:00',
|
||||
]);
|
||||
|
||||
$email = Mockery::mock(EmailService::class);
|
||||
$email->shouldReceive('send')->once()->andReturn(true);
|
||||
|
||||
$service = new PaypalPaymentSyncService($email);
|
||||
$result = $service->sync(false, false);
|
||||
|
||||
$this->assertSame(1, $result['processed']);
|
||||
$this->assertDatabaseHas('paypal_payments', [
|
||||
'id' => 1,
|
||||
'synced' => 1,
|
||||
]);
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'invoice_id' => 1,
|
||||
'parent_id' => 1,
|
||||
'paid_amount' => 50,
|
||||
]);
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => 1,
|
||||
'balance' => 50,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user