Files
famous-ly4-ev/app-modules/catalog/tests/Feature/CatalogReadApiTest.php
T

40 lines
1.3 KiB
PHP
Raw Normal View History

<?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();
});