- FormSubmissionActionFailure: audit model, no organisation_id (FK-chain tenancy per RFC V3), open/resolved/dismissed scopes, canBeRetried() helper. Morph alias 'form_submission_action_failure' registered for future activity-log subject references. - FormSubmission: apply_status (ApplyStatus enum cast), apply_completed_at (datetime), actionFailures() HasMany, scopePendingApply(). Refs: RFC-WS-6.md §3 (Q5), §4 (V3) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.5 KiB
PHP
75 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\ApplyStatus;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
use App\Models\FormBuilder\FormSubmission;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
final class FormSubmissionApplyStatusCastTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_apply_status_round_trips_as_enum(): void
|
|
{
|
|
$submission = FormSubmission::factory()->create();
|
|
$submission->apply_status = ApplyStatus::COMPLETED;
|
|
$submission->save();
|
|
|
|
$reloaded = FormSubmission::query()->find($submission->id);
|
|
$this->assertSame(ApplyStatus::COMPLETED, $reloaded->apply_status);
|
|
}
|
|
|
|
public function test_apply_status_null_round_trip(): void
|
|
{
|
|
$submission = FormSubmission::factory()->create();
|
|
$this->assertNull($submission->apply_status);
|
|
|
|
$submission->apply_status = null;
|
|
$submission->save();
|
|
|
|
$reloaded = FormSubmission::query()->find($submission->id);
|
|
$this->assertNull($reloaded->apply_status);
|
|
}
|
|
|
|
public function test_legacy_seed_row_without_apply_status_remains_null(): void
|
|
{
|
|
$organisation = Organisation::factory()->create();
|
|
$schema = FormSchema::factory()->for($organisation)->create();
|
|
$id = (string) Str::ulid();
|
|
|
|
DB::table('form_submissions')->insert([
|
|
'id' => $id,
|
|
'form_schema_id' => $schema->id,
|
|
'organisation_id' => $organisation->id,
|
|
'status' => 'submitted',
|
|
'is_test' => false,
|
|
'auto_save_count' => 0,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$reloaded = FormSubmission::query()->find($id);
|
|
$this->assertNull($reloaded->apply_status);
|
|
}
|
|
|
|
public function test_pending_apply_scope_filters_correctly(): void
|
|
{
|
|
FormSubmission::factory()->create(['apply_status' => ApplyStatus::PENDING]);
|
|
FormSubmission::factory()->create(['apply_status' => ApplyStatus::COMPLETED]);
|
|
FormSubmission::factory()->create(['apply_status' => ApplyStatus::FAILED]);
|
|
FormSubmission::factory()->create(); // null
|
|
|
|
$pending = FormSubmission::query()->pendingApply()->get();
|
|
$this->assertCount(1, $pending);
|
|
$this->assertSame(ApplyStatus::PENDING, $pending->first()->apply_status);
|
|
}
|
|
}
|