feat(form-builder): FormSubmission cast + factory state for failure_response_code

Per RFC-WS-6 §Q3 v1.3 addition 2.

- Added 'failure_response_code' to FormSubmission $fillable + 'string' cast.
  Plain string (not enum) — the exception subclass on
  form_submission_action_failures is the canonical classification source;
  this column is a denormalised mirror for response-shape rendering.
- Factory fluent state method withFailureResponseCode() with documentation
  of the four valid values.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-08 02:00:18 +02:00
parent 1f66fef3c8
commit 96062b9182
2 changed files with 27 additions and 2 deletions

View File

@@ -11,9 +11,9 @@ use App\Models\Event;
use App\Models\Organisation;
use App\Models\Scopes\OrganisationScope;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -32,7 +32,7 @@ final class FormSubmission extends Model
protected static function booted(): void
{
static::addGlobalScope(new OrganisationScope());
self::addGlobalScope(new OrganisationScope);
}
/** @return array{column: string} */
@@ -72,6 +72,7 @@ final class FormSubmission extends Model
'first_interacted_at',
'idempotency_key',
'identity_match_status',
'failure_response_code',
];
/** @var array<string, string> */
@@ -80,6 +81,11 @@ final class FormSubmission extends Model
'review_status' => FormSubmissionReviewStatus::class,
'apply_status' => ApplyStatus::class,
'apply_completed_at' => 'datetime',
// Plain string (not enum). The exception subclass on
// form_submission_action_failures is the canonical source of
// classification truth; this column is a denormalised mirror for
// response-shape rendering. Per RFC-WS-6 §Q3 v1.3 addition 2.
'failure_response_code' => 'string',
'schema_snapshot' => 'array',
'is_test' => 'bool',
'submitted_at' => 'datetime',

View File

@@ -64,4 +64,23 @@ final class FormSubmissionFactory extends Factory
'organisation_id' => $event->organisation_id,
]);
}
/**
* Set failure_response_code. Typically used in tests asserting the
* downstream rendering behaviour for failed submissions.
*
* Valid values per RFC-WS-6 §Q3 v1.3 addition 2:
* - 'schema_config_error'
* - 'temporary_error'
* - 'data_integrity_error'
* - 'unknown_error'
*
* Note: writing this value via factory does NOT itself set apply_status
* to FAILED. Pair with an explicit apply_status attribute in tests
* that need a coherent failed-submission fixture.
*/
public function withFailureResponseCode(string $code): static
{
return $this->state(fn () => ['failure_response_code' => $code]);
}
}