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

Units methods

This commit is contained in:
Alex Lushpai 2020-07-03 18:00:26 +03:00 committed by GitHub
commit 963eb19bfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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']
];
}