add refund and event logic

This commit is contained in:
root
2026-03-10 23:12:49 -04:00
parent ba1206e314
commit f6be51576c
67 changed files with 4808 additions and 1000 deletions
@@ -0,0 +1,17 @@
<?php
namespace Tests\Unit\Services\Events;
use App\Services\Events\EventCategoryService;
use Tests\TestCase;
class EventCategoryServiceTest extends TestCase
{
public function test_categories_returns_list(): void
{
$categories = EventCategoryService::categories();
$this->assertContains('workshops', $categories);
$this->assertContains('field trips', $categories);
}
}
@@ -0,0 +1,34 @@
<?php
namespace Tests\Unit\Services\Events;
use App\Services\Events\EventChargeQueryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class EventChargeQueryServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_returns_paginated_charges(): void
{
DB::table('event_charges')->insert([
'id' => 1,
'event_id' => 1,
'parent_id' => 10,
'student_id' => 1,
'participation' => 'yes',
'charged' => 10,
'school_year' => '2025-2026',
'semester' => 'Fall',
'created_at' => now(),
'updated_at' => now(),
]);
$service = new EventChargeQueryService();
$result = $service->list(['per_page' => 10, 'page' => 1]);
$this->assertSame(1, $result['pagination']['total']);
}
}
@@ -0,0 +1,59 @@
<?php
namespace Tests\Unit\Services\Events;
use App\Models\Event;
use App\Services\Events\EventChargeService;
use App\Services\Invoices\InvoiceGenerationService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Mockery;
use Tests\TestCase;
class EventChargeServiceTest extends TestCase
{
use RefreshDatabase;
public function test_seed_charges_creates_event_charges(): void
{
DB::table('events')->insert([
'id' => 1,
'event_name' => 'Trip',
'event_category' => 'field trips',
'amount' => 25,
'expiration_date' => '2025-02-01',
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('students')->insert([
'id' => 1,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'One',
]);
DB::table('enrollments')->insert([
'id' => 1,
'student_id' => 1,
'parent_id' => 10,
'class_section_id' => 101,
'enrollment_status' => 'enrolled',
'school_year' => '2025-2026',
]);
$invoiceService = Mockery::mock(InvoiceGenerationService::class);
$invoiceService->shouldReceive('generateInvoice')->andReturn(['ok' => true]);
$service = new EventChargeService($invoiceService);
$event = Event::query()->findOrFail(1);
$service->seedChargesForEvent($event, '2025-2026', 'Fall', 25, 1);
$this->assertDatabaseHas('event_charges', [
'event_id' => 1,
'student_id' => 1,
]);
}
}
@@ -0,0 +1,46 @@
<?php
namespace Tests\Unit\Services\Events;
use App\Services\Events\EventListService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class EventListServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_filters_active_events(): void
{
DB::table('events')->insert([
[
'id' => 1,
'event_name' => 'Active',
'event_category' => 'workshops',
'amount' => 10,
'expiration_date' => now()->addDays(2)->toDateString(),
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
],
[
'id' => 2,
'event_name' => 'Expired',
'event_category' => 'workshops',
'amount' => 10,
'expiration_date' => now()->subDays(2)->toDateString(),
'semester' => 'Fall',
'school_year' => '2025-2026',
'created_at' => now(),
'updated_at' => now(),
],
]);
$service = new EventListService();
$result = $service->list(['active' => true, 'per_page' => 10]);
$this->assertSame(1, $result['pagination']['total']);
}
}
@@ -0,0 +1,26 @@
<?php
namespace Tests\Unit\Services\Events;
use App\Services\Events\EventChargeService;
use App\Services\Events\EventManagementService;
use App\Services\Invoices\InvoiceGenerationService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery;
use Tests\TestCase;
class EventManagementServiceTest extends TestCase
{
use RefreshDatabase;
public function test_update_returns_not_found(): void
{
$chargeService = Mockery::mock(EventChargeService::class);
$invoiceService = Mockery::mock(InvoiceGenerationService::class);
$service = new EventManagementService($chargeService, $invoiceService);
$result = $service->update(999, ['event_name' => 'Missing'], null);
$this->assertFalse($result['ok']);
}
}
@@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Services\Events;
use App\Services\Events\EventStudentChargeService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class EventStudentChargeServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_students_with_charges(): void
{
DB::table('students')->insert([
'id' => 1,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'One',
]);
DB::table('event_charges')->insert([
'id' => 1,
'event_id' => 1,
'parent_id' => 10,
'student_id' => 1,
'participation' => 'yes',
'charged' => 10,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$service = new EventStudentChargeService();
$rows = $service->listStudentsWithCharges(10, '2025-2026', 'Fall');
$this->assertTrue($rows[0]['charged']);
}
}