feat(form-builder): admin UI completion — server filters, KPIs, resource expansion (WS-6 sessie 3c)
Closes the four production gaps that emerged from sessie 3b's admin UI.
What we ship here is final: no further rework planned before production.
Backend
- IndexFailuresRequest validates state/search/failed_at_from/failed_at_to/
listener_class. orgIndex + platformIndex apply them via a single
applyIndexFilters() helper. Search runs case-insensitive `LIKE` on
exception_message; SQL wildcards in user input are escaped.
- New /kpis aggregate endpoint per scope (orgKpis, platformKpis) returns
open / resolved_30d / dismissed_30d / total_submissions in O(1) COUNTs.
Replaces sessie 3b's client-side bucketing of an oversized list.
- Resource expansion: organisation_name, form_schema_label,
resolved_by_user_name, dismissed_by_user_name, exception_trace,
retry_history[]. Eager-loading via indexEagerLoads()/detailEagerLoads()
prevents N+1 (verified by query-count assertion in test).
- New 2026_04_28_181000 migration adds exception_trace (longtext nullable)
to form_submission_action_failures. ApplyBindingsOnFormSubmit listener
now captures $e->getTraceAsString() at failure time.
- New FormSubmissionActionFailureRetryAttemptResource exposes per-attempt
data (timestamp, actor name, outcome, exception details) inside
retry_history[]. Index payloads omit the field via whenLoaded() to keep
list responses lean.
Frontend (apps/app)
- Types updated to mirror the expanded resource shape and the new KPI
endpoint contract. FormFailuresKpis is now { open, resolved_30d,
dismissed_30d, total_submissions } (server-aggregate).
- useFormFailures composable forwards all 5 server filters via
buildIndexParams() (strips empty/whitespace). useFormFailuresKpis hits
the dedicated /kpis endpoint per scope.
- FormFailuresTable replaces client-side bucketing with server-side
filtering, adds listener_class + date-range filter inputs, and renames
the 4th KPI tile to "Submissions" (was "Totaal").
- FormFailureDetail renders organisation_name + form_schema_label in the
header, surfaces an expandable stack-trace card, names the resolved/
dismissed actor in the timeline, and replaces the "v1 placeholder"
retry-history card with a full per-attempt timeline.
ESLint config gap (apps/app)
- New .eslintrc.cjs adapted from the Vuexy reference, minus Vuexy-internal
rules. `pnpm lint` now runs successfully (was previously broken — the
package.json script referenced a missing config). The 80 baseline
violations across the codebase are pre-existing and out of scope for
this session.
Tests + gates
- 24 new backend tests across filter, kpis, and resource-shape suites.
Backend: 1462 → 1486 passing, 0 → 0 failing. Larastan clean. Rector
dry-run unchanged at 354 (pre-Task-1 baseline from f18b55b).
- 3 new vitest tests in apps/app (filter wiring, KPI endpoint, KPI tile
values from /kpis). Vitest: 38 → 41 passing. tsc clean. Portal
unchanged (113 vitest, tsc clean).
- 5 backfill rollback tests bumped --step counts +1 for the new migration.
- Ws6FoundationMigrationTest down/up chain now includes exception_trace
before the parent table is restored.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Api;
|
||||
|
||||
use App\Listeners\FormBuilder\ApplyBindingsOnFormSubmit;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailure;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Sessie 3c — covers the IndexFailuresRequest filter wiring on
|
||||
* orgIndex + platformIndex (state, search, failed_at_from/to,
|
||||
* listener_class). Cross-tenant filtering still scopes to the
|
||||
* org via FK chain (RFC V3) — verified implicitly because every
|
||||
* row in this suite belongs to orgA.
|
||||
*/
|
||||
final class FormSubmissionActionFailureFilterTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $orgA;
|
||||
|
||||
private User $orgAdminA;
|
||||
|
||||
private User $superAdmin;
|
||||
|
||||
private FormSubmission $submission;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->orgA = Organisation::factory()->create();
|
||||
$schema = FormSchema::factory()->create(['organisation_id' => $this->orgA->id]);
|
||||
$this->submission = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $schema->id,
|
||||
'organisation_id' => $this->orgA->id,
|
||||
]);
|
||||
|
||||
$this->orgAdminA = User::factory()->create();
|
||||
$this->orgA->users()->attach($this->orgAdminA, ['role' => 'org_admin']);
|
||||
|
||||
$this->superAdmin = User::factory()->create();
|
||||
$this->superAdmin->assignRole('super_admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $attrs
|
||||
*/
|
||||
private function makeFailure(array $attrs = []): FormSubmissionActionFailure
|
||||
{
|
||||
return FormSubmissionActionFailure::factory()
|
||||
->for($this->submission, 'submission')
|
||||
->create($attrs);
|
||||
}
|
||||
|
||||
private function orgUrl(string $query = ''): string
|
||||
{
|
||||
return "/api/v1/organisations/{$this->orgA->id}/form-failures".($query !== '' ? "?{$query}" : '');
|
||||
}
|
||||
|
||||
public function test_default_state_filter_returns_only_open(): void
|
||||
{
|
||||
$open = $this->makeFailure();
|
||||
$this->makeFailure(['resolved_at' => now()]);
|
||||
$this->makeFailure(['dismissed_at' => now(), 'dismissed_reason_type' => 'schema_deleted']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl())->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $open->id], $ids);
|
||||
}
|
||||
|
||||
public function test_state_resolved_filter(): void
|
||||
{
|
||||
$this->makeFailure();
|
||||
$resolved = $this->makeFailure(['resolved_at' => now()]);
|
||||
$this->makeFailure(['dismissed_at' => now(), 'dismissed_reason_type' => 'schema_deleted']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl('state=resolved'))->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $resolved->id], $ids);
|
||||
}
|
||||
|
||||
public function test_state_dismissed_filter(): void
|
||||
{
|
||||
$this->makeFailure();
|
||||
$this->makeFailure(['resolved_at' => now()]);
|
||||
$dismissed = $this->makeFailure(['dismissed_at' => now(), 'dismissed_reason_type' => 'schema_deleted']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl('state=dismissed'))->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $dismissed->id], $ids);
|
||||
}
|
||||
|
||||
public function test_state_all_returns_every_row(): void
|
||||
{
|
||||
$this->makeFailure();
|
||||
$this->makeFailure(['resolved_at' => now()]);
|
||||
$this->makeFailure(['dismissed_at' => now(), 'dismissed_reason_type' => 'schema_deleted']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl('state=all'))->assertOk();
|
||||
|
||||
$this->assertCount(3, $response->json('data'));
|
||||
}
|
||||
|
||||
public function test_search_matches_exception_message_substring_case_insensitive(): void
|
||||
{
|
||||
$hit = $this->makeFailure(['exception_message' => 'Person provisioning failed: NO_DEFAULT_CROWD_TYPE']);
|
||||
$this->makeFailure(['exception_message' => 'Some other unrelated error']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl('search=crowd_type'))->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $hit->id], $ids);
|
||||
}
|
||||
|
||||
public function test_search_with_sql_wildcards_is_escaped(): void
|
||||
{
|
||||
$this->makeFailure(['exception_message' => 'literal % percent in message']);
|
||||
$this->makeFailure(['exception_message' => 'no wildcard here']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl('search=%25'))->assertOk();
|
||||
|
||||
$messages = array_column((array) $response->json('data'), 'exception_message');
|
||||
$this->assertCount(1, $messages);
|
||||
$this->assertStringContainsString('%', (string) $messages[0]);
|
||||
}
|
||||
|
||||
public function test_failed_at_from_and_to_inclusive(): void
|
||||
{
|
||||
$old = $this->makeFailure(['failed_at' => '2026-01-01 12:00:00']);
|
||||
$mid = $this->makeFailure(['failed_at' => '2026-02-15 12:00:00']);
|
||||
$new = $this->makeFailure(['failed_at' => '2026-03-30 12:00:00']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this
|
||||
->getJson($this->orgUrl('failed_at_from=2026-02-01&failed_at_to=2026-03-01'))
|
||||
->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $mid->id], $ids);
|
||||
$this->assertNotContains((string) $old->id, $ids);
|
||||
$this->assertNotContains((string) $new->id, $ids);
|
||||
}
|
||||
|
||||
public function test_listener_class_exact_match(): void
|
||||
{
|
||||
$hit = $this->makeFailure(['listener_class' => ApplyBindingsOnFormSubmit::class]);
|
||||
$this->makeFailure(['listener_class' => 'App\\Listeners\\Other\\Listener']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this
|
||||
->getJson($this->orgUrl('listener_class='.urlencode(ApplyBindingsOnFormSubmit::class)))
|
||||
->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $hit->id], $ids);
|
||||
}
|
||||
|
||||
public function test_filters_combine_with_and_semantics(): void
|
||||
{
|
||||
$match = $this->makeFailure([
|
||||
'exception_message' => 'crowd_type missing',
|
||||
'failed_at' => '2026-02-15 12:00:00',
|
||||
'listener_class' => ApplyBindingsOnFormSubmit::class,
|
||||
]);
|
||||
$this->makeFailure([
|
||||
'exception_message' => 'crowd_type missing',
|
||||
'failed_at' => '2025-01-01 12:00:00',
|
||||
'listener_class' => ApplyBindingsOnFormSubmit::class,
|
||||
]);
|
||||
$this->makeFailure([
|
||||
'exception_message' => 'unrelated',
|
||||
'failed_at' => '2026-02-15 12:00:00',
|
||||
'listener_class' => ApplyBindingsOnFormSubmit::class,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this
|
||||
->getJson($this->orgUrl('search=crowd_type&failed_at_from=2026-01-01&failed_at_to=2026-12-31&listener_class='.urlencode(ApplyBindingsOnFormSubmit::class)))
|
||||
->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $match->id], $ids);
|
||||
}
|
||||
|
||||
public function test_invalid_state_returns_422(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$this->getJson($this->orgUrl('state=bogus'))
|
||||
->assertStatus(422)
|
||||
->assertJsonValidationErrors(['state']);
|
||||
}
|
||||
|
||||
public function test_invalid_date_range_returns_422(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$this
|
||||
->getJson($this->orgUrl('failed_at_from=2026-03-01&failed_at_to=2026-01-01'))
|
||||
->assertStatus(422)
|
||||
->assertJsonValidationErrors(['failed_at_to']);
|
||||
}
|
||||
|
||||
public function test_platform_index_applies_same_filters(): void
|
||||
{
|
||||
$open = $this->makeFailure();
|
||||
$this->makeFailure(['resolved_at' => now()]);
|
||||
|
||||
Sanctum::actingAs($this->superAdmin);
|
||||
$response = $this->getJson('/api/v1/admin/form-failures?state=open')->assertOk();
|
||||
|
||||
$ids = array_column((array) $response->json('data'), 'id');
|
||||
$this->assertSame([(string) $open->id], $ids);
|
||||
}
|
||||
|
||||
public function test_pagination_preserves_query_string(): void
|
||||
{
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$this->makeFailure(['resolved_at' => now()]);
|
||||
}
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson($this->orgUrl('state=resolved&search=Simulated'))->assertOk();
|
||||
|
||||
$firstPageUrl = (string) $response->json('links.first');
|
||||
$this->assertStringContainsString('state=resolved', $firstPageUrl);
|
||||
$this->assertStringContainsString('search=Simulated', $firstPageUrl);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Api;
|
||||
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
use App\Models\FormBuilder\FormSubmissionActionFailure;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Sessie 3c — admin-UI dashboard KPI counters. Both org-scoped and
|
||||
* platform-wide endpoints; tenant gate via FK chain (RFC V3).
|
||||
*/
|
||||
final class FormSubmissionActionFailureKpisTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $orgA;
|
||||
|
||||
private Organisation $orgB;
|
||||
|
||||
private User $orgAdminA;
|
||||
|
||||
private User $orgAdminB;
|
||||
|
||||
private User $superAdmin;
|
||||
|
||||
private FormSubmission $submissionA;
|
||||
|
||||
private FormSubmission $submissionB;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->orgA = Organisation::factory()->create();
|
||||
$this->orgB = Organisation::factory()->create();
|
||||
|
||||
$schemaA = FormSchema::factory()->create(['organisation_id' => $this->orgA->id]);
|
||||
$schemaB = FormSchema::factory()->create(['organisation_id' => $this->orgB->id]);
|
||||
$this->submissionA = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $schemaA->id,
|
||||
'organisation_id' => $this->orgA->id,
|
||||
]);
|
||||
$this->submissionB = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $schemaB->id,
|
||||
'organisation_id' => $this->orgB->id,
|
||||
]);
|
||||
|
||||
$this->orgAdminA = User::factory()->create();
|
||||
$this->orgA->users()->attach($this->orgAdminA, ['role' => 'org_admin']);
|
||||
$this->orgAdminB = User::factory()->create();
|
||||
$this->orgB->users()->attach($this->orgAdminB, ['role' => 'org_admin']);
|
||||
$this->superAdmin = User::factory()->create();
|
||||
$this->superAdmin->assignRole('super_admin');
|
||||
}
|
||||
|
||||
public function test_org_kpis_counts_open_resolved_dismissed_and_total_submissions(): void
|
||||
{
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')->create();
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')->create();
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')
|
||||
->create(['resolved_at' => now()->subDays(5)]);
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')
|
||||
->create(['dismissed_at' => now()->subDays(10), 'dismissed_reason_type' => 'schema_deleted']);
|
||||
|
||||
// Outside-30d window — must NOT count.
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')
|
||||
->create(['resolved_at' => now()->subDays(45)]);
|
||||
|
||||
// Other tenant — must NOT count.
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionB, 'submission')->create();
|
||||
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$response = $this->getJson("/api/v1/organisations/{$this->orgA->id}/form-failures/kpis")->assertOk();
|
||||
|
||||
$response->assertJsonPath('data.open', 2);
|
||||
$response->assertJsonPath('data.resolved_30d', 1);
|
||||
$response->assertJsonPath('data.dismissed_30d', 1);
|
||||
$response->assertJsonPath('data.total_submissions', 1);
|
||||
}
|
||||
|
||||
public function test_org_kpis_cross_tenant_returns_404(): void
|
||||
{
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')->create();
|
||||
|
||||
Sanctum::actingAs($this->orgAdminB);
|
||||
$this->getJson("/api/v1/organisations/{$this->orgA->id}/form-failures/kpis")
|
||||
->assertStatus(404);
|
||||
}
|
||||
|
||||
public function test_org_kpis_unauthenticated_returns_401(): void
|
||||
{
|
||||
$this->getJson("/api/v1/organisations/{$this->orgA->id}/form-failures/kpis")
|
||||
->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_platform_kpis_aggregates_across_all_orgs(): void
|
||||
{
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')->create();
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionB, 'submission')->create();
|
||||
FormSubmissionActionFailure::factory()->for($this->submissionA, 'submission')
|
||||
->create(['resolved_at' => now()->subDays(2)]);
|
||||
|
||||
Sanctum::actingAs($this->superAdmin);
|
||||
$response = $this->getJson('/api/v1/admin/form-failures/kpis')->assertOk();
|
||||
|
||||
$response->assertJsonPath('data.open', 2);
|
||||
$response->assertJsonPath('data.resolved_30d', 1);
|
||||
$response->assertJsonPath('data.dismissed_30d', 0);
|
||||
$response->assertJsonPath('data.total_submissions', 2);
|
||||
}
|
||||
|
||||
public function test_platform_kpis_org_admin_returns_403(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdminA);
|
||||
$this->getJson('/api/v1/admin/form-failures/kpis')
|
||||
->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_platform_kpis_unauthenticated_returns_401(): void
|
||||
{
|
||||
$this->getJson('/api/v1/admin/form-failures/kpis')->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_kpis_with_no_data_returns_zeros(): void
|
||||
{
|
||||
$orgC = Organisation::factory()->create();
|
||||
$orgAdminC = User::factory()->create();
|
||||
$orgC->users()->attach($orgAdminC, ['role' => 'org_admin']);
|
||||
|
||||
Sanctum::actingAs($orgAdminC);
|
||||
$response = $this->getJson("/api/v1/organisations/{$orgC->id}/form-failures/kpis")->assertOk();
|
||||
|
||||
$response->assertJsonPath('data.open', 0);
|
||||
$response->assertJsonPath('data.resolved_30d', 0);
|
||||
$response->assertJsonPath('data.dismissed_30d', 0);
|
||||
$response->assertJsonPath('data.total_submissions', 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FormBuilder\Api;
|
||||
|
||||
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 Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Sessie 3c — verifies the expanded admin-UI resource payload
|
||||
* (denormalized labels, exception_trace, retry_history[]) and the
|
||||
* eager-loading guarantees that prevent N+1 on index/show.
|
||||
*/
|
||||
final class FormSubmissionActionFailureResourceShapeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $orgA;
|
||||
|
||||
private User $superAdmin;
|
||||
|
||||
private FormSchema $schemaA;
|
||||
|
||||
private FormSubmission $submissionA;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->orgA = Organisation::factory()->create(['name' => 'Festival X']);
|
||||
$this->schemaA = FormSchema::factory()->create([
|
||||
'organisation_id' => $this->orgA->id,
|
||||
'name' => 'Vrijwilligers aanmelding',
|
||||
]);
|
||||
$this->submissionA = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $this->schemaA->id,
|
||||
'organisation_id' => $this->orgA->id,
|
||||
]);
|
||||
|
||||
$this->superAdmin = User::factory()->create();
|
||||
$this->superAdmin->assignRole('super_admin');
|
||||
}
|
||||
|
||||
public function test_show_payload_includes_denormalized_labels_and_trace(): void
|
||||
{
|
||||
$resolver = User::factory()->create(['first_name' => 'Maud', 'last_name' => 'Admin']);
|
||||
$failure = FormSubmissionActionFailure::factory()
|
||||
->for($this->submissionA, 'submission')
|
||||
->create([
|
||||
'exception_trace' => "#0 stack frame\n#1 next frame",
|
||||
'resolved_at' => now(),
|
||||
'resolved_by_user_id' => $resolver->id,
|
||||
'resolved_note' => 'fixed manually',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->superAdmin);
|
||||
$response = $this->getJson("/api/v1/admin/form-failures/{$failure->id}")->assertOk();
|
||||
|
||||
$response
|
||||
->assertJsonPath('data.id', (string) $failure->id)
|
||||
->assertJsonPath('data.organisation_id', (string) $this->orgA->id)
|
||||
->assertJsonPath('data.organisation_name', 'Festival X')
|
||||
->assertJsonPath('data.form_schema_id', (string) $this->schemaA->id)
|
||||
->assertJsonPath('data.form_schema_label', 'Vrijwilligers aanmelding')
|
||||
->assertJsonPath('data.exception_trace', "#0 stack frame\n#1 next frame")
|
||||
->assertJsonPath('data.resolved_by_user_name', 'Maud Admin')
|
||||
->assertJsonPath('data.dismissed_by_user_name', null);
|
||||
}
|
||||
|
||||
public function test_show_payload_includes_retry_history_in_chronological_order(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()
|
||||
->for($this->submissionA, 'submission')
|
||||
->create();
|
||||
|
||||
$actor = User::factory()->create(['first_name' => 'Alex', 'last_name' => 'Operator']);
|
||||
|
||||
FormSubmissionActionFailureRetryAttempt::factory()->create([
|
||||
'form_submission_action_failure_id' => $failure->id,
|
||||
'attempted_at' => now()->subMinutes(10),
|
||||
'attempted_by_user_id' => $actor->id,
|
||||
'outcome' => 'failed',
|
||||
'exception_class' => \RuntimeException::class,
|
||||
'exception_message' => 'first retry failed',
|
||||
]);
|
||||
FormSubmissionActionFailureRetryAttempt::factory()->succeeded()->create([
|
||||
'form_submission_action_failure_id' => $failure->id,
|
||||
'attempted_at' => now(),
|
||||
'attempted_by_user_id' => $actor->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->superAdmin);
|
||||
$response = $this->getJson("/api/v1/admin/form-failures/{$failure->id}")->assertOk();
|
||||
|
||||
$history = $response->json('data.retry_history');
|
||||
$this->assertIsArray($history);
|
||||
$this->assertCount(2, $history);
|
||||
// latest('attempted_at') in the relation puts the newest first.
|
||||
$this->assertSame('succeeded', $history[0]['outcome']);
|
||||
$this->assertSame('failed', $history[1]['outcome']);
|
||||
$this->assertSame('Alex Operator', $history[0]['attempted_by_user_name']);
|
||||
$this->assertSame('first retry failed', $history[1]['exception_message']);
|
||||
}
|
||||
|
||||
public function test_index_payload_omits_retry_history_to_keep_payload_small(): void
|
||||
{
|
||||
$failure = FormSubmissionActionFailure::factory()
|
||||
->for($this->submissionA, 'submission')
|
||||
->create();
|
||||
FormSubmissionActionFailureRetryAttempt::factory()->create([
|
||||
'form_submission_action_failure_id' => $failure->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->superAdmin);
|
||||
$response = $this->getJson('/api/v1/admin/form-failures')->assertOk();
|
||||
|
||||
// whenLoaded() => the key resolves to MissingValue and is omitted.
|
||||
$first = $response->json('data.0');
|
||||
$this->assertArrayNotHasKey('retry_history', $first);
|
||||
$this->assertSame('Festival X', $first['organisation_name']);
|
||||
$this->assertSame('Vrijwilligers aanmelding', $first['form_schema_label']);
|
||||
}
|
||||
|
||||
public function test_index_does_not_n_plus_one_on_relations(): void
|
||||
{
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$sub = FormSubmission::factory()->create([
|
||||
'form_schema_id' => $this->schemaA->id,
|
||||
'organisation_id' => $this->orgA->id,
|
||||
]);
|
||||
FormSubmissionActionFailure::factory()->for($sub, 'submission')->create();
|
||||
}
|
||||
|
||||
Sanctum::actingAs($this->superAdmin);
|
||||
DB::enableQueryLog();
|
||||
$this->getJson('/api/v1/admin/form-failures')->assertOk();
|
||||
$queries = DB::getQueryLog();
|
||||
DB::disableQueryLog();
|
||||
|
||||
// Eager-loading bound: failures + submissions + organisations + schemas
|
||||
// + resolvedBy + dismissedBy + count = 7 baseline; allow modest headroom
|
||||
// for auth/sanctum/pagination overhead but reject linear growth in N.
|
||||
$this->assertLessThanOrEqual(15, count($queries), sprintf(
|
||||
'Index endpoint may have N+1 (executed %d queries for 5 failures): %s',
|
||||
count($queries),
|
||||
implode("\n", array_column($queries, 'query')),
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -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' => 20])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 21])->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' => 20])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 21])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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'));
|
||||
|
||||
@@ -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' => 9])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 10])->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' => 9])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 10])->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' => 9])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 10])->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' => 9])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 10])->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' => 15])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 16])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->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' => 5])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 6])->assertSuccessful();
|
||||
$this->seedTemplateWithSnapshotRaw([
|
||||
'fields' => [[
|
||||
'id' => (string) Str::ulid(),
|
||||
|
||||
@@ -115,8 +115,15 @@ final class Ws6FoundationMigrationTest extends TestCase
|
||||
$retryAttempts = require database_path(
|
||||
'migrations/2026_04_28_180000_create_form_submission_action_failure_retry_attempts_table.php',
|
||||
);
|
||||
// Sessie 3c also adds exception_trace to the parent table — chain
|
||||
// its down() before the parent's drop so the column ordering on
|
||||
// restore matches the production migration order.
|
||||
$exceptionTrace = require database_path(
|
||||
'migrations/2026_04_28_181000_add_exception_trace_to_form_submission_action_failures.php',
|
||||
);
|
||||
|
||||
$retryAttempts->down();
|
||||
$exceptionTrace->down();
|
||||
$createFailures->down();
|
||||
$applyStatus->down();
|
||||
|
||||
@@ -133,6 +140,7 @@ final class Ws6FoundationMigrationTest extends TestCase
|
||||
// Restore state for any subsequent tests in this class.
|
||||
$applyStatus->up();
|
||||
$createFailures->up();
|
||||
$exceptionTrace->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->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' => 18])->assertSuccessful();
|
||||
$this->artisan('migrate:rollback', ['--step' => 19])->assertSuccessful();
|
||||
$this->assertTrue(Schema::hasColumn('form_fields', 'validation_rules'));
|
||||
|
||||
$field = DB::table('form_fields')->where('id', $numberId)->first();
|
||||
|
||||
Reference in New Issue
Block a user