Skip to content

Commit

Permalink
Merge pull request #6 from answear/fix-search-by-image-response-objec…
Browse files Browse the repository at this point in the history
…t-creating

Fix SearchByImageResponse creating
  • Loading branch information
jrawska committed Dec 11, 2020
2 parents 82dfaf3 + f2797d9 commit 82b9241
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/Response/SearchByFeatureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private function __construct(array $uids)
public static function fromArray(array $response): SearchByFeatureResponse
{
try {
$products = $response['products'];
$products = $response[0]['products'];
$responseUids = array_map(
static function ($item) {
Assert::keyExists($item, 'uid');
Expand Down
70 changes: 39 additions & 31 deletions tests/Unit/Response/SearchByFeatureResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ class SearchByFeatureResponseTest extends TestCase
public function correctlyReturnsUids(): void
{
$responseData = [
'products' => [
[
'uid' => 'uid1',
],
[
'uid' => 'uid2',
],
[
'uid' => 'uid3',
[
'products' => [
[
'uid' => 'uid1',
],
[
'uid' => 'uid2',
],
[
'uid' => 'uid3',
],
],
],
];
Expand All @@ -47,15 +49,17 @@ public function correctlyReturnsUids(): void
public function malformedResponseWithoutUidInOneItem(): void
{
$responseData = [
'products' => [
[
'uid' => 'uid1',
],
[
'id' => 'uid2',
],
[
'uid' => 'uid3',
[
'products' => [
[
'uid' => 'uid1',
],
[
'id' => 'uid2',
],
[
'uid' => 'uid3',
],
],
],
];
Expand All @@ -70,12 +74,14 @@ public function malformedResponseWithoutUidInOneItem(): void
public function malformedResponseWithoutUid(): void
{
$responseData = [
'products' => [
[
'result' => 'uid1',
],
[
'result' => 'uid2',
[
'products' => [
[
'result' => 'uid1',
],
[
'result' => 'uid2',
],
],
],
];
Expand All @@ -91,13 +97,15 @@ public function malformedResponseWithoutProducts(): void
{
$responseData = [
[
'uid' => 'uid1',
],
[
'uid' => 'uid2',
],
[
'uid' => 'uid3',
[
'uid' => 'uid1',
],
[
'uid' => 'uid2',
],
[
'uid' => 'uid3',
],
],
];

Expand Down
32 changes: 18 additions & 14 deletions tests/Unit/Service/SearchByImageClientSearchByFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,19 @@ private function prepareProperResponse(string $uid1, string $uid2, string $uid3)
{
$result = [
'results' => [
'products' => [
[
'uid' => $uid1,
'otherData' => 'some data',
],
[
'uid' => $uid2,
],
[
'uid' => $uid3,
'category' => 'category',
[
'products' => [
[
'uid' => $uid1,
'otherData' => 'some data',
],
[
'uid' => $uid2,
],
[
'uid' => $uid3,
'category' => 'category',
],
],
],
],
Expand All @@ -154,9 +156,11 @@ private function prepareNotProperResponse(): string
return \json_encode(
[
'results' => [
'items' => [
[
'uid' => 'uid',
[
'items' => [
[
'uid' => 'uid',
],
],
],
],
Expand Down

0 comments on commit 82b9241

Please sign in to comment.