ldc-arcadia-api/tests/Feature/OpenApi/V1/Brands/BrandOpenApiTest.php

102 lines
3.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\OpenApi\V1\Brands;
use Database\ArcadiaReplicate\Factories\Refp\MarqueFactory;
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();
MarqueFactory::truncate();
});
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;
MarqueFactory::new()->create([
'COD_MARQ' => 1,
'LIB_MARQ' => 'Le Gaulois',
]);
MarqueFactory::new()->create([
'COD_MARQ' => 2,
'LIB_MARQ' => '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/{brandCode} detail response by BrandCode against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$arcadia = MarqueFactory::new()->create([
'COD_MARQ' => 2,
'LIB_MARQ' => 'Maître CoQ',
]);
Brand::factory()->create([
'id' => Uuid::uuid7()->toString(),
'arcadia_id' => $arcadia['COD_MARQ'],
'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/{brandCode} not found response against openapi spec', function (): void {
// GIVEN
/** @var \Tests\TestCase $test */
$test = $this;
$unexistingCode = 'ZZZ98';
// WHEN
/** @var \Illuminate\Testing\TestResponse<\Symfony\Component\HttpFoundation\Response> $response */
$response = $test->getJson("/api/v1/brands/{$unexistingCode}");
// THEN
$response->assertStatus(404);
$response->assertValidRequest();
$response->assertValidResponse(404);
});
it('validates GET /api/v1/brands/{brandCode} 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);
});
});