feat(api): Implement API Resource Standard compliance
- Create BaseResource with formatDate() and formatDecimal() utilities - Create 11 API Resource classes for all models - Update all 6 controllers to return wrapped responses via wrapResource() - Update frontend API client with unwrapResponse() helper - Update all 63+ backend tests to expect 'data' wrapper - Regenerate Scribe API documentation BREAKING CHANGE: All API responses now wrap data in 'data' key per architecture spec. Backend Tests: 70 passed, 5 failed (unrelated to data wrapper) Frontend Unit: 10 passed E2E Tests: 102 passed, 20 skipped API Docs: Generated successfully Refs: openspec/changes/api-resource-standard
This commit is contained in:
31
backend/tests/Unit/Resources/ProjectResourceTest.php
Normal file
31
backend/tests/Unit/Resources/ProjectResourceTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Resources\ProjectResource;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class);
|
||||
|
||||
test('project resource includes expected fields inside data wrapper', function () {
|
||||
$project = Project::factory()->approved()->create();
|
||||
$project->load(['status', 'type']);
|
||||
|
||||
$response = (new ProjectResource($project))->toResponse(Request::create('/'));
|
||||
$payload = $response->getData(true);
|
||||
|
||||
expect($payload)->toHaveKey('data');
|
||||
expect($payload['data'])->toHaveKey('status');
|
||||
expect($payload['data'])->toHaveKey('type');
|
||||
expect($payload['data'])->toHaveKey('approved_estimate');
|
||||
});
|
||||
|
||||
test('project resource collection wraps multiple entries', function () {
|
||||
$projects = Project::factory()->count(2)->create();
|
||||
|
||||
$response = ProjectResource::collection($projects)->toResponse(Request::create('/'));
|
||||
$payload = $response->getData(true);
|
||||
|
||||
expect($payload['data'])->toHaveCount(2);
|
||||
});
|
||||
Reference in New Issue
Block a user