mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-27 13:29:32 +00:00
Added tests for new DTO objects
This commit is contained in:
parent
b94e28a961
commit
5b71d68179
5 changed files with 186 additions and 7 deletions
|
|
@ -206,6 +206,53 @@ class BulkSearchResponseDTOTest extends KernelTestCase
|
|||
|
||||
$deserialized = BulkSearchResponseDTO::fromSerializableRepresentation($input, $this->entityManager);
|
||||
$this->assertEquals($this->dummy, $deserialized);
|
||||
}
|
||||
|
||||
public function testMerge(): void
|
||||
{
|
||||
$merged = BulkSearchResponseDTO::merge($this->dummy, $this->dummyEmpty);
|
||||
$this->assertCount(1, $merged->partResults);
|
||||
|
||||
$merged = BulkSearchResponseDTO::merge($this->dummyEmpty, $this->dummyEmpty);
|
||||
$this->assertCount(0, $merged->partResults);
|
||||
|
||||
$merged = BulkSearchResponseDTO::merge($this->dummy, $this->dummy, $this->dummy);
|
||||
$this->assertCount(3, $merged->partResults);
|
||||
}
|
||||
|
||||
public function testReplaceResultsForPart(): void
|
||||
{
|
||||
$newPartResults = new BulkSearchPartResultsDTO(
|
||||
part: $this->entityManager->find(Part::class, 1),
|
||||
searchResults: [
|
||||
new BulkSearchPartResultDTO(
|
||||
searchResult: new SearchResultDTO(provider_key: "new", provider_id: "new", name: "New Part", description: "A new part"),
|
||||
sourceField: "mpn", sourceKeyword: "new", priority: 1
|
||||
)
|
||||
],
|
||||
errors: ['New Error']
|
||||
);
|
||||
|
||||
$replaced = $this->dummy->replaceResultsForPart($newPartResults);
|
||||
$this->assertCount(1, $replaced->partResults);
|
||||
$this->assertSame($newPartResults, $replaced->partResults[0]);
|
||||
}
|
||||
|
||||
public function testReplaceResultsForPartNotExisting(): void
|
||||
{
|
||||
$newPartResults = new BulkSearchPartResultsDTO(
|
||||
part: $this->entityManager->find(Part::class, 1),
|
||||
searchResults: [
|
||||
new BulkSearchPartResultDTO(
|
||||
searchResult: new SearchResultDTO(provider_key: "new", provider_id: "new", name: "New Part", description: "A new part"),
|
||||
sourceField: "mpn", sourceKeyword: "new", priority: 1
|
||||
)
|
||||
],
|
||||
errors: ['New Error']
|
||||
);
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$replaced = $this->dummyEmpty->replaceResultsForPart($newPartResults);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue