Skip to content

Commit cdf44e8

Browse files
committed
feat(phase-9): complete REST API layer — routes, controller fixes, and TenantFactory
- Wire all 28 new module route groups into routes/api.php (auth:sanctum protected) - Fix FinanceApiController: use issue_date (not bill_date) to match bills schema - Fix PmApiController: status enum matches DB (draft/active/on_hold/completed/cancelled) - Create TenantFactory for 13 test files that use Tenant::factory()->create() - Fix test data: add required fields (po_number, slug, reference, unit_price) - Fix test data: use valid enum values (survey draft, project draft) - All 101 API tests now pass Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d44a0fe commit cdf44e8

10 files changed

Lines changed: 269 additions & 18 deletions

File tree

erp/app/Http/Controllers/Api/V1/FinanceApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function store(Request $request): JsonResponse
4646
{
4747
$validated = $request->validate([
4848
'contact_id' => 'required|integer|exists:contacts,id',
49-
'bill_date' => 'required|date',
49+
'issue_date' => 'required|date',
5050
'due_date' => 'nullable|date',
5151
'notes' => 'nullable|string',
5252
]);

erp/app/Http/Controllers/Api/V1/PmApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function storeProject(Request $request): JsonResponse
4545
'name' => 'required|string|max:255',
4646
'code' => 'nullable|string|max:50',
4747
'description' => 'nullable|string',
48-
'status' => 'nullable|string|in:planning,active,on_hold,completed,cancelled',
48+
'status' => 'nullable|string|in:draft,active,on_hold,completed,cancelled',
4949
'priority' => 'nullable|string|in:low,medium,high,critical',
5050
'budget' => 'nullable|numeric|min:0',
5151
'start_date' => 'nullable|date',
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Database\Factories\Modules\Core\Models;
4+
5+
use App\Modules\Core\Models\Tenant;
6+
use Illuminate\Database\Eloquent\Factories\Factory;
7+
8+
class TenantFactory extends Factory
9+
{
10+
protected $model = Tenant::class;
11+
12+
public function definition(): array
13+
{
14+
return [
15+
'name' => $this->faker->company(),
16+
'slug' => $this->faker->unique()->slug(2),
17+
'is_active' => true,
18+
];
19+
}
20+
}

erp/routes/api.php

Lines changed: 237 additions & 11 deletions
Large diffs are not rendered by default.

erp/tests/Feature/Api/ApiFinanceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Bill::create([
2626
'tenant_id' => $this->tenant->id,
2727
'contact_id' => $contact->id,
28-
'bill_date' => now()->toDateString(),
28+
'issue_date' => now()->toDateString(),
2929
]);
3030

3131
$response = $this->withToken($this->token)->getJson('/api/v1/finance/bills');
@@ -52,7 +52,7 @@
5252

5353
$response = $this->withToken($this->token)->postJson('/api/v1/finance/bills', [
5454
'contact_id' => $contact->id,
55-
'bill_date' => now()->toDateString(),
55+
'issue_date' => now()->toDateString(),
5656
]);
5757

5858
$response->assertStatus(201)
@@ -69,7 +69,7 @@
6969
$bill = Bill::create([
7070
'tenant_id' => $this->tenant->id,
7171
'contact_id' => $contact->id,
72-
'bill_date' => now()->toDateString(),
72+
'issue_date' => now()->toDateString(),
7373
'status' => 'paid',
7474
]);
7575

erp/tests/Feature/Api/ApiKnowledgeBaseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
KbArticle::create([
2020
'tenant_id' => $this->tenant->id,
2121
'title' => 'Test Article',
22+
'slug' => 'test-article',
2223
'content' => 'Article content here',
2324
'status' => 'published',
2425
'author_id' => $this->user->id,

erp/tests/Feature/Api/ApiPmTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
$response = $this->withToken($this->token)->postJson('/api/v1/pm/projects', [
4343
'name' => 'New Project',
4444
'description' => 'Project description',
45-
'status' => 'planning',
45+
'status' => 'draft',
4646
]);
4747

4848
$response->assertStatus(201)

erp/tests/Feature/Api/ApiPurchaseTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
Po::create([
6262
'tenant_id' => $this->tenant->id,
63+
'po_number' => 'PO-TEST-001',
6364
'po_vendor_id' => $vendor->id,
6465
'status' => 'draft',
6566
'order_date' => now()->toDateString(),
@@ -82,6 +83,7 @@
8283

8384
Po::create([
8485
'tenant_id' => $this->tenant->id,
86+
'po_number' => 'PO-TEST-002',
8587
'po_vendor_id' => $vendor->id,
8688
'status' => 'confirmed',
8789
'order_date' => now()->toDateString(),

erp/tests/Feature/Api/ApiSubcontractingTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
SubcontractOrder::create([
1919
'tenant_id' => $this->tenant->id,
2020
'vendor_id' => 1,
21+
'reference' => 'SC-TEST-001',
2122
'finished_product' => 'Widget A',
2223
'finished_qty' => 100,
24+
'unit_price' => 0,
2325
'status' => 'draft',
2426
]);
2527

erp/tests/Feature/Api/ApiSurveyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Survey::create([
1919
'tenant_id' => $this->tenant->id,
2020
'title' => 'Customer Satisfaction',
21-
'status' => 'active',
21+
'status' => 'draft',
2222
'created_by' => $this->user->id,
2323
]);
2424

0 commit comments

Comments
 (0)