v1.0.0
This commit is contained in:
61
src/tests/Feature/DictionariesApiTest.php
Normal file
61
src/tests/Feature/DictionariesApiTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ApiClient;
|
||||
use App\Models\Category;
|
||||
use App\Models\Priority;
|
||||
use App\Models\Status;
|
||||
use App\Models\Team;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
test('categories are returned with subcategories and custom fields', function () {
|
||||
$category = Category::query()->create(['name' => 'IT']);
|
||||
$sub = $category->subcategories()->create(['name' => 'VPN']);
|
||||
|
||||
$client = ApiClient::factory()->create();
|
||||
Sanctum::actingAs($client, ['dictionaries:read']);
|
||||
|
||||
$this->getJson('/api/v1/categories')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.name', 'IT')
|
||||
->assertJsonPath('data.0.subcategories.0.name', 'VPN');
|
||||
});
|
||||
|
||||
test('statuses are returned ordered by sort_order', function () {
|
||||
seedStatusesAndPriorities();
|
||||
|
||||
$client = ApiClient::factory()->create();
|
||||
Sanctum::actingAs($client, ['dictionaries:read']);
|
||||
|
||||
$this->getJson('/api/v1/statuses')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.key', 'new');
|
||||
});
|
||||
|
||||
test('priorities are returned ordered by sort_order', function () {
|
||||
seedStatusesAndPriorities();
|
||||
|
||||
$client = ApiClient::factory()->create();
|
||||
Sanctum::actingAs($client, ['dictionaries:read']);
|
||||
|
||||
$this->getJson('/api/v1/priorities')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.key', 'high');
|
||||
});
|
||||
|
||||
test('teams are returned', function () {
|
||||
Team::query()->create(['name' => 'Infra']);
|
||||
|
||||
$client = ApiClient::factory()->create();
|
||||
Sanctum::actingAs($client, ['dictionaries:read']);
|
||||
|
||||
$this->getJson('/api/v1/teams')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.name', 'Infra');
|
||||
});
|
||||
|
||||
test('dictionaries require the dictionaries:read ability', function () {
|
||||
$client = ApiClient::factory()->create();
|
||||
Sanctum::actingAs($client, ['tickets:read']);
|
||||
|
||||
$this->getJson('/api/v1/categories')->assertForbidden();
|
||||
});
|
||||
Reference in New Issue
Block a user