active()->create(['dns_record_id' => null]); $this->artisan('clupilot:prune-host-dns') ->assertSuccessful() ->expectsOutputToContain('Nothing to do'); }); it('without --force only reports what it would delete, and changes nothing', function () { $s = fakeServices(); $recordId = $s['dns']->upsertRecord('fsn-legacy.node.clupilot.com', 'A', '10.66.0.55'); $host = Host::factory()->active()->create(['dns_record_id' => $recordId]); $this->artisan('clupilot:prune-host-dns')->assertSuccessful(); expect($host->fresh()->dns_record_id)->toBe($recordId) ->and($s['dns']->records)->toHaveKey('fsn-legacy.node.clupilot.com'); }); it('with --force deletes the record and clears the column', function () { $s = fakeServices(); $recordId = $s['dns']->upsertRecord('fsn-legacy.node.clupilot.com', 'A', '10.66.0.55'); $host = Host::factory()->active()->create(['dns_record_id' => $recordId]); $this->artisan('clupilot:prune-host-dns --force')->assertSuccessful(); expect($host->fresh()->dns_record_id)->toBeNull() ->and($s['dns']->records)->not->toHaveKey('fsn-legacy.node.clupilot.com'); }); it('with --force leaves the id in place when the provider refuses the deletion', function () { $s = fakeServices(); $recordId = $s['dns']->upsertRecord('fsn-legacy.node.clupilot.com', 'A', '10.66.0.55'); $host = Host::factory()->active()->create(['dns_record_id' => $recordId]); $s['dns']->failDelete = true; // A failed provider call must not silently forget which record still // needs cleaning up — nulling the column here would do exactly that. $this->artisan('clupilot:prune-host-dns --force')->assertFailed(); expect($host->fresh()->dns_record_id)->toBe($recordId); });