From d715a177bd0b9d97631b11b47a4721b8ee394ca4 Mon Sep 17 00:00:00 2001 From: jon brookes Date: Thu, 15 Jan 2026 18:02:04 +0000 Subject: [PATCH] fix: standardize JSON response format in TextWidgetController and update related tests --- app/Http/Controllers/TextWidgetController.php | 4 +++- tests/Unit/TextWidgetApiTest.php | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/TextWidgetController.php b/app/Http/Controllers/TextWidgetController.php index 113b9d3..53f89f3 100644 --- a/app/Http/Controllers/TextWidgetController.php +++ b/app/Http/Controllers/TextWidgetController.php @@ -14,7 +14,9 @@ class TextWidgetController extends Controller */ public function index() { - return TextWidget::with('category')->get()->map(fn ($tw) => new TextWidgetResource($tw)); + return response()->json([ + 'data' => TextWidget::with('category')->get()->map(fn ($tw) => new TextWidgetResource($tw)) + ]); } /** diff --git a/tests/Unit/TextWidgetApiTest.php b/tests/Unit/TextWidgetApiTest.php index c7fc422..5f2df58 100644 --- a/tests/Unit/TextWidgetApiTest.php +++ b/tests/Unit/TextWidgetApiTest.php @@ -14,7 +14,10 @@ test('can list text widgets', function () { $response = $this->actingAs($user)->getJson('/api/text-widgets'); $response->assertOk() - ->assertJsonCount(3); + ->assertJson(fn ($json) => + $json->has('data', 3) + ->etc() + ); }); test('can create a text widget', function () {