feat(form-builder): retry/resolve/dismiss artisan commands (WS-6)
Three CLI commands for ops use, mirroring the API endpoints in Task 9: - form-failures:retry (id|submission|org filter, --dry-run) - form-failures:resolve (single id, optional note) - form-failures:dismiss (single id, DismissalReasonType + note) Cross-tenant isolation enforced via form_submissions.organisation_id FK chain (RFC V3). retry_count incremented on retry; failure history preserved (new row on repeat failure, not in-place mutation). Refs: RFC-WS-6.md §3 (Q5), §4 (V2, V3) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Commands;
|
||||
|
||||
use App\Enums\FormBuilder\DismissalReasonType;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailure;
|
||||
use App\Models\Organisation;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class FormFailuresCommandsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_resolve_marks_failure_resolved_with_note(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->create();
|
||||
|
||||
$this->artisan('form-failures:resolve', ['id' => $failure->id, '--note' => 'fixed via console'])
|
||||
->expectsConfirmation("Resolve failure {$failure->id}?", 'yes')
|
||||
->expectsOutput("Resolved failure {$failure->id}.")
|
||||
->assertSuccessful();
|
||||
|
||||
$reloaded = FormSubmissionActionFailure::query()->find($failure->id);
|
||||
$this->assertNotNull($reloaded->resolved_at);
|
||||
$this->assertSame('fixed via console', $reloaded->resolved_note);
|
||||
}
|
||||
|
||||
public function test_resolve_no_op_on_already_resolved(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->resolved()->create();
|
||||
|
||||
$this->artisan('form-failures:resolve', ['id' => $failure->id])
|
||||
->expectsOutput("Failure {$failure->id} already resolved at {$failure->resolved_at}; no-op.")
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_resolve_skips_already_dismissed(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->dismissed()->create();
|
||||
|
||||
$this->artisan('form-failures:resolve', ['id' => $failure->id])
|
||||
->expectsOutput("Failure {$failure->id} already dismissed at {$failure->dismissed_at}; cannot resolve.")
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
public function test_dismiss_with_enum_reason(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->create();
|
||||
|
||||
$this->artisan('form-failures:dismiss', [
|
||||
'id' => $failure->id,
|
||||
'--reason' => DismissalReasonType::SCHEMA_DELETED->value,
|
||||
])->assertSuccessful();
|
||||
|
||||
$reloaded = FormSubmissionActionFailure::query()->find($failure->id);
|
||||
$this->assertNotNull($reloaded->dismissed_at);
|
||||
$this->assertSame(DismissalReasonType::SCHEMA_DELETED, $reloaded->dismissed_reason_type);
|
||||
}
|
||||
|
||||
public function test_dismiss_other_without_note_fails(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->create();
|
||||
|
||||
$this->artisan('form-failures:dismiss', [
|
||||
'id' => $failure->id,
|
||||
'--reason' => DismissalReasonType::OTHER->value,
|
||||
])->assertFailed();
|
||||
}
|
||||
|
||||
public function test_dismiss_other_with_note_succeeds(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->create();
|
||||
|
||||
$this->artisan('form-failures:dismiss', [
|
||||
'id' => $failure->id,
|
||||
'--reason' => DismissalReasonType::OTHER->value,
|
||||
'--note' => 'manual investigation closed it',
|
||||
])->assertSuccessful();
|
||||
|
||||
$reloaded = FormSubmissionActionFailure::query()->find($failure->id);
|
||||
$this->assertSame('manual investigation closed it', $reloaded->dismissed_reason_note);
|
||||
}
|
||||
|
||||
public function test_retry_dry_run_does_not_modify_state(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->create();
|
||||
|
||||
$this->artisan('form-failures:retry', ['--id' => $failure->id, '--dry-run' => true])
|
||||
->assertSuccessful();
|
||||
|
||||
$reloaded = FormSubmissionActionFailure::query()->find($failure->id);
|
||||
$this->assertNull($reloaded->resolved_at);
|
||||
$this->assertSame(0, $reloaded->retry_count);
|
||||
}
|
||||
|
||||
public function test_retry_requires_at_least_one_filter(): void
|
||||
{
|
||||
$this->artisan('form-failures:retry')
|
||||
->expectsOutput('At least one of --id, --submission, or --org is required.')
|
||||
->assertFailed();
|
||||
}
|
||||
|
||||
public function test_retry_by_org_isolates_to_that_organisation(): void
|
||||
{
|
||||
$orgA = Organisation::factory()->create();
|
||||
$orgB = Organisation::factory()->create();
|
||||
|
||||
$submissionA = FormSubmission::factory()->forOrganisation($orgA)->create();
|
||||
$submissionB = FormSubmission::factory()->forOrganisation($orgB)->create();
|
||||
|
||||
$failureA = FormSubmissionActionFailure::factory()
|
||||
->for($submissionA, 'submission')
|
||||
->create();
|
||||
$failureB = FormSubmissionActionFailure::factory()
|
||||
->for($submissionB, 'submission')
|
||||
->create();
|
||||
|
||||
// Dry-run isolates risk; we just verify the filter works.
|
||||
$this->artisan('form-failures:retry', ['--org' => $orgA->id, '--dry-run' => true])
|
||||
->expectsOutputToContain((string) $failureA->id)
|
||||
->doesntExpectOutputToContain((string) $failureB->id)
|
||||
->assertSuccessful();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user