1
0
mirror of synced 2024-11-21 21:06:07 +03:00

units methods

This commit is contained in:
Akolzin Dmitry 2020-07-03 09:58:31 +03:00
parent 30dfcc7c68
commit 4073580394
2 changed files with 81 additions and 1 deletions

View File

@ -245,4 +245,49 @@ trait References
['courier' => json_encode($courier)]
);
}
/**
* Get units
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function unitsList()
{
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
'/reference/units',
"GET"
);
}
/**
* Edit unit
*
* @param array $unit
*
* @throws \InvalidArgumentException
* @throws \RetailCrm\Exception\CurlException
* @throws \RetailCrm\Exception\InvalidJsonException
*
* @return \RetailCrm\Response\ApiResponse
*/
public function unitsEdit(array $unit)
{
if (empty($unit['code']) || empty($unit['name']) || empty($unit['sym'])) {
throw new \InvalidArgumentException(
'`code`, `name` and `sym` parameters must not be empty.'
);
}
/* @noinspection PhpUndefinedMethodInspection */
return $this->client->makeRequest(
sprintf('/reference/units/%s/edit', $unit['code']),
"POST",
['unit' => json_encode($unit)]
);
}
}

View File

@ -137,6 +137,40 @@ class ApiClientReferenceTest extends TestCase
}
}
/**
* @group reference_v5
*/
public function testUnitsEditing()
{
$client = static::getApiClient();
$unit = [
'code' => 'test',
'name' => 'Test',
'sym' => 'tst'
];
$response = $client->request->unitsEdit($unit);
static::assertTrue(in_array($response->getStatusCode(), [200, 201]));
}
/**
* @group reference_v5
* @expectedException \InvalidArgumentException
*/
public function testUnitsEditingFail()
{
$client = static::getApiClient();
$unit = [
'name' => 'Test',
'sym' => 'tst'
];
$client->request->unitsEdit($unit);
}
/**
* @return array
*/
@ -155,7 +189,8 @@ class ApiClientReferenceTest extends TestCase
['sites'],
['stores'],
['couriers'],
['costs']
['costs'],
['units']
];
}