2015-05-04 18:47:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace RetailCrm\Tests;
|
|
|
|
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
|
2016-03-12 01:54:33 +03:00
|
|
|
/**
|
|
|
|
* Class ApiClientStoreTest
|
|
|
|
* @package RetailCrm\Tests
|
|
|
|
*/
|
2015-05-04 18:47:14 +03:00
|
|
|
class ApiClientStoreTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @group integration
|
|
|
|
*/
|
|
|
|
public function testStoreInventories()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$response = $client->storeInventories();
|
|
|
|
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
$this->assertEquals(200, $response->getStatusCode());
|
|
|
|
$this->assertTrue($response->success);
|
|
|
|
$this->assertTrue(
|
|
|
|
isset($response['offers']),
|
|
|
|
'API returns orders assembly history'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group unit
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testStoreInventoriesUploadExceptionEmpty()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
2016-03-12 01:54:33 +03:00
|
|
|
$client->storeInventoriesUpload(array());
|
2015-05-04 18:47:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group integration
|
|
|
|
*/
|
|
|
|
public function testStoreInventoriesUpload()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$externalIdA = 'upload-a-' . time();
|
|
|
|
$externalIdB = 'upload-b-' . time();
|
|
|
|
|
|
|
|
$response = $client->storeInventoriesUpload(array(
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdA,
|
2016-03-12 01:54:33 +03:00
|
|
|
'stores' => array(
|
|
|
|
array(
|
|
|
|
'code' => $_SERVER['CRM_STORE'],
|
|
|
|
'available' => 10,
|
|
|
|
'purchasePrice' => 1700
|
|
|
|
)
|
|
|
|
)
|
2015-05-04 18:47:14 +03:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdB,
|
2016-03-12 01:54:33 +03:00
|
|
|
'stores' => array(
|
|
|
|
array(
|
|
|
|
'code' => $_SERVER['CRM_STORE'],
|
|
|
|
'available' => 20,
|
|
|
|
'purchasePrice' => 1500
|
|
|
|
)
|
|
|
|
)
|
2015-05-04 18:47:14 +03:00
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
2016-03-12 01:54:33 +03:00
|
|
|
$this->assertTrue($response->isSuccessful());
|
2015-05-04 18:47:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group integration
|
|
|
|
*/
|
|
|
|
public function testStoreInventoriesUploadFailed()
|
|
|
|
{
|
|
|
|
$client = static::getApiClient();
|
|
|
|
|
|
|
|
$externalIdA = 'upload-a-' . time();
|
|
|
|
$externalIdB = 'upload-b-' . time();
|
|
|
|
|
|
|
|
$response = $client->storeInventoriesUpload(array(
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdA,
|
|
|
|
'available' => 10,
|
|
|
|
'purchasePrice' => 1700
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'externalId' => $externalIdB,
|
|
|
|
'available' => 20,
|
|
|
|
'purchasePrice' => 1500
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response);
|
|
|
|
$this->assertEquals(400, $response->getStatusCode());
|
|
|
|
$this->assertTrue(isset($response['errorMsg']), $response['errorMsg']);
|
|
|
|
}
|
|
|
|
}
|