-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Finish api for CostCenter module with tests
- Loading branch information
Showing
11 changed files
with
1,056 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Ianriizky\TalentaApi\Services\Api; | ||
|
||
use Illuminate\Http\Client\Response; | ||
|
||
/** | ||
* @property \Ianriizky\TalentaApi\Http\Client\PendingRequest $request | ||
* | ||
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#ab263267-7251-41a7-aa23-53fc61d58370 | ||
*/ | ||
trait CostCenter | ||
{ | ||
/** | ||
* Create "/cost-center" GET request to the Talenta api. | ||
* | ||
* Get Cost Center report. | ||
* | ||
* @param array|string|null $query | ||
* @return \Illuminate\Http\Client\Response | ||
* | ||
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#f88530c7-082d-4c96-a3b4-2192525cc390 | ||
*/ | ||
protected function getCostCenterReport($query = null): Response | ||
{ | ||
return $this->request->get('/cost-center', $query); | ||
} | ||
|
||
/** | ||
* Create "/company/:cost_center_id/cost-center" GET request to the Talenta api. | ||
* | ||
* Get company cost center. | ||
* | ||
* @param string $cost_center_id | ||
* @param array|string|null $query | ||
* @return \Illuminate\Http\Client\Response | ||
* | ||
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#600b64a7-d39e-42af-9457-65dbd90fc93d | ||
*/ | ||
protected function getCompanyCostCenter(string $cost_center_id, $query = null): Response | ||
{ | ||
return $this->request->get('/company/'.$cost_center_id.'/cost-center', $query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?php | ||
|
||
namespace Ianriizky\TalentaApi\Tests\Api; | ||
|
||
use Ianriizky\TalentaApi\Support\Facades\TalentaApi; | ||
use Ianriizky\TalentaApi\Tests\ApiTestCase; | ||
use Illuminate\Http\Client\RequestException; | ||
use Illuminate\Http\Client\Response; | ||
use Illuminate\Http\Response as HttpResponse; | ||
|
||
/** | ||
* @see \Ianriizky\TalentaApi\Services\Api\Employee | ||
*/ | ||
class CostCenterTest extends ApiTestCase | ||
{ | ||
public function test_getCostCenterReport_response_200() | ||
{ | ||
$jsonPath = 'cost_center/getCostCenterReport/200.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath); | ||
|
||
tap(TalentaApi::getCostCenterReport([ | ||
'user_id' => '571919', | ||
'year' => '2021', | ||
'month' => '8', | ||
]), function ($response) use ($jsonPath) { | ||
$this->assertInstanceOf(Response::class, $response); | ||
|
||
$response->assertSameWithJsonPath($jsonPath); | ||
}); | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
|
||
public function test_getCostCenterReport_response_200_with_filter() | ||
{ | ||
$jsonPath = 'cost_center/getCostCenterReport/200_with_filter.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath); | ||
|
||
tap(TalentaApi::getCostCenterReport([ | ||
'user_id' => '571919', | ||
'year' => '2021', | ||
'month' => '8', | ||
'payment_schedule_id' => '2475', | ||
'cost_center_id' => '71', | ||
// 'week' => '', | ||
]), function ($response) use ($jsonPath) { | ||
$this->assertInstanceOf(Response::class, $response); | ||
|
||
$response->assertSameWithJsonPath($jsonPath); | ||
}); | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
|
||
public function test_getCostCenterReport_response_400_error_validation_month_required() | ||
{ | ||
$jsonPath = 'cost_center/getCostCenterReport/400_error_validation_month_required.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_BAD_REQUEST); | ||
|
||
$this->expectException(RequestException::class); | ||
$this->expectExceptionCode(HttpResponse::HTTP_BAD_REQUEST); | ||
|
||
try { | ||
TalentaApi::getCostCenterReport([ | ||
'user_id' => '571919', | ||
'year' => '2021', | ||
]); | ||
} catch (RequestException $th) { | ||
$th->response->assertSameWithJsonPath($jsonPath); | ||
|
||
throw $th; | ||
} | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
|
||
public function test_getCostCenterReport_response_400_error_company_sap_integration() | ||
{ | ||
$jsonPath = 'cost_center/getCostCenterReport/400_error_company_sap_integration.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_BAD_REQUEST); | ||
|
||
$this->expectException(RequestException::class); | ||
$this->expectExceptionCode(HttpResponse::HTTP_BAD_REQUEST); | ||
|
||
try { | ||
TalentaApi::getCostCenterReport([ | ||
'user_id' => '571919', | ||
'year' => '2021', | ||
]); | ||
} catch (RequestException $th) { | ||
$th->response->assertSameWithJsonPath($jsonPath); | ||
|
||
throw $th; | ||
} | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
|
||
public function test_getCompanyCostCenter_response_200() | ||
{ | ||
$jsonPath = 'cost_center/getCompanyCostCenter/200.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath); | ||
|
||
tap(TalentaApi::getCompanyCostCenter('3053', [ | ||
'limit' => '10', | ||
'page' => '1', | ||
'user_id' => '988152', | ||
]), function ($response) use ($jsonPath) { | ||
$this->assertInstanceOf(Response::class, $response); | ||
|
||
$response->assertSameWithJsonPath($jsonPath); | ||
}); | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
|
||
public function test_getCompanyCostCenter_response_400() | ||
{ | ||
$jsonPath = 'cost_center/getCompanyCostCenter/400.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_BAD_REQUEST); | ||
|
||
$this->expectException(RequestException::class); | ||
$this->expectExceptionCode(HttpResponse::HTTP_BAD_REQUEST); | ||
|
||
try { | ||
TalentaApi::getCompanyCostCenter('3053', [ | ||
'limit' => '1000', | ||
'page' => '1', | ||
'user_id' => '988152x', | ||
]); | ||
} catch (RequestException $th) { | ||
$th->response->assertSameWithJsonPath($jsonPath); | ||
|
||
throw $th; | ||
} | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
|
||
public function test_getCompanyCostCenter_response_401() | ||
{ | ||
$jsonPath = 'cost_center/getCompanyCostCenter/401.json'; | ||
|
||
$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_UNAUTHORIZED); | ||
|
||
$this->expectException(RequestException::class); | ||
$this->expectExceptionCode(HttpResponse::HTTP_UNAUTHORIZED); | ||
|
||
try { | ||
TalentaApi::getCompanyCostCenter('3053', [ | ||
'limit' => '10', | ||
'page' => '1', | ||
'user_id' => '988152', | ||
]); | ||
} catch (RequestException $th) { | ||
$th->response->assertSameWithJsonPath($jsonPath); | ||
|
||
throw $th; | ||
} | ||
|
||
$this->factory->assertSentCount(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"message": "Get company cost center successfully", | ||
"data": { | ||
"costcenter": [ | ||
{ | ||
"id": 71, | ||
"codename": "COST CENTER DONT DELETE" | ||
} | ||
], | ||
"pagination": { | ||
"current_page": 0, | ||
"first_page_url": "http://api-upstream.talentadev.comhttps://talenta-staging-core-haatori-web.talentadev.comhttps://talenta-staging-core-haatori-web.talentadev.com/public-api/v2/cost-center/list?companyId=3053&limit=10&page=1&userId=988152&per-page=10", | ||
"from": 1, | ||
"last_page": 1, | ||
"last_page_url": "http://api-upstream.talentadev.comhttps://talenta-staging-core-haatori-web.talentadev.comhttps://talenta-staging-core-haatori-web.talentadev.com/public-api/v2/cost-center/list?companyId=3053&limit=10&page=1&userId=988152&per-page=10", | ||
"next_page_url": "", | ||
"path": "http://api-upstream.talentadev.comhttps://talenta-staging-core-haatori-web.talentadev.comhttps://talenta-staging-core-haatori-web.talentadev.com/public-api/v2/cost-center/list", | ||
"per_page": 10, | ||
"prev_page_url": "", | ||
"to": 1, | ||
"total": 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"message": "input validation error", | ||
"errors": [ | ||
"user_id param should be positive integer", | ||
"limit must be an integer between 1 - 100" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"message": "Unauthorized", | ||
"errors": [ | ||
"Unauthorized user" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"message": "Get cost center success", | ||
"data": { | ||
"cost_center": [ | ||
{ | ||
"codename": "567 TDA", | ||
"payroll_component": [ | ||
{ | ||
"name": "Basic salary", | ||
"amount": 0, | ||
"gl_account": "100-Basic Salary", | ||
"gl_account_type": "Direct", | ||
"type": "Debit" | ||
}, | ||
{ | ||
"name": "Basic salary", | ||
"amount": 6000000, | ||
"gl_account": "100-Basic Salary", | ||
"gl_account_type": "In-direct", | ||
"type": "Debit" | ||
}, | ||
{ | ||
"name": "Tunjangan Makan", | ||
"amount": 0, | ||
"gl_account": "200-Tunjangan Makan", | ||
"gl_account_type": "Direct", | ||
"type": "Debit" | ||
}, | ||
{ | ||
"name": "Tunjangan Makan", | ||
"amount": 0, | ||
"gl_account": "200-Tunjangan Makan", | ||
"gl_account_type": "In-direct", | ||
"type": "Debit" | ||
}, | ||
{ | ||
"name": "Take home pay", | ||
"amount": 0, | ||
"gl_account": "600-Take home pay", | ||
"gl_account_type": "Direct", | ||
"type": "Debit" | ||
}, | ||
{ | ||
"name": "Take home pay", | ||
"amount": 800000, | ||
"gl_account": "600-Take home pay", | ||
"gl_account_type": "In-direct", | ||
"type": "Debit" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.