add notifications logic and add support of both JWT and Sanctum
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use App\Services\Attendance\AttendanceAutoPublishJobService;
|
||||
use App\Services\Attendance\AttendanceDailySummaryService;
|
||||
use App\Services\Attendance\AttendanceSummaryRebuildService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AttendanceCommandsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_attendance_auto_publish_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(AttendanceAutoPublishJobService::class);
|
||||
$service->shouldReceive('run')->once()->andReturn([
|
||||
'checked_at' => '2025-03-01 10:00:00',
|
||||
'timezone' => 'UTC',
|
||||
'published' => 0,
|
||||
]);
|
||||
|
||||
$this->app->instance(AttendanceAutoPublishJobService::class, $service);
|
||||
|
||||
$this->artisan('attendance:auto-publish')->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_attendance_recalculate_summary_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(AttendanceSummaryRebuildService::class);
|
||||
$service->shouldReceive('rebuild')->once()->andReturn(['inserted' => 3]);
|
||||
|
||||
$this->app->instance(AttendanceSummaryRebuildService::class, $service);
|
||||
|
||||
$this->artisan('attendance:recalculate-summary')->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_attendance_absentees_summary_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(AttendanceDailySummaryService::class);
|
||||
$service->shouldReceive('sendAbsenteesSummary')->once()->andReturn(2);
|
||||
|
||||
$this->app->instance(AttendanceDailySummaryService::class, $service);
|
||||
|
||||
$this->artisan('attendance:absentees-summary')->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_attendance_lates_summary_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(AttendanceDailySummaryService::class);
|
||||
$service->shouldReceive('sendLatesSummary')->once()->andReturn(1);
|
||||
|
||||
$this->app->instance(AttendanceDailySummaryService::class, $service);
|
||||
|
||||
$this->artisan('attendance:lates-summary')->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use App\Services\Payments\PaymentMissedCheckService;
|
||||
use App\Services\Payments\PaymentNotificationService;
|
||||
use App\Services\Payments\PaymentTestNotificationService;
|
||||
use App\Services\Payments\PaypalPaymentSyncService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaymentsCommandsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_check_missed_payments_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(PaymentMissedCheckService::class);
|
||||
$service->shouldReceive('findUsersWithMissedPayments')->once()->andReturn([]);
|
||||
|
||||
$this->app->instance(PaymentMissedCheckService::class, $service);
|
||||
|
||||
$this->artisan('payments:check-missed')->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_monthly_reminder_command_sends_to_email(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'email' => 'parent@example.com',
|
||||
'status' => 'Active',
|
||||
]);
|
||||
|
||||
$service = Mockery::mock(PaymentNotificationService::class);
|
||||
$service->shouldReceive('send')->once()->andReturn([
|
||||
'sent' => 1,
|
||||
'skipped' => 0,
|
||||
'failed' => 0,
|
||||
'details' => [],
|
||||
]);
|
||||
|
||||
$this->app->instance(PaymentNotificationService::class, $service);
|
||||
|
||||
$this->artisan('payments:monthly-reminder', ['--email' => 'parent@example.com'])->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_send_test_payment_notification_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(PaymentTestNotificationService::class);
|
||||
$service->shouldReceive('send')->once()->andReturn(['ok' => true]);
|
||||
|
||||
$this->app->instance(PaymentTestNotificationService::class, $service);
|
||||
|
||||
$this->artisan('payments:send-test', ['--email' => 'parent@example.com'])->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_sync_paypal_payments_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(PaypalPaymentSyncService::class);
|
||||
$service->shouldReceive('sync')->once()->andReturn([
|
||||
'mode' => 'DRY-RUN',
|
||||
'processed' => 0,
|
||||
'failed' => [],
|
||||
]);
|
||||
|
||||
$this->app->instance(PaypalPaymentSyncService::class, $service);
|
||||
|
||||
$this->artisan('payments:sync-paypal', ['--dry-run' => true])->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use App\Services\Auth\PasswordResetCleanupService;
|
||||
use App\Services\Notifications\NotificationCleanupService;
|
||||
use App\Services\System\ConfigUpdateService;
|
||||
use App\Services\Users\InactiveUserCleanupService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SystemCommandsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_cleanup_expired_notifications_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(NotificationCleanupService::class);
|
||||
$service->shouldReceive('cleanupExpired')->once()->andReturn(2);
|
||||
|
||||
$this->app->instance(NotificationCleanupService::class, $service);
|
||||
|
||||
$this->artisan('notifications:cleanup')->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_cleanup_password_resets_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(PasswordResetCleanupService::class);
|
||||
$service->shouldReceive('cleanup')->once()->andReturn(1);
|
||||
|
||||
$this->app->instance(PasswordResetCleanupService::class, $service);
|
||||
|
||||
$this->artisan('cleanup:password-resets')->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_config_update_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(ConfigUpdateService::class);
|
||||
$service->shouldReceive('availableTasks')->andReturn(['enable_attendance_on']);
|
||||
$service->shouldReceive('runTask')->once()->andReturn(['ok' => true]);
|
||||
|
||||
$this->app->instance(ConfigUpdateService::class, $service);
|
||||
|
||||
$this->artisan('config:update', ['--task' => 'enable_attendance_on', '--tz' => 'UTC'])->assertExitCode(0);
|
||||
}
|
||||
|
||||
public function test_delete_inactive_users_command_runs(): void
|
||||
{
|
||||
$service = Mockery::mock(InactiveUserCleanupService::class);
|
||||
$service->shouldReceive('cleanup')->once()->andReturn([
|
||||
'deleted_users' => 0,
|
||||
'deleted_parents' => 0,
|
||||
'deleted_roles' => 0,
|
||||
]);
|
||||
|
||||
$this->app->instance(InactiveUserCleanupService::class, $service);
|
||||
|
||||
$this->artisan('users:delete-inactive-users')->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user