add more controllers and fix tests
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Email;
|
||||
|
||||
use App\Services\Email\EmailExtractorService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailExtractorServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_and_compare_emails(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'User',
|
||||
'lastname' => 'One',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'user1@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('parents')->insert([
|
||||
'secondparent_firstname' => 'Parent',
|
||||
'secondparent_lastname' => 'Two',
|
||||
'secondparent_email' => 'parent2@example.com',
|
||||
'secondparent_phone' => '5555555555',
|
||||
'firstparent_id' => 1,
|
||||
'secondparent_id' => 2,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new EmailExtractorService();
|
||||
$emails = $service->listEmails();
|
||||
|
||||
$this->assertContains('user1@example.com', $emails['users']);
|
||||
$this->assertContains('parent2@example.com', $emails['parents']);
|
||||
|
||||
$result = $service->compare(['user1@example.com', 'missing@example.com']);
|
||||
|
||||
$this->assertContains('user1@example.com', $result['existed']);
|
||||
$this->assertContains('parent2@example.com', $result['needToAdd']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Email;
|
||||
|
||||
use App\Services\Email\EmailProfileService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailProfileServiceTest extends TestCase
|
||||
{
|
||||
public function test_resolve_profile_maps_aliases(): void
|
||||
{
|
||||
$service = new EmailProfileService();
|
||||
|
||||
$this->assertSame('communication', $service->resolveProfile('comm'));
|
||||
$this->assertSame('default', $service->resolveProfile('system'));
|
||||
$this->assertSame('payment', $service->resolveProfile('payment'));
|
||||
}
|
||||
|
||||
public function test_env_key_from_profile(): void
|
||||
{
|
||||
$service = new EmailProfileService();
|
||||
|
||||
$this->assertSame('PAYMENT_ALERTS', $service->envKeyFromProfile('payment alerts'));
|
||||
}
|
||||
|
||||
public function test_sanitize_reply_to_name(): void
|
||||
{
|
||||
$service = new EmailProfileService();
|
||||
|
||||
$this->assertSame('Fallback', $service->sanitizeReplyToName('no-reply', 'Fallback'));
|
||||
$this->assertSame('Support', $service->sanitizeReplyToName('Support', 'Fallback'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Fees;
|
||||
|
||||
use App\Services\Fees\FeeGradeService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeeGradeServiceTest extends TestCase
|
||||
{
|
||||
public function test_grade_level_parsing(): void
|
||||
{
|
||||
$service = new FeeGradeService();
|
||||
|
||||
$this->assertSame(0, $service->getGradeLevel('K'));
|
||||
$this->assertSame(99, $service->getGradeLevel('Y'));
|
||||
$this->assertSame(3, $service->getGradeLevel('3-A'));
|
||||
$this->assertSame(999, $service->getGradeLevel('Unknown'));
|
||||
}
|
||||
|
||||
public function test_compare_grades_orders_numeric_then_suffix(): void
|
||||
{
|
||||
$service = new FeeGradeService();
|
||||
|
||||
$this->assertSame(-1, $service->compareGrades('2', '3'));
|
||||
$this->assertSame(-1, $service->compareGrades('3-A', '3-B'));
|
||||
$this->assertSame(1, $service->compareGrades('4', '3'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Fees;
|
||||
|
||||
use App\Services\Fees\FeeConfigService;
|
||||
use App\Services\Fees\FeeGradeService;
|
||||
use App\Services\Fees\FeeRefundCalculatorService;
|
||||
use App\Services\Fees\FeeStudentFeeService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeeRefundCalculatorServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_calculate_refund_caps_at_total_paid(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'refund_deadline', 'config_value' => '2025-02-01'],
|
||||
['config_key' => 'weeks_study', 'config_value' => '8'],
|
||||
['config_key' => 'last_school_day', 'config_value' => '2025-06-01'],
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
['config_key' => 'youth_fee', 'config_value' => '180'],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '3',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 99,
|
||||
'paid_amount' => 100.00,
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'number_of_installments' => 1,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$service = new FeeRefundCalculatorService(
|
||||
new FeeConfigService(),
|
||||
new FeeStudentFeeService(new FeeGradeService(), new FeeConfigService())
|
||||
);
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
],
|
||||
], 99);
|
||||
|
||||
$this->assertSame(100.0, $result['refund_amount']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\PurchaseOrders;
|
||||
|
||||
use App\Services\PurchaseOrders\PurchaseOrderCreateService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PurchaseOrderCreateServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_create_persists_purchase_order_and_items(): void
|
||||
{
|
||||
$supplierId = DB::table('suppliers')->insertGetId(['name' => 'Alpha Supplies']);
|
||||
$supplyId = DB::table('supplies')->insertGetId(['name' => 'Paper', 'unit' => 'box', 'qty_on_hand' => 0]);
|
||||
|
||||
$service = new PurchaseOrderCreateService();
|
||||
$po = $service->create([
|
||||
'po_number' => 'PO-500',
|
||||
'supplier_id' => $supplierId,
|
||||
'order_date' => '2026-03-10',
|
||||
'expected_date' => '2026-03-15',
|
||||
'notes' => 'Initial order',
|
||||
'items' => [
|
||||
[
|
||||
'supply_id' => $supplyId,
|
||||
'description' => 'Paper for class',
|
||||
'quantity' => 3,
|
||||
'unit_cost' => 4,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertNotNull($po->id);
|
||||
$this->assertDatabaseHas('purchase_orders', [
|
||||
'id' => $po->id,
|
||||
'po_number' => 'PO-500',
|
||||
'subtotal' => 12,
|
||||
'total' => 12,
|
||||
]);
|
||||
$this->assertDatabaseHas('purchase_order_items', [
|
||||
'purchase_order_id' => $po->id,
|
||||
'supply_id' => $supplyId,
|
||||
'quantity' => 3,
|
||||
'unit_cost' => 4,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\PurchaseOrders;
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\PurchaseOrderItem;
|
||||
use App\Models\Supply;
|
||||
use App\Services\PurchaseOrders\PurchaseOrderReceiveService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PurchaseOrderReceiveServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_receive_updates_items_and_inventory(): void
|
||||
{
|
||||
$supply = Supply::query()->create([
|
||||
'name' => 'Paper',
|
||||
'unit' => 'box',
|
||||
'qty_on_hand' => 2,
|
||||
]);
|
||||
|
||||
$po = PurchaseOrder::query()->create([
|
||||
'po_number' => 'PO-600',
|
||||
'supplier_id' => 1,
|
||||
'status' => PurchaseOrder::STATUS_ORDERED,
|
||||
'subtotal' => 10,
|
||||
'tax' => 0,
|
||||
'total' => 10,
|
||||
]);
|
||||
|
||||
$item = PurchaseOrderItem::query()->create([
|
||||
'purchase_order_id' => $po->id,
|
||||
'supply_id' => $supply->id,
|
||||
'description' => 'Paper for class',
|
||||
'quantity' => 3,
|
||||
'received_qty' => 0,
|
||||
'unit_cost' => 3,
|
||||
]);
|
||||
|
||||
$service = new PurchaseOrderReceiveService();
|
||||
$result = $service->receive($po->id, [
|
||||
['id' => $item->id, 'quantity' => 3],
|
||||
], 'tester@example.com');
|
||||
|
||||
$this->assertTrue($result['completed']);
|
||||
$this->assertDatabaseHas('purchase_order_items', [
|
||||
'id' => $item->id,
|
||||
'received_qty' => 3,
|
||||
]);
|
||||
$this->assertDatabaseHas('supplies', [
|
||||
'id' => $supply->id,
|
||||
'qty_on_hand' => 5,
|
||||
]);
|
||||
$this->assertDatabaseHas('supply_transactions', [
|
||||
'supply_id' => $supply->id,
|
||||
'type' => 'in',
|
||||
'quantity' => 3,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\PurchaseOrders;
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Services\PurchaseOrders\PurchaseOrderStatusService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PurchaseOrderStatusServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_cancel_marks_purchase_order_canceled(): void
|
||||
{
|
||||
$po = PurchaseOrder::query()->create([
|
||||
'po_number' => 'PO-700',
|
||||
'supplier_id' => 1,
|
||||
'status' => PurchaseOrder::STATUS_ORDERED,
|
||||
'subtotal' => 0,
|
||||
'tax' => 0,
|
||||
'total' => 0,
|
||||
]);
|
||||
|
||||
$service = new PurchaseOrderStatusService();
|
||||
$updated = $service->cancel($po->id);
|
||||
|
||||
$this->assertSame(PurchaseOrder::STATUS_CANCELED, $updated->status);
|
||||
$this->assertDatabaseHas('purchase_orders', [
|
||||
'id' => $po->id,
|
||||
'status' => PurchaseOrder::STATUS_CANCELED,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user