Skip to content

Commit

Permalink
fix #62 again
Browse files Browse the repository at this point in the history
  • Loading branch information
gam6itko authored Jul 17, 2023
1 parent 9c3a2b5 commit 0f0b5e9
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Service/V3/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@
use Gam6itko\OzonSeller\Service\AbstractService;
use Gam6itko\OzonSeller\Utils\ArrayHelper;

/**
* @psalm-type TInfoStocksRequestFilter = array{
* offer_id: list<string>,
* product_id: list<string>,
* visibility: string
* }
* @psalm-type TInfoStocksResponseStocks = array{
* present: int,
* reserver: int,
* type: string
* }
* @psalm-type TInfoStocksResponseItem = array{
* offer_id: string,
* product_id: int,
* stocks: list<TInfoStocksResponseStocks>
* }
* @psalm-type TInfoStocksResponse = array{
* items: list<TInfoStocksResponseItem>,
* last_id: string,
* limit: int
* }
*/
class ProductService extends AbstractService
{
private $path = '/v3/product';
Expand Down Expand Up @@ -37,4 +59,20 @@ public function infoAttributes(array $filter, ?string $lastId = '', int $limit =

return $this->request('POST', "{$this->path}s/info/attributes", $body);
}

/**
* @param TInfoStocksRequestFilter $filter
*
* @return TInfoStocksResponse
*/
public function infoStocks(array $filter, ?string $lastId = '', int $limit = 100): array
{
$body = [
'filter' => ArrayHelper::pick($filter, ['offer_id', 'product_id', 'visibility']),
'last_id' => $lastId ?? '',
'limit' => $limit,
];

return $this->request('POST', "{$this->path}/info/stocks", $body);
}
}
48 changes: 48 additions & 0 deletions tests/Service/V3/ProductServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Gam6itko\OzonSeller\Tests\Service\V3;

use Gam6itko\OzonSeller\Service\V3\ProductService;
use Gam6itko\OzonSeller\Tests\Service\AbstractTestCase;

/**
* @coversDefaultClass \Gam6itko\OzonSeller\Service\V3\ProductService
*/
final class ProductServiceTest extends AbstractTestCase
{
protected function getClass(): string
{
return ProductService::class;
}

/**
* @covers ::infoStocks
*/
public function testList(): void
{
$payload = [
'filter' => [
'offer_id' => ['offer_id'],
'product_id' => ['offer_id'],
'visibility' => 'ALL',
],
'last_id' => '1',
'limit' => 100,
];
$this->quickTest(
'infoStocks',
[
$payload['filter'],
$payload['last_id'],
$payload['limit'],
],
[
'POST',
'/v3/product/info/stocks',
\json_encode($payload),
]
);
}
}

0 comments on commit 0f0b5e9

Please sign in to comment.