Skip to content

Commit d44a0fe

Browse files
committed
feat(phase-9): add API test files for all remaining modules
Tests cover: Approvals, Discuss, Documents, Ecommerce, Events, FieldService, Frontdesk, Lunch, Planning, Sign, SocialMarketing, Subcontracting, Survey, Website. Each test file has authenticated (200) and unauthenticated (401) checks. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0743797 commit d44a0fe

14 files changed

Lines changed: 378 additions & 0 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
6+
it('returns approval requests for authenticated user', function () {
7+
$tenant = Tenant::factory()->create();
8+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
9+
$token = $user->createToken('test')->plainTextToken;
10+
$response = $this->withToken($token)->getJson('/api/v1/approvals');
11+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
12+
});
13+
14+
it('requires authentication for approvals', function () {
15+
$this->getJson('/api/v1/approvals')->assertStatus(401);
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
6+
it('returns discuss channels for authenticated user', function () {
7+
$tenant = Tenant::factory()->create();
8+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
9+
$token = $user->createToken('test')->plainTextToken;
10+
$response = $this->withToken($token)->getJson('/api/v1/discuss/channels');
11+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
12+
});
13+
14+
it('requires authentication for discuss channels', function () {
15+
$this->getJson('/api/v1/discuss/channels')->assertStatus(401);
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
6+
it('returns documents for authenticated user', function () {
7+
$tenant = Tenant::factory()->create();
8+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
9+
$token = $user->createToken('test')->plainTextToken;
10+
$response = $this->withToken($token)->getJson('/api/v1/documents');
11+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
12+
});
13+
14+
it('requires authentication for documents', function () {
15+
$this->getJson('/api/v1/documents')->assertStatus(401);
16+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
6+
it('returns store products for authenticated user', function () {
7+
$tenant = Tenant::factory()->create();
8+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
9+
$token = $user->createToken('test')->plainTextToken;
10+
$response = $this->withToken($token)->getJson('/api/v1/ecommerce/products');
11+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
12+
});
13+
14+
it('requires authentication for store products', function () {
15+
$this->getJson('/api/v1/ecommerce/products')->assertStatus(401);
16+
});
17+
18+
it('returns store orders for authenticated user', function () {
19+
$tenant = Tenant::factory()->create();
20+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
21+
$token = $user->createToken('test')->plainTextToken;
22+
$response = $this->withToken($token)->getJson('/api/v1/ecommerce/orders');
23+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
24+
});
25+
26+
it('requires authentication for store orders', function () {
27+
$this->getJson('/api/v1/ecommerce/orders')->assertStatus(401);
28+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
6+
it('returns events for authenticated user', function () {
7+
$tenant = Tenant::factory()->create();
8+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
9+
$token = $user->createToken('test')->plainTextToken;
10+
$response = $this->withToken($token)->getJson('/api/v1/events');
11+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
12+
});
13+
14+
it('requires authentication for events', function () {
15+
$this->getJson('/api/v1/events')->assertStatus(401);
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
6+
it('returns field service tasks for authenticated user', function () {
7+
$tenant = Tenant::factory()->create();
8+
$user = User::factory()->create(['tenant_id' => $tenant->id]);
9+
$token = $user->createToken('test')->plainTextToken;
10+
$response = $this->withToken($token)->getJson('/api/v1/field-service/tasks');
11+
$response->assertStatus(200)->assertJsonStructure(['success', 'data', 'meta']);
12+
});
13+
14+
it('requires authentication for field service tasks', function () {
15+
$this->getJson('/api/v1/field-service/tasks')->assertStatus(401);
16+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
use App\Modules\Frontdesk\Models\FrontdeskStation;
6+
use Database\Seeders\RolePermissionSeeder;
7+
8+
beforeEach(function () {
9+
$this->seed(RolePermissionSeeder::class);
10+
$this->tenant = Tenant::create(['name' => 'Desk Co', 'slug' => 'desk-co']);
11+
$this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
12+
$this->user->assignRole('super-admin');
13+
$this->token = $this->user->createToken('test')->plainTextToken;
14+
app()->instance('tenant', $this->tenant);
15+
});
16+
17+
it('returns stations for authenticated user', function () {
18+
FrontdeskStation::create([
19+
'tenant_id' => $this->tenant->id,
20+
'name' => 'Main Entrance',
21+
'location' => 'Ground Floor',
22+
'is_active' => true,
23+
]);
24+
25+
$response = $this->withToken($this->token)->getJson('/api/v1/frontdesk/stations');
26+
27+
$response->assertStatus(200)
28+
->assertJsonStructure(['success', 'data', 'meta']);
29+
});
30+
31+
it('requires authentication for stations', function () {
32+
$this->getJson('/api/v1/frontdesk/stations')->assertStatus(401);
33+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
use App\Modules\Lunch\Models\LunchSupplier;
6+
use Database\Seeders\RolePermissionSeeder;
7+
8+
beforeEach(function () {
9+
$this->seed(RolePermissionSeeder::class);
10+
$this->tenant = Tenant::create(['name' => 'Lunch Co', 'slug' => 'lunch-co']);
11+
$this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
12+
$this->user->assignRole('super-admin');
13+
$this->token = $this->user->createToken('test')->plainTextToken;
14+
app()->instance('tenant', $this->tenant);
15+
});
16+
17+
it('returns suppliers for authenticated user', function () {
18+
LunchSupplier::create([
19+
'tenant_id' => $this->tenant->id,
20+
'name' => 'Pizza Palace',
21+
'is_active' => true,
22+
]);
23+
24+
$response = $this->withToken($this->token)->getJson('/api/v1/lunch/suppliers');
25+
26+
$response->assertStatus(200)
27+
->assertJsonStructure(['success', 'data', 'meta']);
28+
});
29+
30+
it('requires authentication for suppliers', function () {
31+
$this->getJson('/api/v1/lunch/suppliers')->assertStatus(401);
32+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
use App\Modules\Planning\Models\Shift;
6+
use Database\Seeders\RolePermissionSeeder;
7+
8+
beforeEach(function () {
9+
$this->seed(RolePermissionSeeder::class);
10+
$this->tenant = Tenant::create(['name' => 'Planning Co', 'slug' => 'planning-co']);
11+
$this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
12+
$this->user->assignRole('super-admin');
13+
$this->token = $this->user->createToken('test')->plainTextToken;
14+
app()->instance('tenant', $this->tenant);
15+
});
16+
17+
it('returns shifts for authenticated user', function () {
18+
Shift::create([
19+
'tenant_id' => $this->tenant->id,
20+
'employee_id' => $this->user->id,
21+
'title' => 'Morning Shift',
22+
'starts_at' => now()->addDay()->setTime(8, 0),
23+
'ends_at' => now()->addDay()->setTime(16, 0),
24+
'status' => 'scheduled',
25+
]);
26+
27+
$response = $this->withToken($this->token)->getJson('/api/v1/planning/shifts');
28+
29+
$response->assertStatus(200)
30+
->assertJsonStructure(['success', 'data', 'meta']);
31+
});
32+
33+
it('requires authentication for shifts', function () {
34+
$this->getJson('/api/v1/planning/shifts')->assertStatus(401);
35+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use App\Models\User;
4+
use App\Modules\Core\Models\Tenant;
5+
use App\Modules\Sign\Models\SignRequest;
6+
use Database\Seeders\RolePermissionSeeder;
7+
8+
beforeEach(function () {
9+
$this->seed(RolePermissionSeeder::class);
10+
$this->tenant = Tenant::create(['name' => 'Sign Co', 'slug' => 'sign-co']);
11+
$this->user = User::factory()->create(['tenant_id' => $this->tenant->id]);
12+
$this->user->assignRole('super-admin');
13+
$this->token = $this->user->createToken('test')->plainTextToken;
14+
app()->instance('tenant', $this->tenant);
15+
});
16+
17+
it('returns documents for authenticated user', function () {
18+
SignRequest::create([
19+
'tenant_id' => $this->tenant->id,
20+
'title' => 'NDA Agreement',
21+
'document_name' => 'nda.pdf',
22+
'document_path' => 'documents/nda.pdf',
23+
'status' => 'draft',
24+
'created_by' => $this->user->id,
25+
]);
26+
27+
$response = $this->withToken($this->token)->getJson('/api/v1/sign/documents');
28+
29+
$response->assertStatus(200)
30+
->assertJsonStructure(['success', 'data', 'meta']);
31+
});
32+
33+
it('requires authentication for documents', function () {
34+
$this->getJson('/api/v1/sign/documents')->assertStatus(401);
35+
});

0 commit comments

Comments
 (0)