Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
}

Route::get('/converters', [ConverterController::class, 'index'])->name('converters.index');
Route::get('/converters/{source}/{target}/schema', [ConverterController::class, 'schema'])->name('converters.schema');
});
});
40 changes: 40 additions & 0 deletions tests/Feature/Api/V1/ConverterSchemaEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

use App\Enums\Plan;
use App\Models\User;
use App\Services\Api\ApiKeyGenerator;

it('returns converter options schema for valid pair', function () {
$user = User::factory()->create(['plan' => Plan::Pro]);
$token = app(ApiKeyGenerator::class)->create($user, 'API')->plainToken;

$this->withToken($token)
->getJson('/api/v1/converters/png/jpg/schema')
->assertOk()
->assertJsonPath('data.source_format', 'png')
->assertJsonPath('data.target_format', 'jpg')
->assertJsonStructure([
'data' => [
'source_format',
'target_format',
'options',
],
]);
});

it('returns 422 for unsupported conversion pair', function () {
$user = User::factory()->create(['plan' => Plan::Pro]);
$token = app(ApiKeyGenerator::class)->create($user, 'API')->plainToken;

$this->withToken($token)
->getJson('/api/v1/converters/png/mp3/schema')
->assertStatus(422)
->assertJsonPath('error.code', 'unsupported_conversion');
});

it('requires api key authentication to get converter schema', function () {
$this->getJson('/api/v1/converters/png/jpg/schema')
->assertUnauthorized();
});