Add Departure Time Slot and Catalog read API (T2.4, T2.5)
Adds the shared DepartureTimeSlot catalog entity with its Filament resource, and public GET /api/v1/companies + /api/v1/destinations endpoints (auth:sanctum + throttled) for the mini app/mobile/agent clients to consume.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Modules\Catalog\Models\Destination;
|
||||
use Modules\Catalog\Models\EvCompany;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->token = User::factory()->create()->createToken('test-token')->plainTextToken;
|
||||
});
|
||||
|
||||
test('lists active ev companies', function () {
|
||||
$active = EvCompany::factory()->create(['is_active' => true]);
|
||||
EvCompany::factory()->create(['is_active' => false]);
|
||||
|
||||
$this->withHeader('Authorization', "Bearer {$this->token}")
|
||||
->getJson('/api/v1/companies')
|
||||
->assertSuccessful()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonFragment(['id' => $active->id]);
|
||||
});
|
||||
|
||||
test('lists active destinations', function () {
|
||||
$active = Destination::factory()->create(['is_active' => true]);
|
||||
Destination::factory()->create(['is_active' => false]);
|
||||
|
||||
$this->withHeader('Authorization', "Bearer {$this->token}")
|
||||
->getJson('/api/v1/destinations')
|
||||
->assertSuccessful()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonFragment(['id' => $active->id]);
|
||||
});
|
||||
|
||||
test('companies endpoint rejects unauthenticated requests', function () {
|
||||
$this->getJson('/api/v1/companies')->assertUnauthorized();
|
||||
});
|
||||
|
||||
test('destinations endpoint rejects unauthenticated requests', function () {
|
||||
$this->getJson('/api/v1/destinations')->assertUnauthorized();
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
use Modules\Catalog\Filament\Resources\DepartureTimeSlots\Pages\CreateDepartureTimeSlot;
|
||||
use Modules\Catalog\Filament\Resources\DepartureTimeSlots\Pages\EditDepartureTimeSlot;
|
||||
use Modules\Catalog\Filament\Resources\DepartureTimeSlots\Pages\ListDepartureTimeSlots;
|
||||
use Modules\Catalog\Models\DepartureTimeSlot;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
use function Pest\Laravel\assertDatabaseHas;
|
||||
|
||||
beforeEach(function () {
|
||||
Role::findOrCreate('admin', 'web');
|
||||
|
||||
$this->admin = User::factory()->create()->assignRole('admin');
|
||||
$this->actingAs($this->admin);
|
||||
});
|
||||
|
||||
test('can list departure time slots', function () {
|
||||
$timeSlots = DepartureTimeSlot::factory()->count(3)->create();
|
||||
|
||||
Livewire::test(ListDepartureTimeSlots::class)
|
||||
->assertOk()
|
||||
->assertCanSeeTableRecords($timeSlots);
|
||||
});
|
||||
|
||||
test('can create a departure time slot', function () {
|
||||
$timeSlot = DepartureTimeSlot::factory()->make();
|
||||
|
||||
Livewire::test(CreateDepartureTimeSlot::class)
|
||||
->fillForm([
|
||||
'label' => $timeSlot->label,
|
||||
'time' => $timeSlot->time,
|
||||
'is_active' => true,
|
||||
])
|
||||
->call('create')
|
||||
->assertNotified()
|
||||
->assertRedirect();
|
||||
|
||||
assertDatabaseHas(DepartureTimeSlot::class, [
|
||||
'label' => $timeSlot->label,
|
||||
]);
|
||||
});
|
||||
|
||||
test('can edit a departure time slot', function () {
|
||||
$timeSlot = DepartureTimeSlot::factory()->create();
|
||||
|
||||
Livewire::test(EditDepartureTimeSlot::class, ['record' => $timeSlot->getRouteKey()])
|
||||
->assertOk()
|
||||
->fillForm(['label' => 'Updated Label'])
|
||||
->call('save')
|
||||
->assertNotified();
|
||||
|
||||
assertDatabaseHas(DepartureTimeSlot::class, [
|
||||
'id' => $timeSlot->id,
|
||||
'label' => 'Updated Label',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a departure time slot is a shared catalog entity not owned by a single route', function () {
|
||||
$timeSlot = DepartureTimeSlot::factory()->create();
|
||||
|
||||
expect($timeSlot->getFillable())->not->toContain('ev_route_id');
|
||||
});
|
||||
Reference in New Issue
Block a user