'Full Administrator', 'guard_name' => 'admin']); $this->admin = User::factory()->create(); $this->admin->assignRole('Full Administrator'); $this->customer = Customer::factory()->create(); $this->product = Product::factory()->create(['product_type' => 'domain']); } private function createService(string $serverName): Service { $this->actingAs($this->admin, 'admin')->postJson( "/api/v1/administrator/customers/{$this->customer->uuid}/services", ['product_id' => $this->product->id, 'payment_method' => 'transfer', 'server_name' => $serverName, 'amount_paid' => 0], )->assertCreated(); return Service::where('server_name', $serverName)->firstOrFail(); } public function test_deleting_service_hides_its_order_and_invoices(): void { $kept = $this->createService('kept.vn'); $removed = $this->createService('removed.vn'); $removedOrderId = $removed->orderItem->order_id; $this->actingAs($this->admin, 'admin')->postJson( "/api/v1/administrator/customers/{$this->customer->uuid}/services/bulk-delete", ['ids' => [$removed->id]], )->assertOk(); $this->assertSoftDeleted('orders', ['id' => $removedOrderId]); $this->assertSoftDeleted('invoices', ['order_id' => $removedOrderId]); $this->assertSame([$kept->orderItem->order_id], Order::pluck('id')->all()); $this->assertSame(1, Invoice::count()); } public function test_recreating_same_service_discards_previous_order(): void { $first = $this->createService('same.vn'); $firstOrderId = $first->orderItem->order_id; $second = $this->createService('same.vn'); $this->assertSame($first->id, $second->id); $this->assertSoftDeleted('orders', ['id' => $firstOrderId]); $this->assertSame([$second->orderItem->order_id], Order::pluck('id')->all()); $this->assertSame(1, Invoice::count()); } }