Skip to content

Commit

Permalink
Refactoring recently added files..
Browse files Browse the repository at this point in the history
  • Loading branch information
plvhx committed Dec 14, 2020
1 parent 7a34533 commit 8abf32f
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
56 changes: 55 additions & 1 deletion src/Service/Logistic.php
Expand Up @@ -17,7 +17,7 @@ class Logistic extends Resource
*/
public function getShipmentInfo(int $shopID)
{
$endpoint = sprintf(
$endpoint = sprintf(
'/v2/logistic/fs/%s/info',
$this->getFulfillmentServiceID()
);
Expand All @@ -33,6 +33,60 @@ public function getShipmentInfo(int $shopID)
return $this->getContents($response);
}

/**
* @param int $shopID
* @param int $firstOrderID
* @param int $nextOrderID
* @param int $orderID
* @param int $perPage
* @return string
*/
public function getJOBAndCOD(
int $shopID = 0,
int $firstOrderID = 0,
int $nextOrderID = 0,
int $orderID = 0,
int $perPage = 0
) {
$endpoint = sprintf(
'/v1/fs/%s/fulfillment_order',
$this->getFulfillmentServiceID()
);

$queryParams = [];

if ($shopID > 0) {
$queryParams['shop_id'] = $shopID;
}

if ($firstOrderID > 0) {
$queryParams['first_order_id'] = $firstOrderID;
}

if ($nextOrderID > 0) {
$queryParams['next_order_id'] = $nextOrderID;
}

if ($orderID > 0) {
$queryParams['order_id'] = $orderID;
}

if ($perPage > 0) {
$queryParams['per_page'] = $perPage;
}

$response = $this->call(
'GET',
sprintf(
"%s%s",
$endpoint,
!sizeof($queryParams) ? '' : '?' . http_build_query($queryParams)
)
);

return $this->getContents($response);
}

/**
* Update shipment info.
*
Expand Down
46 changes: 46 additions & 0 deletions tests/Service/LogisticTest.php
Expand Up @@ -66,6 +66,52 @@ public function testGetShipmentInfoWithFailedResponse()
$this->assertEquals($deserialized, $response);
}

public function testCanGetJOBAndCODWithSuccessResponse()
{
$logistic = new Logistic($this->getAuthorization());
$mockHandler = new MockHandler();
$httpClient = new Client(['handler' => $mockHandler]);
$contents = file_get_contents(
__DIR__ . '/../data-fixtures/logistic/get-job-and-cod-ok.json'
);

$mockHandler->append(new Response(
200,
['Content-Type' => 'application/json'],
$contents
));

$logistic->setHttpClient($httpClient);

$deserialized = json_decode($contents, true);
$response = json_decode($logistic->getJOBAndCOD(1, 1, 1, 1, 1), true);

$this->assertEquals($deserialized, $response);
}

public function testCanGetJOBAndCODWithFailedResponse()
{
$logistic = new Logistic($this->getAuthorization());
$mockHandler = new MockHandler();
$httpClient = new Client(['handler' => $mockHandler]);
$contents = file_get_contents(
__DIR__ . '/../data-fixtures/logistic/get-job-and-cod-fail.json'
);

$mockHandler->append(new Response(
400,
['Content-Type' => 'application/json'],
$contents
));

$logistic->setHttpClient($httpClient);

$deserialized = json_decode($contents, true);
$response = json_decode($logistic->getJOBAndCOD(1, 1, 1, 1, 1), true);

$this->assertEquals($deserialized, $response);
}

public function testCanUpdateShipmentInfoWithSuccessResponse()
{
$logistic = new Logistic($this->getAuthorization());
Expand Down
1 change: 1 addition & 0 deletions tests/data-fixtures/logistic/get-job-and-cod-fail.json
@@ -0,0 +1 @@
{"data":null,"status":"Contain error code of response","error_message":["Contain error messages of response"]}
1 change: 1 addition & 0 deletions tests/data-fixtures/logistic/get-job-and-cod-ok.json
@@ -0,0 +1 @@
{"header":{"process_time":"35.50ms","messages":null,"reason":"","error_code":""},"data":{"order_data":[{"order":{"order_id":342026997,"buyer_id":64565282,"seller_id":2926870,"payment_id":444594306,"order_status":700,"invoice_number":"INV/20190718/XIX/VII/341976843","invoice_pdf_link":"pdf/2019/07/18","open_amt":200000,"payment_amt_cod":195000},"order_history":[{"order_hist_id":2883479110,"status":700,"shipping_date":null,"create_by":0},{"order_hist_id":2883478788,"status":690,"shipping_date":null,"create_by":0}],"order_detail":[{"order_detail_id":540585010,"product_id":375822451,"product_name":"","quantity":1,"product_price":184000,"insurance_price":0}],"drop_shipper":{"order_id":0,"dropship_name":"","dropship_telp":""},"type_meta":{"kelontong":{},"cod":{},"sampai":{},"now":{},"ppp":{},"trade_in":{},"vehicle_leasing":{}},"order_shipment_fulfillment":{"id":121101022,"order_id":342026997,"payment_date_time":"2019-07-18T14:58:01.998063Z","is_same_day":false,"accept_deadline":"2019-07-19T14:58:01.998063Z","confirm_shipping_deadline":"2019-07-22T14:58:01.998063Z","item_delivered_deadline":{"Time":"0001-01-01T00:00:00Z","Valid":false},"is_accepted":false,"is_confirm_shipping":false,"is_item_delivered":false,"fulfillment_status":0},"booking_data":{"order_id":342026997,"booking_code":"000213552920","booking_status":200}}],"next_order_id":342026997,"first_order_id":342026997},"status":"200"}

0 comments on commit 8abf32f

Please sign in to comment.