'11111111-1111-1111-1111-111111111111', 'name' => 'Admin BerasPro', 'email' => 'admin@beraspro.test', 'password' => '$2y$04$hash', 'role' => 'admin', 'is_active' => true, ]); Livewire::test(Login::class) ->fillForm(['email' => 'admin@beraspro.test', 'password' => 'secret']) ->call('authenticate') ->assertHasNoErrors(); $this->assertAuthenticated(); } private function actingAsRole(string $role): User { $user = new User; $user->forceFill([ 'id' => "33333333-3333-3333-3333-{$role}0000000", 'name' => ucfirst($role), 'email' => "{$role}@beraspro.test", 'role' => $role, 'is_active' => true, ]); InsForgeFake::reset(); InsForgeFake::fakeRest(); $this->actingAs($user); return $user; } public function test_products_page_lists_records_from_insforge(): void { $this->loginAsAdmin(); $this->assertTrue(auth()->check(), 'admin should be authenticated after login'); $this->assertTrue(auth()->user()->isAdmin(), 'authenticated user should have admin role'); InsForgeFake::seed('products', [ 'id' => '00000000-0000-0000-0000-000000000101', 'code' => 'BERAS-001', 'name' => 'Beras Premium 5kg', 'unit' => 'sak', 'weight' => 5, 'stock_minimum' => 100, 'cost_price' => 13000, 'is_active' => true, ]); InsForgeFake::fakeRest(); Livewire::test(Products::class) ->assertSuccessful() ->assertSee('Beras Premium 5kg'); } public function test_products_page_is_denied_for_operator(): void { $this->actingAsRole('operator'); $this->get('/admin/'.(new Products)->getSlug())->assertForbidden(); } public function test_customers_page_is_accessible_for_operator(): void { $this->actingAsRole('operator'); Livewire::test(Customers::class)->assertSuccessful(); } public function test_drivers_page_is_denied_for_operator(): void { $this->actingAsRole('operator'); $this->get('/admin/'.(new Drivers)->getSlug())->assertForbidden(); } public function test_drivers_page_is_accessible_for_admin(): void { $this->loginAsAdmin(); InsForgeFake::fakeRest(); Livewire::test(Drivers::class)->assertSuccessful(); } public function test_product_service_creates_record_via_post(): void { InsForgeFake::reset(); InsForgeFake::fakeRest(); app(ProductService::class)->create([ 'code' => 'BERAS-002', 'name' => 'Beras Merah', 'unit' => 'kg', 'weight' => 25, 'stock_minimum' => 50, 'cost_price' => 12000, 'is_active' => true, ]); $stored = array_values(InsForgeFake::$store['products'])[0]; $this->assertSame('BERAS-002', $stored['code']); $this->assertSame(12000, $stored['cost_price']); } public function test_customer_service_updates_and_deletes(): void { InsForgeFake::reset(); InsForgeFake::fakeRest(); InsForgeFake::seed('customers', [ 'id' => 'aaaa1111-0000-0000-0000-000000000001', 'customer_code' => 'CUST-0001', 'name' => 'Andi', 'phone' => '0812', ]); $service = app(CustomerService::class); $found = $service->findBy(['customer_code' => 'CUST-0001']); $this->assertNotNull($found); $service->update($found['id'], ['name' => 'Andi Updated']); $this->assertSame('Andi Updated', $service->find($found['id'])['name']); $service->delete($found['id']); $this->assertNull($service->find($found['id'])); } public function test_driver_service_paginates_with_total(): void { InsForgeFake::reset(); InsForgeFake::fakeRest(); for ($i = 1; $i <= 3; $i++) { InsForgeFake::seed('drivers', [ 'id' => sprintf('bbbb2222-0000-0000-0000-00000000000%d', $i), 'driver_code' => sprintf('DRV-%04d', $i), 'name' => "Driver {$i}", 'is_active' => true, ]); } $paginator = app(DriverService::class)->paginate(page: 1, perPage: 2); $this->assertCount(2, $paginator->items()); $this->assertSame(3, $paginator->total()); } }