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>
87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormSubmissionStatus;
|
|
use App\Models\Event;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
use App\Models\FormBuilder\FormSubmission;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/** @extends Factory<FormSubmission> */
|
|
final class FormSubmissionFactory extends Factory
|
|
{
|
|
protected $model = FormSubmission::class;
|
|
|
|
/** @return array<string, mixed> */
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'form_schema_id' => FormSchema::factory(),
|
|
'subject_type' => null,
|
|
'subject_id' => null,
|
|
'submitted_by_user_id' => null,
|
|
'status' => FormSubmissionStatus::DRAFT,
|
|
'is_test' => false,
|
|
'submitted_in_locale' => 'nl',
|
|
];
|
|
}
|
|
|
|
public function submitted(): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'status' => FormSubmissionStatus::SUBMITTED,
|
|
'submitted_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function test(): static
|
|
{
|
|
return $this->state(fn () => ['is_test' => true]);
|
|
}
|
|
|
|
/**
|
|
* Force a specific tenant. The observer would otherwise resolve it
|
|
* from the schema parent; this state lets tests override for edge
|
|
* cases (e.g. cross-org leakage scenarios in Commit 3).
|
|
*/
|
|
public function forOrganisation(Organisation $organisation): static
|
|
{
|
|
return $this->state(fn () => ['organisation_id' => $organisation->id]);
|
|
}
|
|
|
|
/**
|
|
* Force a specific event + its organisation. Addendum Q2 contract:
|
|
* any submission tied to an event also has that event's org.
|
|
*/
|
|
public function forEvent(Event $event): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'event_id' => $event->id,
|
|
'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]);
|
|
}
|
|
}
|