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:
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace Tests\Feature\Auth;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationTest extends TestCase
|
||||
{
|
||||
@@ -52,11 +52,11 @@ class AuthenticationTest extends TestCase
|
||||
$payload = base64_encode($payload);
|
||||
$payload = str_replace(['+', '/', '='], ['-', '_', ''], $payload);
|
||||
|
||||
$signature = hash_hmac('sha256', $header . '.' . $payload, config('app.key'), true);
|
||||
$signature = hash_hmac('sha256', $header.'.'.$payload, config('app.key'), true);
|
||||
$signature = base64_encode($signature);
|
||||
$signature = str_replace(['+', '/', '='], ['-', '_', ''], $signature);
|
||||
|
||||
return $header . '.' . $payload . '.' . $signature;
|
||||
return $header.'.'.$payload.'.'.$signature;
|
||||
}
|
||||
|
||||
protected function decodeJWT(string $token): ?object
|
||||
@@ -67,9 +67,9 @@ class AuthenticationTest extends TestCase
|
||||
return null;
|
||||
}
|
||||
|
||||
list($header, $payload, $signature) = $parts;
|
||||
[$header, $payload, $signature] = $parts;
|
||||
|
||||
$expectedSignature = hash_hmac('sha256', $header . '.' . $payload, config('app.key'), true);
|
||||
$expectedSignature = hash_hmac('sha256', $header.'.'.$payload, config('app.key'), true);
|
||||
$expectedSignature = base64_encode($expectedSignature);
|
||||
$expectedSignature = str_replace(['+', '/', '='], ['-', '_', ''], $expectedSignature);
|
||||
|
||||
@@ -103,16 +103,19 @@ class AuthenticationTest extends TestCase
|
||||
'refresh_token',
|
||||
'token_type',
|
||||
'expires_in',
|
||||
'user' => [
|
||||
'data' => [
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'role',
|
||||
'active',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
],
|
||||
]);
|
||||
$response->assertJsonPath('user.name', $user->name);
|
||||
$response->assertJsonPath('user.email', $user->email);
|
||||
$response->assertJsonPath('user.role', 'manager');
|
||||
$response->assertJsonPath('data.name', $user->name);
|
||||
$response->assertJsonPath('data.email', $user->email);
|
||||
$response->assertJsonPath('data.role', 'manager');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -196,8 +199,10 @@ class AuthenticationTest extends TestCase
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson([
|
||||
'id' => $user->id,
|
||||
'email' => $user->email,
|
||||
'data' => [
|
||||
'id' => $user->id,
|
||||
'email' => $user->email,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user