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
|
|
@ -39,6 +39,16 @@ class InfoProviderEndpointTest extends AuthenticatedApiTestCase
|
|||
|
||||
$keys = array_column($json['hydra:member'], 'key');
|
||||
self::assertContains('test', $keys);
|
||||
|
||||
//The 'test' provider has a disabledHelp set internally, but it must not leak into the API response
|
||||
$testProvider = $json['hydra:member'][array_search('test', $keys, true)];
|
||||
self::assertArrayHasKey('capabilities', $testProvider);
|
||||
self::assertArrayNotHasKey('disabledHelp', $testProvider);
|
||||
self::assertArrayNotHasKey('oauthAppName', $testProvider);
|
||||
self::assertArrayNotHasKey('settingsClass', $testProvider);
|
||||
|
||||
//Capabilities must serialize as plain enum-name strings, not objects
|
||||
self::assertSame(['BASIC', 'FOOTPRINT'], $testProvider['capabilities']);
|
||||
}
|
||||
|
||||
public function testListInfoProvidersRequiresAuthentication(): void
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ namespace App\Tests\Services\InfoProviderSystem\DTOs;
|
|||
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use App\Services\InfoProviderSystem\DTOs\BulkSearchFieldMappingDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class BulkSearchFieldMappingDTOTest extends TestCase
|
||||
|
|
@ -32,7 +33,7 @@ final class BulkSearchFieldMappingDTOTest extends TestCase
|
|||
public function testProviderInstanceNormalization(): void
|
||||
{
|
||||
$mockProvider = $this->createMock(InfoProviderInterface::class);
|
||||
$mockProvider->method('getProviderKey')->willReturn('mock_provider');
|
||||
$mockProvider->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: 'mock_provider', name: 'mock_provider'));
|
||||
|
||||
$fieldMapping = new BulkSearchFieldMappingDTO(field: 'mpn', providers: ['provider1', $mockProvider], priority: 5);
|
||||
$this->assertSame(['provider1', 'mock_provider'], $fieldMapping->providers);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace App\Tests\Services\InfoProviderSystem;
|
||||
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use App\Services\InfoProviderSystem\ProviderRegistry;
|
||||
use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
||||
use App\Services\InfoProviderSystem\Providers\URLHandlerInfoProviderInterface;
|
||||
|
|
@ -46,7 +47,7 @@ final class ProviderRegistryTest extends TestCase
|
|||
public function getMockProvider(string $key, bool $active = true): InfoProviderInterface
|
||||
{
|
||||
$mock = $this->createMockForIntersectionOfInterfaces([InfoProviderInterface::class, URLHandlerInfoProviderInterface::class]);
|
||||
$mock->method('getProviderKey')->willReturn($key);
|
||||
$mock->method('getProviderInfo')->willReturn(new ProviderInfoDTO(key: $key, name: $key));
|
||||
$mock->method('isActive')->willReturn($active);
|
||||
$mock->method('getHandledDomains')->willReturn(["$key.com", "test.$key.de"]);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
|||
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||
use App\Services\InfoProviderSystem\Providers\LCSCProvider;
|
||||
use App\Services\InfoProviderSystem\Providers\ProviderCapabilities;
|
||||
|
|
@ -56,18 +57,10 @@ final class LCSCProviderTest extends TestCase
|
|||
{
|
||||
$info = $this->provider->getProviderInfo();
|
||||
|
||||
$this->assertIsArray($info);
|
||||
$this->assertArrayHasKey('name', $info);
|
||||
$this->assertArrayHasKey('description', $info);
|
||||
$this->assertArrayHasKey('url', $info);
|
||||
$this->assertArrayHasKey('disabled_help', $info);
|
||||
$this->assertEquals('LCSC', $info['name']);
|
||||
$this->assertEquals('https://www.lcsc.com/', $info['url']);
|
||||
}
|
||||
|
||||
public function testGetProviderKey(): void
|
||||
{
|
||||
$this->assertSame('lcsc', $this->provider->getProviderKey());
|
||||
$this->assertInstanceOf(ProviderInfoDTO::class, $info);
|
||||
$this->assertSame('lcsc', $info->key);
|
||||
$this->assertEquals('LCSC', $info->name);
|
||||
$this->assertEquals('https://www.lcsc.com/', $info->url);
|
||||
}
|
||||
|
||||
public function testIsActiveWhenEnabled(): void
|
||||
|
|
@ -86,7 +79,7 @@ final class LCSCProviderTest extends TestCase
|
|||
|
||||
public function testGetCapabilities(): void
|
||||
{
|
||||
$capabilities = $this->provider->getCapabilities();
|
||||
$capabilities = $this->provider->getProviderInfo()->capabilities;
|
||||
|
||||
$this->assertIsArray($capabilities);
|
||||
$this->assertContains(ProviderCapabilities::BASIC, $capabilities);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ namespace App\Tests\Services\InfoProviderSystem\Providers;
|
|||
|
||||
use App\Entity\Parts\ManufacturingStatus;
|
||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\ProviderInfoDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
||||
use App\Services\InfoProviderSystem\Providers\ProviderCapabilities;
|
||||
|
|
@ -212,17 +213,10 @@ final class TMEProviderTest extends TestCase
|
|||
{
|
||||
$info = $this->provider->getProviderInfo();
|
||||
|
||||
$this->assertIsArray($info);
|
||||
$this->assertArrayHasKey('name', $info);
|
||||
$this->assertArrayHasKey('description', $info);
|
||||
$this->assertArrayHasKey('url', $info);
|
||||
$this->assertEquals('TME', $info['name']);
|
||||
$this->assertEquals('https://tme.eu/', $info['url']);
|
||||
}
|
||||
|
||||
public function testGetProviderKey(): void
|
||||
{
|
||||
$this->assertSame('tme', $this->provider->getProviderKey());
|
||||
$this->assertInstanceOf(ProviderInfoDTO::class, $info);
|
||||
$this->assertSame('tme', $info->key);
|
||||
$this->assertEquals('TME', $info->name);
|
||||
$this->assertEquals('https://tme.eu/', $info->url);
|
||||
}
|
||||
|
||||
public function testIsActiveWithCredentials(): void
|
||||
|
|
@ -239,7 +233,7 @@ final class TMEProviderTest extends TestCase
|
|||
|
||||
public function testGetCapabilities(): void
|
||||
{
|
||||
$capabilities = $this->provider->getCapabilities();
|
||||
$capabilities = $this->provider->getProviderInfo()->capabilities;
|
||||
|
||||
$this->assertIsArray($capabilities);
|
||||
$this->assertContains(ProviderCapabilities::BASIC, $capabilities);
|
||||
|
|
|
|||
|
|
@ -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