create(); $serverId = DB::table('dns_manager_servers')->insertGetId([ 'ip_address' => '10.0.0.1', 'password' => 'x', ]); $domain = DnsDomain::create([ 'domain_name' => 'devro-tech.com', 'dns_manager_server_id' => $serverId, 'is_created' => DnsDomain::STATUS_CREATED, ]); DomainPricing::query()->delete(); DomainPricing::create(['type' => 'domain', 'tld' => '.com', 'setup_fee' => '0', 'first_year' => 320_000, 'recurring_fee' => '340000', 'is_active' => true]); $product = Product::factory()->create(['product_type' => 'domain', 'is_active' => true]); $sync = app(CustomerDomainServiceSync::class); $sync->syncCustomers($domain, [$customer->id]); $service = Service::query() ->where('customer_id', $customer->id) ->where('type', 'domain') ->where('server_name', 'devro-tech.com') ->firstOrFail(); $this->assertSame('active', $service->status); $this->assertSame(CustomerDomainServiceSync::AUTO_CREATED_NOTE, $service->note); $this->assertSame($product->id, $service->product_id); $this->assertSame('devro-tech.com', $service->orderItem->domain_name); $this->assertSame(320_000, (int) $service->orderItem->price); $this->assertSame('annually', $service->orderItem->billing_cycle); $this->assertSame(1, (int) $service->invoice->status); $this->assertSame(320_000, (int) $service->invoice->total); $sync->syncCustomers($domain, [$customer->id]); $this->assertSame(1, Service::query()->where('customer_id', $customer->id)->count()); $this->assertSame(1, $service->orderItem->order()->count()); $this->assertDatabaseCount('invoices', 1); $sync->updateCustomerDomain($domain, $customer->id, '2027-07-21'); $this->assertSame('2027-07-21', $service->fresh()->expires_at?->toDateString()); $sync->syncCustomers($domain, []); $this->assertSoftDeleted('services', ['id' => $service->id]); $this->assertSame(3, (int) $service->invoice->fresh()->status); $this->assertDatabaseMissing('dns_domain_user', [ 'domain_id' => $domain->id, 'user_id' => $customer->id, ]); } public function test_apply_term_sets_dates_and_cycle_for_domain_services(): void { $customer = Customer::factory()->create(); $serverId = DB::table('dns_manager_servers')->insertGetId(['ip_address' => '10.0.0.1', 'password' => 'x']); $domain = DnsDomain::create([ 'domain_name' => 'devro-tech.com', 'dns_manager_server_id' => $serverId, 'is_created' => DnsDomain::STATUS_CREATED, ]); Product::factory()->create(['product_type' => 'domain', 'is_active' => true]); $sync = app(CustomerDomainServiceSync::class); $sync->syncCustomers($domain, [$customer->id]); $updated = $sync->applyTerm($domain, '2025-06-17', '2027-06-17', 2); $service = Service::where('customer_id', $customer->id)->where('type', 'domain')->firstOrFail(); $this->assertSame(1, $updated); $this->assertSame('2025-06-17', $service->started_at->toDateString()); $this->assertSame('2027-06-17', $service->expires_at->toDateString()); $this->assertSame(24, (int) $service->orderItem->months); $this->assertSame('biennially', $service->orderItem->billing_cycle); $this->assertSame(0, $sync->applyTerm(DnsDomain::create(['domain_name' => 'solo.vn', 'dns_manager_server_id' => $serverId]), null, null, 1)); } }