'CUST-A', 'tenant_name' => 'Customer Tenant']); $owner = User::factory()->create(['access_level' => 'tenant_owner']); $owner->userTenants()->create(['tenant_id' => $tenant->id, 'is_default' => true]); $provinsi = WilayahProvinsi::create(['kode' => '01', 'nama' => 'Provinsi']); $kabupaten = WilayahKabupaten::create(['provinsi_id' => $provinsi->id, 'kode' => '0101', 'nama' => 'Kabupaten']); $kecamatan = WilayahKecamatan::create(['kabupaten_id' => $kabupaten->id, 'kode' => '010101', 'nama' => 'Kecamatan']); $desa = WilayahDesa::create(['kecamatan_id' => $kecamatan->id, 'kode' => '01010101', 'nama' => 'Desa']); $profile = NasPackageProfile::create([ 'tenant_id' => $tenant->id, 'name' => '10 Mbps', 'service_type' => 'ppp', ]); $nas = NasMikrotik::create([ 'tenant_id' => $tenant->id, 'name' => 'Router Customer', 'connection_type' => 'api', 'host' => '10.0.0.1', ]); $billingProfile = BillingProfile::create([ 'tenant_id' => $tenant->id, 'name' => 'Tagihan Customer', 'invoice_day' => 1, 'send_day' => 2, 'warning_day' => 10, 'isolation_day' => 15, 'tax_type' => 'non_tax', ]); $service = app(CustomerService::class); $customer = $service->create([ 'name' => 'Customer Satu', 'installation_address' => 'Jalan Pengujian', 'provinsi_id' => $provinsi->id, 'kabupaten_id' => $kabupaten->id, 'kecamatan_id' => $kecamatan->id, 'desa_id' => $desa->id, ], $owner, $tenant->id); $this->assertSame('order', $customer->status); $customer = $service->activate($customer, [ 'package_profile_id' => $profile->id, 'nas_mikrotik_id' => $nas->id, 'billing_profile_id' => $billingProfile->id, ]); $this->assertSame('active', $customer->status); $this->assertNotNull($customer->activated_at); $customer = $service->deactivate($customer); $this->assertSame('inactive', $customer->status); $service->trash($customer); $this->assertNotNull($customer->fresh()->deleted_at); $restored = $service->restore($service->find($customer->id, true)); $this->assertNull($restored->deleted_at); $this->assertSame('inactive', $restored->status); } public function test_customer_list_is_isolated_by_active_tenant(): void { $tenantA = Tenant::create(['tenant_code' => 'CUST-LA', 'tenant_name' => 'Tenant A']); $tenantB = Tenant::create(['tenant_code' => 'CUST-LB', 'tenant_name' => 'Tenant B']); $owner = User::factory()->create(['access_level' => 'tenant_owner']); $owner->userTenants()->create(['tenant_id' => $tenantA->id, 'is_default' => true]); $service = app(CustomerService::class); $service->create(['name' => 'Customer A'], $owner, $tenantA->id); $master = User::factory()->create(['is_master' => true, 'access_level' => 'master_admin']); $service->create(['tenant_id' => $tenantB->id, 'name' => 'Customer B'], $master, null); $result = $service->list('orders', ['per_page' => 100], $owner, $tenantA->id); $this->assertSame(['Customer A'], $result->getCollection()->pluck('name')->all()); } }