update tests

This commit is contained in:
root
2026-06-08 22:06:30 -04:00
parent 79024235ef
commit 60ecacb7f8
54 changed files with 13243 additions and 5561 deletions
@@ -44,8 +44,12 @@ class ApiLoginSecurityServiceTest extends TestCase
$this->assertTrue($payload['status']);
$this->assertSame('jwt-token', $payload['token']);
$this->assertSame('jwt-token', $payload['access_token']);
$this->assertSame('bearer', $payload['token_type']);
$this->assertSame(99, $payload['user']['id']);
$this->assertSame('Amina Teacher', $payload['user']['name']);
$this->assertSame('Amina', $payload['user']['firstname']);
$this->assertSame('Teacher', $payload['user']['lastname']);
$this->assertSame(42, $payload['user']['class_section_id']);
$this->assertSame('Grade 5 - A', $payload['user']['class_section_name']);
$this->assertTrue($payload['user']['roles']->Teacher);
+3 -3
View File
@@ -13,9 +13,9 @@ class AuthSessionServiceTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$urls = $this->createMock(ApplicationUrlService::class);
$urls->method('docsHomeUrl')->willReturn('http://example.org');
$this->svc = new AuthSessionService($urls);
// ApplicationUrlService is final (cannot be mocked); these tests only exercise
// relative-path sanitization and never call docsHomeUrl().
$this->svc = new AuthSessionService(new ApplicationUrlService());
}
public function test_sanitize_redirect_relative(): void
@@ -3,8 +3,7 @@
namespace Tests\Unit\Http\Controllers\Api;
use App\Http\Controllers\Api\Attendance\AttendanceCommentTemplateController;
use App\Http\Requests\AttendanceCommentTemplate\StoreAttendanceCommentTemplateRequest;
use App\Http\Requests\AttendanceCommentTemplate\UpdateAttendanceCommentTemplateRequest;
use App\Services\ApplicationUrlService;
use App\Services\AttendanceCommentTemplateService;
use Illuminate\Http\Request;
use Mockery;
@@ -12,6 +11,11 @@ use Tests\TestCase;
class AttendanceCommentTemplateControllerTest extends TestCase
{
private function makeController(AttendanceCommentTemplateService $service): AttendanceCommentTemplateController
{
return new AttendanceCommentTemplateController($service, new ApplicationUrlService());
}
protected function tearDown(): void
{
Mockery::close();
@@ -28,7 +32,7 @@ class AttendanceCommentTemplateControllerTest extends TestCase
['id' => 1, 'min_score' => 0, 'max_score' => 59, 'template_text' => 'Needs improvement', 'is_active' => true],
]);
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$request = Request::create('/api/attendance-comment-templates', 'GET');
@@ -50,7 +54,7 @@ class AttendanceCommentTemplateControllerTest extends TestCase
->with(true)
->andReturn([]);
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$request = Request::create('/api/attendance-comment-templates?active_only=1', 'GET');
@@ -75,7 +79,7 @@ class AttendanceCommentTemplateControllerTest extends TestCase
'is_active' => true,
]);
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$response = $controller->show(5);
@@ -101,10 +105,9 @@ class AttendanceCommentTemplateControllerTest extends TestCase
->with($payload)
->andReturn(array_merge(['id' => 10], $payload));
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$request = Mockery::mock(StoreAttendanceCommentTemplateRequest::class);
$request->shouldReceive('validated')->once()->andReturn($payload);
$request = Request::create('/api/attendance-comment-templates', 'POST', $payload);
$response = $controller->store($request);
@@ -135,10 +138,9 @@ class AttendanceCommentTemplateControllerTest extends TestCase
'is_active' => false,
]);
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$request = Mockery::mock(UpdateAttendanceCommentTemplateRequest::class);
$request->shouldReceive('validated')->once()->andReturn($payload);
$request = Request::create('/api/attendance-comment-templates/7', 'PUT', $payload);
$response = $controller->update($request, 7);
@@ -155,7 +157,7 @@ class AttendanceCommentTemplateControllerTest extends TestCase
$service = Mockery::mock(AttendanceCommentTemplateService::class);
$service->shouldReceive('delete')->once()->with(12);
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$response = $controller->destroy(12);
@@ -176,7 +178,7 @@ class AttendanceCommentTemplateControllerTest extends TestCase
['id' => 1, 'min_score' => 0, 'max_score' => 49, 'template_text' => 'Low', 'is_active' => true],
]);
$controller = new AttendanceCommentTemplateController($service);
$controller = $this->makeController($service);
$request = Request::create('/api/attendance-comment-templates/list-data', 'GET');
@@ -19,7 +19,7 @@ class NotificationUserListServiceTest extends TestCase
'title' => 'Unread',
'message' => 'Message 1',
'target_group' => 'parent',
'delivery_channels' => json_encode(['in_app']),
'delivery_channels' => 'in_app',
'scheduled_at' => now()->subHour(),
'created_at' => now(),
'updated_at' => now(),
@@ -29,7 +29,7 @@ class NotificationUserListServiceTest extends TestCase
'title' => 'Read',
'message' => 'Message 2',
'target_group' => 'parent',
'delivery_channels' => json_encode(['in_app']),
'delivery_channels' => 'in_app',
'scheduled_at' => now()->subHours(2),
'created_at' => now(),
'updated_at' => now(),
@@ -17,6 +17,9 @@ class ParentAttendanceReportServiceTest extends TestCase
public function test_form_data_returns_students(): void
{
// Pin calendar so upcoming Sundays exist within the 2025-2026 school year.
$this->travelTo('2025-10-05 10:00:00');
$this->seedConfig();
$parentId = $this->seedParent();
$this->seedStudent($parentId);
@@ -2,6 +2,7 @@
namespace Tests\Unit\Services\Payments;
use App\Services\ApplicationUrlService;
use App\Services\Payments\PaymentEnrollmentEventService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
@@ -11,9 +12,14 @@ class PaymentEnrollmentEventServiceTest extends TestCase
{
use RefreshDatabase;
private function makeService(): PaymentEnrollmentEventService
{
return new PaymentEnrollmentEventService(new ApplicationUrlService());
}
public function test_build_event_data_requires_parent(): void
{
$service = new PaymentEnrollmentEventService();
$service = $this->makeService();
$this->expectException(\RuntimeException::class);
@@ -43,7 +49,7 @@ class PaymentEnrollmentEventServiceTest extends TestCase
'school_year' => '2025-2026',
]);
$service = new PaymentEnrollmentEventService();
$service = $this->makeService();
[$parent, $students] = $service->buildEventData(10, [], '2025-2026', 'Fall', 'https://example.test/login');
$this->assertSame(10, $parent['user_id']);
@@ -23,7 +23,16 @@ class PaymentMissedCheckServiceTest extends TestCase
'id' => 1,
'firstname' => 'Parent',
'lastname' => 'Late',
'cellphone' => '5551112222',
'email' => 'late@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('secret'),
'semester' => 'Spring',
'school_year' => '2024-2025',
'status' => 'Active',
]);
@@ -24,7 +24,7 @@ class PaymentNotificationDispatchServiceTest extends TestCase
$this->assertDatabaseHas('notifications', [
'title' => 'Payment Reminder',
'message' => 'Reminder body',
'target_group' => 'user',
'target_group' => 'everyone',
'status' => 'sent',
'school_year' => '2025-2026',
'semester' => 'Fall',
@@ -21,8 +21,38 @@ class PaymentTestNotificationServiceTest extends TestCase
]);
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'],
[
'id' => 10,
'firstname' => 'Primary',
'lastname' => 'Parent',
'cellphone' => '5551112222',
'email' => 'primary@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('secret'),
'semester' => 'Spring',
'school_year' => '2024-2025',
'status' => 'Active',
],
[
'id' => 11,
'firstname' => 'Secondary',
'lastname' => 'Parent',
'cellphone' => '5553334444',
'email' => 'secondary@example.com',
'address_street' => '456 Oak',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'password' => bcrypt('secret'),
'semester' => 'Spring',
'school_year' => '2024-2025',
'status' => 'Active',
],
]);
DB::table('families')->insert([
@@ -2,6 +2,7 @@
namespace Tests\Unit\Services\Payments;
use App\Services\ApplicationUrlService;
use App\Services\Payments\PaypalPaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
@@ -11,6 +12,11 @@ class PaypalPaymentServiceTest extends TestCase
{
use RefreshDatabase;
private function makeService(): PaypalPaymentService
{
return new PaypalPaymentService(new ApplicationUrlService());
}
public function test_create_payment_falls_back_to_hosted_when_sdk_missing(): void
{
DB::table('payments')->insert([
@@ -27,7 +33,7 @@ class PaypalPaymentServiceTest extends TestCase
'status' => 'Pending',
]);
$service = new PaypalPaymentService();
$service = $this->makeService();
$result = $service->createPayment(1);
$this->assertSame('hosted', $result['mode']);
@@ -36,7 +42,7 @@ class PaypalPaymentServiceTest extends TestCase
public function test_execute_payment_throws_when_sdk_missing(): void
{
$service = new PaypalPaymentService();
$service = $this->makeService();
$this->expectException(\RuntimeException::class);