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:
@@ -73,12 +73,11 @@ class ProjectTest extends TestCase
|
||||
|
||||
$response = $this->withToken($token)
|
||||
->postJson('/api/projects', $payload);
|
||||
dump($response->json());
|
||||
|
||||
$response->assertStatus(201)
|
||||
->assertJsonFragment([
|
||||
'code' => $payload['code'],
|
||||
'title' => $payload['title'],
|
||||
]);
|
||||
$response->assertStatus(201);
|
||||
$response->assertJsonPath('data.code', $payload['code']);
|
||||
$response->assertJsonPath('data.title', $payload['title']);
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'code' => $payload['code'],
|
||||
@@ -110,7 +109,7 @@ class ProjectTest extends TestCase
|
||||
$payload = $this->projectPayload();
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $payload)
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$invalidStatus = $this->statusId('In Progress');
|
||||
|
||||
@@ -123,7 +122,7 @@ class ProjectTest extends TestCase
|
||||
|
||||
$this->transitionProjectStatus($projectId, 'SOW Approval', $token)
|
||||
->assertStatus(200)
|
||||
->assertJsonPath('status.name', 'SOW Approval');
|
||||
->assertJsonPath('data.status.name', 'SOW Approval');
|
||||
}
|
||||
|
||||
// 3.1.16 API test: Estimate approved requires estimate value
|
||||
@@ -132,7 +131,7 @@ class ProjectTest extends TestCase
|
||||
$token = $this->loginAsManager();
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $this->projectPayload())
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$this->transitionProjectStatus($projectId, 'SOW Approval', $token)
|
||||
->assertStatus(200);
|
||||
@@ -154,7 +153,7 @@ class ProjectTest extends TestCase
|
||||
$payload = $this->projectPayload(['approved_estimate' => 120]);
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $payload)
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$workflow = [
|
||||
'Pre-sales',
|
||||
@@ -172,7 +171,7 @@ class ProjectTest extends TestCase
|
||||
foreach (array_slice($workflow, 1) as $statusName) {
|
||||
$this->transitionProjectStatus($projectId, $statusName, $token)
|
||||
->assertStatus(200)
|
||||
->assertJsonPath('status.name', $statusName);
|
||||
->assertJsonPath('data.status.name', $statusName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,11 +181,11 @@ class ProjectTest extends TestCase
|
||||
$token = $this->loginAsManager();
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $this->projectPayload())
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$this->transitionProjectStatus($projectId, 'SOW Approval', $token)
|
||||
->assertStatus(200)
|
||||
->assertJsonPath('status.name', 'SOW Approval');
|
||||
->assertJsonPath('data.status.name', 'SOW Approval');
|
||||
|
||||
$this->assertDatabaseHas('projects', [
|
||||
'id' => $projectId,
|
||||
@@ -200,12 +199,12 @@ class ProjectTest extends TestCase
|
||||
$token = $this->loginAsManager();
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $this->projectPayload())
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$this->withToken($token)
|
||||
->putJson("/api/projects/{$projectId}/estimate", ['approved_estimate' => 275])
|
||||
->assertStatus(200)
|
||||
->assertJsonPath('approved_estimate', '275.00');
|
||||
->assertJsonPath('data.approved_estimate', '275.00');
|
||||
|
||||
$this->assertSame('275.00', (string) Project::find($projectId)->approved_estimate);
|
||||
}
|
||||
@@ -216,14 +215,14 @@ class ProjectTest extends TestCase
|
||||
$token = $this->loginAsManager();
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $this->projectPayload(['approved_estimate' => 100]))
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$forecast = ['2025-01' => 33, '2025-02' => 33, '2025-03' => 34];
|
||||
|
||||
$this->withToken($token)
|
||||
->putJson("/api/projects/{$projectId}/forecast", ['forecasted_effort' => $forecast])
|
||||
->assertStatus(200)
|
||||
->assertJsonFragment(['forecasted_effort' => $forecast]);
|
||||
->assertJsonPath('data.forecasted_effort', $forecast);
|
||||
|
||||
$this->assertSame($forecast, Project::find($projectId)->forecasted_effort);
|
||||
}
|
||||
@@ -234,7 +233,7 @@ class ProjectTest extends TestCase
|
||||
$token = $this->loginAsManager();
|
||||
$projectId = $this->withToken($token)
|
||||
->postJson('/api/projects', $this->projectPayload(['approved_estimate' => 100]))
|
||||
->json('id');
|
||||
->json('data.id');
|
||||
|
||||
$forecast = ['2025-01' => 50, '2025-02' => 50, '2025-03' => 50];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user