feat(form-builder): retry history table + integration (WS-6)
Per-attempt retry history (timestamp, user, outcome, exception detail
if failed) replaces the counter-only retry_count tracking.
Changes:
- New `form_submission_action_failure_retry_attempts` table (cascade on
parent delete, nullOnDelete on user). Explicit short FK names
(`fsafra_failure_fk`, `fsafra_user_fk`) — auto-generated names exceed
MySQL's 64-char identifier limit.
- New FormSubmissionActionFailureRetryAttempt model + factory +
succeeded() state.
- Parent FormSubmissionActionFailure gets retryAttempts() HasMany
relation (latest('attempted_at')).
- New FormFailureRetryService centralises the retry-flow logic. Both
the API controller and the artisan command delegate to it. Service
writes a retry_attempt record per attempt; parent's retry_count
stays as denormalised cache for index-view performance.
- Successful retry: attempt(succeeded) + parent.retry_count++ +
parent.resolved_at + parent.resolved_by_user_id + parent.resolved_note
("Geslaagde retry door {actor.name}" or "Geslaagde retry
(geautomatiseerd)" for command-line invocation without an actor).
- Failed retry: attempt(failed) with NEW exception details +
parent.retry_count++. Parent's exception_class/_message stay
audit-immutable — they represent the FIRST failure.
- canBeRetried() now correctly checks both resolved_at AND
dismissed_at (sessie 2's open question Q2 closure).
- New FailureNotRetriableException (controller → 422) and
ParentSubmissionGoneException (controller → 410) for cleaner
flow control.
12 new tests:
- FormSubmissionActionFailureRetryAttemptTest (5 unit tests)
- RetryFlowProducesRetryAttemptsTest (7 integration tests covering
succeeded path, failed path, resolved/dismissed blocking,
multiple-retries chronological ordering, canBeRetried truth tables)
Pre-existing tests touched:
- FormSubmissionActionFailureTest::test_can_be_retried_only_for_open_state
— updated to reflect Q2 closure (resolved now blocks too).
- Ws6FoundationMigrationTest::test_down_methods_clean_up_columns_and_table
— child table must drop before parent (FK constraint).
- 5 backfill test step-counts bumped +1 (new migration sits at top).
SCHEMA.md → v2.9. Schema dump regenerated.
Refs: RFC-WS-6.md §3 Q5 addendum, sessie 2 Q2
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -57,7 +57,7 @@ final class FormFieldBindingMigrationTest extends TestCase
|
||||
// validation-rules-backfill, create-validation-rules) +
|
||||
// 2 WS-6 migrations (action-failures, apply-status) +
|
||||
// 2 WS-5a migrations (drop-binding-cols, create-bindings) = 16.
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 20])->assertSuccessful();
|
||||
$this->assertFalse(Schema::hasTable('form_field_bindings'));
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'binding'));
|
||||
$this->assertTrue(Schema::hasColumn('form_field_library', 'default_binding'));
|
||||
@@ -119,7 +119,7 @@ final class FormFieldBindingMigrationTest extends TestCase
|
||||
public function test_rollback_reconstructs_json_and_drops_table(): void
|
||||
{
|
||||
// Walk back the full WS-5d + WS-5c + WS-6 + WS-5b + WS-5a stack (16 migrations).
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 20])->assertSuccessful();
|
||||
[$fieldAId] = $this->seedFieldsWithBindingJson();
|
||||
[$libAId] = $this->seedLibraryWithBindingJson();
|
||||
|
||||
@@ -134,7 +134,7 @@ final class FormFieldBindingMigrationTest extends TestCase
|
||||
// the pre-WS-5b state (conditional-logic, validation-rules, configs
|
||||
// and options tables gone, validation_rules + options JSON columns
|
||||
// reappear on source tables; binding contract intact).
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
$this->assertFalse(Schema::hasTable('form_field_options'));
|
||||
$this->assertFalse(Schema::hasTable('form_field_conditional_logic_groups'));
|
||||
$this->assertFalse(Schema::hasTable('form_field_conditional_logic_conditions'));
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Bindings;
|
||||
|
||||
use App\Enums\FormBuilder\FormPurpose;
|
||||
use App\Exceptions\FormBuilder\FailureNotRetriableException;
|
||||
use App\FormBuilder\Bindings\BindingPassResult;
|
||||
use App\FormBuilder\Bindings\FormBindingApplicator;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailure;
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailureRetryAttempt;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
use App\Services\FormBuilder\FormFailureRetryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Sessie 3c — covers the integration between FormFailureRetryService,
|
||||
* the parent FormSubmissionActionFailure model, and the new
|
||||
* FormSubmissionActionFailureRetryAttempt records.
|
||||
*/
|
||||
final class RetryFlowProducesRetryAttemptsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function makeFailure(): FormSubmissionActionFailure
|
||||
{
|
||||
$org = Organisation::factory()->create();
|
||||
$schema = FormSchema::factory()->create([
|
||||
'organisation_id' => $org->id,
|
||||
'purpose' => FormPurpose::EVENT_REGISTRATION->value,
|
||||
]);
|
||||
$submission = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $schema->id,
|
||||
'organisation_id' => $org->id,
|
||||
]);
|
||||
|
||||
return FormSubmissionActionFailure::factory()
|
||||
->for($submission, 'submission')
|
||||
->create([
|
||||
'exception_class' => 'OriginalException',
|
||||
'exception_message' => 'first failure message',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(FormSubmission, ?string): BindingPassResult $apply
|
||||
*/
|
||||
private function bindApplicator(callable $apply): void
|
||||
{
|
||||
// The applicator is `class` (not final/not readonly) specifically so
|
||||
// listener tests can extend and override apply(). We use the same
|
||||
// override mechanism here. Properties on the parent are readonly
|
||||
// promoted constructor params; we skip parent::__construct because
|
||||
// we override the ONLY method (apply) that touches them.
|
||||
$stub = new class($apply) extends FormBindingApplicator {
|
||||
/** @var callable(FormSubmission, ?string): BindingPassResult */
|
||||
private $apply;
|
||||
|
||||
/** @param callable(FormSubmission, ?string): BindingPassResult $apply */
|
||||
public function __construct(callable $apply)
|
||||
{
|
||||
$this->apply = $apply;
|
||||
}
|
||||
|
||||
public function apply(FormSubmission $submission, ?string $sectionId = null): BindingPassResult
|
||||
{
|
||||
return ($this->apply)($submission, $sectionId);
|
||||
}
|
||||
};
|
||||
$this->app->instance(FormBindingApplicator::class, $stub);
|
||||
}
|
||||
|
||||
public function test_successful_retry_creates_succeeded_attempt_and_resolves_parent(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
$actor = User::factory()->create(['first_name' => 'Maud', 'last_name' => 'Admin']);
|
||||
|
||||
// Applicator returns a real BindingPassResult that maps to COMPLETED.
|
||||
$this->bindApplicator(fn (): BindingPassResult => new BindingPassResult(
|
||||
formSubmissionId: (string) $failure->form_submission_id,
|
||||
provisionedSubjectType: 'person',
|
||||
provisionedSubjectId: (string) \Illuminate\Support\Str::ulid(),
|
||||
applications: [],
|
||||
));
|
||||
|
||||
$service = $this->app->make(FormFailureRetryService::class);
|
||||
$result = $service->retry($failure, $actor);
|
||||
|
||||
$this->assertSame('succeeded', $result['outcome']);
|
||||
|
||||
$failure->refresh();
|
||||
$this->assertNotNull($failure->resolved_at);
|
||||
$this->assertSame((string) $actor->id, (string) $failure->resolved_by_user_id);
|
||||
$this->assertSame('Geslaagde retry door Maud Admin', $failure->resolved_note);
|
||||
$this->assertSame(1, $failure->retry_count);
|
||||
|
||||
$attempts = FormSubmissionActionFailureRetryAttempt::query()
|
||||
->where('form_submission_action_failure_id', $failure->id)
|
||||
->get();
|
||||
$this->assertCount(1, $attempts);
|
||||
$this->assertSame('succeeded', $attempts[0]->outcome);
|
||||
$this->assertNull($attempts[0]->exception_class);
|
||||
|
||||
// Parent's original exception fields stay audit-immutable.
|
||||
$this->assertSame('OriginalException', $failure->exception_class);
|
||||
$this->assertSame('first failure message', $failure->exception_message);
|
||||
}
|
||||
|
||||
public function test_failed_retry_creates_failed_attempt_and_keeps_parent_open(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
|
||||
$this->bindApplicator(function (): never {
|
||||
throw new RuntimeException('NEW exception on retry');
|
||||
});
|
||||
|
||||
$service = $this->app->make(FormFailureRetryService::class);
|
||||
$result = $service->retry($failure);
|
||||
|
||||
$this->assertSame('failed', $result['outcome']);
|
||||
|
||||
$failure->refresh();
|
||||
$this->assertNull($failure->resolved_at);
|
||||
$this->assertNull($failure->dismissed_at);
|
||||
$this->assertSame(1, $failure->retry_count);
|
||||
// Parent's original exception fields untouched (audit-immutable).
|
||||
$this->assertSame('OriginalException', $failure->exception_class);
|
||||
$this->assertSame('first failure message', $failure->exception_message);
|
||||
|
||||
$attempts = FormSubmissionActionFailureRetryAttempt::query()
|
||||
->where('form_submission_action_failure_id', $failure->id)
|
||||
->get();
|
||||
$this->assertCount(1, $attempts);
|
||||
$this->assertSame('failed', $attempts[0]->outcome);
|
||||
$this->assertSame(RuntimeException::class, $attempts[0]->exception_class);
|
||||
$this->assertSame('NEW exception on retry', $attempts[0]->exception_message);
|
||||
}
|
||||
|
||||
public function test_retry_on_resolved_failure_throws(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
$failure->update(['resolved_at' => now(), 'resolved_note' => 'manual fix']);
|
||||
|
||||
$service = $this->app->make(FormFailureRetryService::class);
|
||||
|
||||
$this->expectException(FailureNotRetriableException::class);
|
||||
$service->retry($failure);
|
||||
}
|
||||
|
||||
public function test_retry_on_dismissed_failure_throws(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
$failure->update([
|
||||
'dismissed_at' => now(),
|
||||
'dismissed_reason_type' => 'schema_deleted',
|
||||
]);
|
||||
|
||||
$service = $this->app->make(FormFailureRetryService::class);
|
||||
|
||||
$this->expectException(FailureNotRetriableException::class);
|
||||
$service->retry($failure);
|
||||
}
|
||||
|
||||
public function test_multiple_retries_produce_chronologically_ordered_attempts(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
|
||||
$callCount = 0;
|
||||
$this->bindApplicator(function () use (&$callCount): never {
|
||||
$callCount++;
|
||||
throw new RuntimeException("attempt #{$callCount}");
|
||||
});
|
||||
|
||||
$service = $this->app->make(FormFailureRetryService::class);
|
||||
$service->retry($failure);
|
||||
$failure->refresh();
|
||||
$service->retry($failure);
|
||||
$failure->refresh();
|
||||
$service->retry($failure);
|
||||
|
||||
$failure->refresh();
|
||||
$this->assertSame(3, $failure->retry_count);
|
||||
$this->assertNull($failure->resolved_at);
|
||||
|
||||
$attempts = FormSubmissionActionFailureRetryAttempt::query()
|
||||
->where('form_submission_action_failure_id', $failure->id)
|
||||
->oldest('attempted_at')
|
||||
->get();
|
||||
$this->assertCount(3, $attempts);
|
||||
$this->assertSame('attempt #1', $attempts[0]->exception_message);
|
||||
$this->assertSame('attempt #2', $attempts[1]->exception_message);
|
||||
$this->assertSame('attempt #3', $attempts[2]->exception_message);
|
||||
}
|
||||
|
||||
public function test_can_be_retried_blocks_resolved_state(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
$this->assertTrue($failure->canBeRetried());
|
||||
|
||||
$failure->update(['resolved_at' => now()]);
|
||||
$this->assertFalse($failure->fresh()->canBeRetried());
|
||||
}
|
||||
|
||||
public function test_can_be_retried_blocks_dismissed_state(): void
|
||||
{
|
||||
$failure = $this->makeFailure();
|
||||
$failure->update(['dismissed_at' => now(), 'dismissed_reason_type' => 'schema_deleted']);
|
||||
|
||||
$this->assertFalse($failure->fresh()->canBeRetried());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,7 +49,7 @@ final class ConditionalLogicBackfillTest extends TestCase
|
||||
// create-options + WS-5c drop-cl-col + WS-5c backfill-cl
|
||||
// migrations to land in the conditional-logic JSON-era state with
|
||||
// no relational form_field_options table yet.
|
||||
$this->artisan('migrate:rollback', ['--step' => 8])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 9])->assertSuccessful();
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'conditional_logic'));
|
||||
|
||||
$fieldId = $this->seedFieldWithJson([
|
||||
@@ -170,7 +170,7 @@ final class ConditionalLogicBackfillTest extends TestCase
|
||||
]);
|
||||
|
||||
// Roll back only the backfill migration — writes the JSON back.
|
||||
$this->artisan('migrate:rollback', ['--step' => 8])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 9])->assertSuccessful();
|
||||
|
||||
$reconstructed = DB::table('form_fields')
|
||||
->where('id', $fieldId)
|
||||
@@ -203,7 +203,7 @@ final class ConditionalLogicBackfillTest extends TestCase
|
||||
|
||||
public function test_unknown_top_level_key_fails_migration(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 8])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 9])->assertSuccessful();
|
||||
|
||||
$this->seedFieldWithJson([
|
||||
'hide_when' => ['all' => [['field_slug' => 'x', 'operator' => 'equals', 'value' => 1]]],
|
||||
@@ -216,7 +216,7 @@ final class ConditionalLogicBackfillTest extends TestCase
|
||||
|
||||
public function test_unknown_comparison_operator_fails_migration(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 8])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 9])->assertSuccessful();
|
||||
|
||||
$this->seedFieldWithJson([
|
||||
'show_when' => ['all' => [['field_slug' => 'x', 'operator' => 'matches_regex', 'value' => 'y']]],
|
||||
|
||||
@@ -30,7 +30,7 @@ final class FormFieldConfigBackfillAndDropTest extends TestCase
|
||||
// Roll back 4 WS-5c migrations + 2 WS-6 migrations + 5 WS-5b
|
||||
// migrations = 11, to get the pre-WS-5b state where the JSON column
|
||||
// still exists on form_fields / form_field_library.
|
||||
$this->artisan('migrate:rollback', ['--step' => 14])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 15])->assertSuccessful();
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'validation_rules'));
|
||||
|
||||
$fieldId = $this->seedField([
|
||||
|
||||
@@ -47,7 +47,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
// Roll back only the backfill migration (latest WS-5d step).
|
||||
// Leaves the form_field_options table in place, JSON columns
|
||||
// present on the source tables, and snapshots in pre-WS-5d shape.
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->assertTrue(Schema::hasTable('form_field_options'));
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'options'));
|
||||
|
||||
@@ -136,7 +136,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_rollback_reconstructs_json_columns_and_snapshots(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
[$selectId, $multiId, $libraryId] = $this->seedFieldsAndLibraryWithJson();
|
||||
$submissionId = $this->seedSubmissionWithSnapshot($selectId);
|
||||
|
||||
@@ -149,7 +149,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
// Step back over only the backfill migration → JSON columns repopulate
|
||||
// and snapshots revert to flat-string-array shape.
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->assertSame(0, DB::table('form_field_options')->count());
|
||||
|
||||
$select = DB::table('form_fields')->where('id', $selectId)->first();
|
||||
@@ -168,7 +168,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_when_options_present_on_non_option_field_type(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->seedFieldWithOptions('TAG_PICKER', ['Veiligheid', 'Horeca']);
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
@@ -178,7 +178,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_when_options_contains_non_string_entry(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
|
||||
$this->seedFieldWithOptionsRaw('SELECT', json_encode([
|
||||
['label' => 'A'],
|
||||
@@ -192,7 +192,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_when_options_is_object_shape(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
|
||||
$this->seedFieldWithOptionsRaw('SELECT', json_encode([
|
||||
'XS' => 'Extra small',
|
||||
@@ -206,7 +206,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_on_translations_length_mismatch(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->seedFieldWithOptionsRaw('SELECT', json_encode(['XS', 'S', 'M']), json_encode([
|
||||
'de' => ['options' => ['Klein', 'Mittel']], // 2 vs 3
|
||||
]));
|
||||
@@ -218,7 +218,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_on_non_string_translation(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->seedFieldWithOptionsRaw('SELECT', json_encode(['XS', 'S']), json_encode([
|
||||
'de' => ['options' => ['Klein', 42]],
|
||||
]));
|
||||
@@ -230,7 +230,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_on_oversized_translation(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->seedFieldWithOptionsRaw('SELECT', json_encode(['XS']), json_encode([
|
||||
'de' => ['options' => [str_repeat('x', 256)]],
|
||||
]));
|
||||
@@ -242,7 +242,7 @@ final class FormFieldOptionsBackfillTest extends TestCase
|
||||
|
||||
public function test_fails_when_snapshot_options_present_on_non_option_field_type(): void
|
||||
{
|
||||
$this->artisan('migrate:rollback', ['--step' => 4])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 5])->assertSuccessful();
|
||||
$this->seedTemplateWithSnapshotRaw([
|
||||
'fields' => [[
|
||||
'id' => (string) Str::ulid(),
|
||||
|
||||
@@ -110,7 +110,13 @@ final class Ws6FoundationMigrationTest extends TestCase
|
||||
$applyStatus = require database_path(
|
||||
'migrations/2026_04_25_140000_extend_form_submissions_with_apply_status.php',
|
||||
);
|
||||
// Sessie 3c added a child table referencing form_submission_action_failures
|
||||
// via FK; we must drop the child before downing the parent.
|
||||
$retryAttempts = require database_path(
|
||||
'migrations/2026_04_28_180000_create_form_submission_action_failure_retry_attempts_table.php',
|
||||
);
|
||||
|
||||
$retryAttempts->down();
|
||||
$createFailures->down();
|
||||
$applyStatus->down();
|
||||
|
||||
@@ -118,6 +124,7 @@ final class Ws6FoundationMigrationTest extends TestCase
|
||||
$this->assertFalse(Schema::hasColumn('form_submissions', 'apply_status'));
|
||||
$this->assertFalse(Schema::hasColumn('form_submissions', 'apply_completed_at'));
|
||||
$this->assertFalse(Schema::hasTable('form_submission_action_failures'));
|
||||
$this->assertFalse(Schema::hasTable('form_submission_action_failure_retry_attempts'));
|
||||
|
||||
$indexes = $this->indexNamesFor('form_submissions');
|
||||
$this->assertNotContains('fs_schema_apply_status_idx', $indexes);
|
||||
@@ -126,6 +133,7 @@ final class Ws6FoundationMigrationTest extends TestCase
|
||||
// Restore state for any subsequent tests in this class.
|
||||
$applyStatus->up();
|
||||
$createFailures->up();
|
||||
$retryAttempts->up();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
// validation-rules-backfill + create-validation-rules) = 14.
|
||||
// Brings us to the pre-WS-5b state: validation_rules JSON column
|
||||
// present, no relational tables for WS-5b/c/d.
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
$this->assertFalse(Schema::hasTable('form_field_validation_rules'));
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'validation_rules'));
|
||||
|
||||
@@ -114,7 +114,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
// (validation_rules JSON column present; no relational tables for
|
||||
// WS-5b). Step count: drop-cols + configs-backfill + create-configs
|
||||
// + validation-rules-backfill + create-validation-rules = 5.
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
|
||||
$fieldId = $this->seedFieldWithJson([
|
||||
'field_type' => 'TAG_PICKER',
|
||||
@@ -138,7 +138,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
// (validation_rules JSON column present; no relational tables for
|
||||
// WS-5b). Step count: drop-cols + configs-backfill + create-configs
|
||||
// + validation-rules-backfill + create-validation-rules = 5.
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
|
||||
$fieldId = $this->seedFieldWithJson([
|
||||
'field_type' => 'TEXT',
|
||||
@@ -165,7 +165,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
// (validation_rules JSON column present; no relational tables for
|
||||
// WS-5b). Step count: drop-cols + configs-backfill + create-configs
|
||||
// + validation-rules-backfill + create-validation-rules = 5.
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
|
||||
$this->seedFieldWithJson([
|
||||
'field_type' => 'TEXT',
|
||||
@@ -182,7 +182,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
// (validation_rules JSON column present; no relational tables for
|
||||
// WS-5b). Step count: drop-cols + configs-backfill + create-configs
|
||||
// + validation-rules-backfill + create-validation-rules = 5.
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
|
||||
$this->seedFieldWithJson([
|
||||
'field_type' => 'BOOLEAN',
|
||||
@@ -201,7 +201,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
// full-back-then-full-forward cycle — rolling back all WS-5b
|
||||
// migrations restores the pre-WS-5b state (columns present on
|
||||
// source tables; validation rules relational table gone).
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
[$numberId] = $this->seedFields();
|
||||
|
||||
$this->artisan('migrate')->assertSuccessful();
|
||||
@@ -216,7 +216,7 @@ final class FormFieldValidationRuleBackfillTest extends TestCase
|
||||
|
||||
// Roll back WS-5b fully → column reappears and carries canonical JSON
|
||||
// reconstructed from the relational rows.
|
||||
$this->artisan('migrate:rollback', ['--step' => 17])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 18])->assertSuccessful();
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'validation_rules'));
|
||||
|
||||
$field = DB::table('form_fields')->where('id', $numberId)->first();
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Models\FormBuilder;
|
||||
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailure;
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailureRetryAttempt;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
final class FormSubmissionActionFailureRetryAttemptTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_factory_creates_a_valid_record(): void
|
||||
{
|
||||
$attempt = FormSubmissionActionFailureRetryAttempt::factory()->create();
|
||||
|
||||
$this->assertSame('failed', $attempt->outcome);
|
||||
$this->assertNotEmpty($attempt->exception_class);
|
||||
$this->assertNotEmpty($attempt->exception_message);
|
||||
}
|
||||
|
||||
public function test_failure_relation_resolves_to_the_parent(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()->create();
|
||||
$attempt = FormSubmissionActionFailureRetryAttempt::factory()
|
||||
->for($failure, 'failure')
|
||||
->create();
|
||||
|
||||
$this->assertSame((string) $failure->id, (string) $attempt->failure->id);
|
||||
}
|
||||
|
||||
public function test_attempted_by_relation_resolves_to_the_user(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$attempt = FormSubmissionActionFailureRetryAttempt::factory()
|
||||
->state(['attempted_by_user_id' => $user->id])
|
||||
->create();
|
||||
|
||||
$this->assertSame((string) $user->id, (string) $attempt->attemptedBy->id);
|
||||
}
|
||||
|
||||
public function test_succeeded_state_produces_null_exception_fields(): void
|
||||
{
|
||||
$attempt = FormSubmissionActionFailureRetryAttempt::factory()->succeeded()->create();
|
||||
|
||||
$this->assertSame('succeeded', $attempt->outcome);
|
||||
$this->assertNull($attempt->exception_class);
|
||||
$this->assertNull($attempt->exception_message);
|
||||
}
|
||||
|
||||
public function test_attempted_at_is_cast_to_datetime(): void
|
||||
{
|
||||
$attempt = FormSubmissionActionFailureRetryAttempt::factory()->create();
|
||||
|
||||
$this->assertInstanceOf(\Illuminate\Support\Carbon::class, $attempt->attempted_at);
|
||||
}
|
||||
}
|
||||
@@ -74,14 +74,16 @@ final class FormSubmissionActionFailureTest extends TestCase
|
||||
$this->assertSame('company', $reloaded->context['target_entity']);
|
||||
}
|
||||
|
||||
public function test_can_be_retried_false_when_dismissed(): void
|
||||
public function test_can_be_retried_only_for_open_state(): void
|
||||
{
|
||||
// Sessie 3c (Q2 closure): both resolved AND dismissed block retry.
|
||||
// Open is the only retriable state.
|
||||
$open = FormSubmissionActionFailure::factory()->create();
|
||||
$resolved = FormSubmissionActionFailure::factory()->resolved()->create();
|
||||
$dismissed = FormSubmissionActionFailure::factory()->dismissed()->create();
|
||||
|
||||
$this->assertTrue($open->canBeRetried());
|
||||
$this->assertTrue($resolved->canBeRetried());
|
||||
$this->assertFalse($resolved->canBeRetried());
|
||||
$this->assertFalse($dismissed->canBeRetried());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user