mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-07-27 03:31:35 +00:00
Reworked info provider system to merge all provider metadata into a unified DTO
This commit is contained in:
parent
661cc5a052
commit
071ffe322d
39 changed files with 412 additions and 533 deletions
|
|
@ -26,6 +26,7 @@ namespace App\Tests\State\Mcp;
|
|||
use ApiPlatform\Metadata\Get;
|
||||
use App\Mcp\DTO\InfoProviderPartDetailsInput;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use App\Services\InfoProviderSystem\DTOtoEntityConverter;
|
||||
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
|
|
@ -45,14 +46,14 @@ final class GetInfoProviderPartDetailsProcessorTest extends TestCase
|
|||
protected function setUp(): void
|
||||
{
|
||||
$activeProvider = $this->createMock(InfoProviderInterface::class);
|
||||
$activeProvider->method('getProviderKey')->willReturn('test1');
|
||||
$activeProvider->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: 'test1', name: 'test1'));
|
||||
$activeProvider->method('isActive')->willReturn(true);
|
||||
$activeProvider->method('getDetails')->willReturn(
|
||||
new PartDetailDTO(provider_key: 'test1', provider_id: '42', name: 'Element 42', description: 'desc')
|
||||
);
|
||||
|
||||
$inactiveProvider = $this->createMock(InfoProviderInterface::class);
|
||||
$inactiveProvider->method('getProviderKey')->willReturn('test2');
|
||||
$inactiveProvider->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: 'test2', name: 'test2'));
|
||||
$inactiveProvider->method('isActive')->willReturn(false);
|
||||
|
||||
$providerRegistry = new ProviderRegistry([$activeProvider, $inactiveProvider]);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace App\Tests\State\Mcp;
|
|||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Mcp\DTO\ListInfoProvidersInput;
|
||||
use App\Services\InfoProviderSystem\DTOs\InfoProviderDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use App\Services\InfoProviderSystem\Providers\ProviderCapabilities;
|
||||
use App\Services\InfoProviderSystem\ProviderRegistry;
|
||||
|
|
@ -37,20 +37,18 @@ final class ListInfoProvidersProcessorTest extends TestCase
|
|||
public function testOnlyActiveProvidersAreListed(): void
|
||||
{
|
||||
$active = $this->createMock(InfoProviderInterface::class);
|
||||
$active->method('getProviderKey')->willReturn('active_provider');
|
||||
$active->method('isActive')->willReturn(true);
|
||||
$active->method('getProviderInfo')->willReturn([
|
||||
'name' => 'Active Provider',
|
||||
'description' => 'A provider that is active',
|
||||
'url' => 'https://example.com',
|
||||
]);
|
||||
$active->method('getCapabilities')->willReturn([ProviderCapabilities::BASIC, ProviderCapabilities::PRICE]);
|
||||
$active->method('getProviderInfo')->willReturn(new ProviderInfoDTO(
|
||||
key: 'active_provider',
|
||||
name: 'Active Provider',
|
||||
description: 'A provider that is active',
|
||||
url: 'https://example.com',
|
||||
capabilities: [ProviderCapabilities::BASIC, ProviderCapabilities::PRICE],
|
||||
));
|
||||
|
||||
$disabled = $this->createMock(InfoProviderInterface::class);
|
||||
$disabled->method('getProviderKey')->willReturn('disabled_provider');
|
||||
$disabled->method('isActive')->willReturn(false);
|
||||
$disabled->method('getProviderInfo')->willReturn(['name' => 'Disabled Provider']);
|
||||
$disabled->method('getCapabilities')->willReturn([]);
|
||||
$disabled->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: 'disabled_provider', name: 'Disabled Provider'));
|
||||
|
||||
$registry = new ProviderRegistry([$active, $disabled]);
|
||||
$processor = new ListInfoProvidersProcessor($registry);
|
||||
|
|
@ -58,11 +56,11 @@ final class ListInfoProvidersProcessorTest extends TestCase
|
|||
$result = $processor->process(new ListInfoProvidersInput(), new Get());
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertInstanceOf(InfoProviderDTO::class, $result[0]);
|
||||
$this->assertInstanceOf(ProviderInfoDTO::class, $result[0]);
|
||||
$this->assertSame('active_provider', $result[0]->key);
|
||||
$this->assertSame('Active Provider', $result[0]->name);
|
||||
$this->assertSame('A provider that is active', $result[0]->description);
|
||||
$this->assertSame('https://example.com', $result[0]->url);
|
||||
$this->assertSame(['BASIC', 'PRICE'], $result[0]->capabilities);
|
||||
$this->assertSame([ProviderCapabilities::BASIC, ProviderCapabilities::PRICE], $result[0]->capabilities);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ namespace App\Tests\State\Mcp;
|
|||
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Mcp\DTO\InfoProviderSearchInput;
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
||||
use App\Services\InfoProviderSystem\DTOtoEntityConverter;
|
||||
use App\Services\InfoProviderSystem\PartInfoRetriever;
|
||||
|
|
@ -69,8 +70,8 @@ final class SearchInfoProvidersProcessorTest extends TestCase
|
|||
private function getMockProvider(string $key, bool $active = true): InfoProviderInterface
|
||||
{
|
||||
$mock = $this->createMock(InfoProviderInterface::class);
|
||||
$mock->method('getProviderKey')->willReturn($key);
|
||||
$mock->method('isActive')->willReturn($active);
|
||||
$mock->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: $key, name: $key));
|
||||
$mock->method('searchByKeyword')->willReturn([
|
||||
new SearchResultDTO(provider_key: $key, provider_id: '1', name: 'Element 1', description: 'desc'),
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue