129 lines
4 KiB
PHP
129 lines
4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\OpenApi\V1\Brands;
|
|
|
|
use Infra\Database\Models\ArcadiaBrand;
|
|
use Infra\Database\Models\Brand;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Spectator\Spectator;
|
|
|
|
beforeEach(function (): void {
|
|
/** @var \Tests\TestCase $this */
|
|
Spectator::reset();
|
|
Spectator::using('openapi.yaml');
|
|
|
|
Brand::query()->delete();
|
|
ArcadiaBrand::query()->delete();
|
|
});
|
|
|
|
describe('Brand OpenAPI Conformance', function (): void {
|
|
it('validates GET /api/v1/brands list response against openapi spec', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
|
|
ArcadiaBrand::factory()->create([
|
|
'code' => 1,
|
|
'libelle' => 'Le Gaulois',
|
|
]);
|
|
ArcadiaBrand::factory()->create([
|
|
'code' => 2,
|
|
'libelle' => 'Maître CoQ',
|
|
]);
|
|
|
|
// WHEN
|
|
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
|
$response = $test->getJson('/api/v1/brands');
|
|
|
|
// THEN
|
|
$response->assertStatus(200);
|
|
$response->assertValidRequest();
|
|
$response->assertValidResponse(200);
|
|
});
|
|
|
|
it('validates GET /api/v1/brands/{identifier} detail response by UUID against openapi spec', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
|
|
$arcadia = ArcadiaBrand::factory()->create([
|
|
'code' => 1,
|
|
'libelle' => 'Le Gaulois',
|
|
]);
|
|
|
|
$uuid = Uuid::uuid7()->toString();
|
|
Brand::factory()->create([
|
|
'id' => $uuid,
|
|
'arcadia_id' => $arcadia->code,
|
|
'uwil_public_id' => 'LGL01',
|
|
]);
|
|
|
|
// WHEN
|
|
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
|
$response = $test->getJson("/api/v1/brands/{$uuid}");
|
|
|
|
// THEN
|
|
$response->assertStatus(200);
|
|
$response->assertValidRequest();
|
|
$response->assertValidResponse(200);
|
|
});
|
|
|
|
it('validates GET /api/v1/brands/{identifier} detail response by BrandCode against openapi spec', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
|
|
$arcadia = ArcadiaBrand::factory()->create([
|
|
'code' => 2,
|
|
'libelle' => 'Maître CoQ',
|
|
]);
|
|
|
|
Brand::factory()->create([
|
|
'id' => Uuid::uuid7()->toString(),
|
|
'arcadia_id' => $arcadia->code,
|
|
'uwil_public_id' => 'MCQ02',
|
|
]);
|
|
|
|
// WHEN
|
|
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
|
$response = $test->getJson('/api/v1/brands/MCQ02');
|
|
|
|
// THEN
|
|
$response->assertStatus(200);
|
|
$response->assertValidRequest();
|
|
$response->assertValidResponse(200);
|
|
});
|
|
|
|
it('validates GET /api/v1/brands/{identifier} not found response against openapi spec', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
$unexistingId = Uuid::uuid7()->toString();
|
|
|
|
// WHEN
|
|
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
|
$response = $test->getJson("/api/v1/brands/{$unexistingId}");
|
|
|
|
// THEN
|
|
$response->assertStatus(404);
|
|
$response->assertValidRequest();
|
|
$response->assertValidResponse(404);
|
|
});
|
|
|
|
it('validates GET /api/v1/brands/{identifier} validation error for invalid identifier', function (): void {
|
|
// GIVEN
|
|
/** @var \Tests\TestCase $test */
|
|
$test = $this;
|
|
$invalidId = 'invalid-format-123';
|
|
|
|
// WHEN
|
|
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
|
|
$response = $test->getJson("/api/v1/brands/{$invalidId}");
|
|
|
|
// THEN
|
|
$response->assertStatus(422);
|
|
$response->assertValidResponse(422);
|
|
});
|
|
});
|