create(); $otherCustomer = Customer::factory()->create(); $vps = Service::create([ 'customer_id' => $customer->id, 'type' => 'vps', 'server_name' => 'vps.example.vn', 'status' => 'active', ]); $hosting = Service::create([ 'customer_id' => $customer->id, 'type' => 'hosting', 'server_name' => 'hosting.example.vn', 'status' => 'cancelled', ]); $domain = Service::create([ 'customer_id' => $customer->id, 'type' => 'domain', 'server_name' => 'example.vn', 'status' => 'active', ]); $dnsServerId = DB::table('dns_manager_servers')->insertGetId([ 'ip_address' => '10.0.0.1', 'password' => 'x', ]); $dnsDomain = DnsDomain::create([ 'domain_name' => 'example.vn', 'dns_manager_server_id' => $dnsServerId, 'is_created' => DnsDomain::STATUS_CREATED, ]); $dnsDomain->customer()->attach($customer->id); DnsManagerNS::create([ 'dns_manager_domain_id' => $dnsDomain->id, 'type' => 'A', 'type_valid' => 'A', 'name' => 'example.vn', 'value' => '10.0.0.2', 'ttl' => 300, ]); Service::create([ 'customer_id' => $otherCustomer->id, 'type' => 'vps', 'server_name' => 'private.example.vn', 'status' => 'active', ]); $response = $this->actingAs($customer, 'client') ->withHeaders(['x-access-token' => $this->buildClientAccessToken()]) ->getJson('/v1/client/client-service') ->assertOk() ->assertJsonPath('error', false) ->assertJsonCount(3, 'data.items'); $items = collect($response->json('data.items'))->keyBy('uuid'); $this->assertSame('vps', $items[$vps->uuid]['type']); $this->assertSame('hosting', $items[$hosting->uuid]['type']); $this->assertSame(1, $items[$domain->uuid]['dns_records_count']); $this->assertFalse($items->contains('server_name', 'private.example.vn')); $this->assertSame(['os', 'specs'], array_values(array_intersect( array_keys($items[$vps->uuid]), ['os', 'specs', 'service_plan', 'dns_records_count'], ))); $this->assertSame(['service_plan'], array_values(array_intersect( array_keys($items[$hosting->uuid]), ['os', 'specs', 'service_plan', 'dns_records_count'], ))); $this->assertSame(['dns_records_count'], array_values(array_intersect( array_keys($items[$domain->uuid]), ['os', 'specs', 'service_plan', 'dns_records_count'], ))); } }