|
| 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 | +}); |
0 commit comments