Skip to content

Commit

Permalink
- Finish api for PayrollPaymentSchedule module with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianriizky committed May 19, 2022
1 parent f65995f commit 3496d8b
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Services/Api/PayrollPaymentSchedule.php
@@ -0,0 +1,48 @@
<?php

namespace Ianriizky\TalentaApi\Services\Api;

use Illuminate\Http\Client\Response;

/**
* @property \Illuminate\Http\Client\PendingRequest $request
*
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#561cc8c8-403f-46c7-b12f-6f3e3922a47c
*/
trait PayrollPaymentSchedule
{
/**
* Create "/company/me/payroll-payment-schedule" GET request to the Talenta api.
*
* Get company payroll payment schedule. This endpoint will allow user to:
* - get company payroll payment schedule master data
* - get company payroll payment schedule transaction data with additonal year, month, status parameters
*
* @param array|string|null $query
* @return \Illuminate\Http\Client\Response
*
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#52ffb3a7-5ea9-401f-a3db-a488e6546eb4
*/
protected function getCompanyPayrollPaymentSchedule($query = null): Response
{
return $this->request->get('/company/me/payroll-payment-schedule', $query);
}

/**
* Create "/payroll-payment-schedule/:company_id/history" GET request to the Talenta api.
*
* Get company payroll payment schedule. This endpoint will allow user to
* - get company payroll payment schedule master data
* - get company payroll payment schedule transaction data with additonal year, month, status parameters
*
* @param string $company_id
* @param array|string|null $query
* @return \Illuminate\Http\Client\Response
*
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#0835590c-7454-4377-9419-7dacdd2073ef
*/
protected function getPayrollPaymentScheduleHistory(string $company_id, $query = null): Response
{
return $this->request->get('/payroll-payment-schedule/'.$company_id.'/history', $query);
}
}
6 changes: 6 additions & 0 deletions src/Services/TalentaApi.php
Expand Up @@ -49,6 +49,11 @@
*
* @method \Illuminate\Http\Client\Response postAttendanceImportFingerprint(array $data = [], array<string|resource> $files) Create "/attendance/import-fingerprint" POST request to the Talenta api.
*
* @see \Ianriizky\TalentaApi\Services\Api\PayrollPaymentSchedule
*
* @method \Illuminate\Http\Client\Response getCompanyPayrollPaymentSchedule(array|string|null $query = null) Create "/company/me/payroll-payment-schedule" GET request to the Talenta api.
* @method \Illuminate\Http\Client\Response getPayrollPaymentScheduleHistory(string $company_id, array|string|null $query = null) Create "/payroll-payment-schedule/:company_id/history" GET request to the Talenta api.
*
* @see \Ianriizky\TalentaApi\Services\Api\Report
*
* @method \Illuminate\Http\Client\Response getTurnoverReport(string $user_id, array|string|null $query = null) Create "/report/:user_id/turnover" GET request to the Talenta api.
Expand All @@ -65,6 +70,7 @@ class TalentaApi
use Api\Employee;
use Api\CostCenter;
use Api\Fingerprint;
use Api\PayrollPaymentSchedule;
use Api\Report;
use Concerns\HandleAuthentication;
use Concerns\HandleHTTPClient;
Expand Down
5 changes: 5 additions & 0 deletions src/Support/Facades/TalentaApi.php
Expand Up @@ -51,6 +51,11 @@
*
* @method static \Illuminate\Http\Client\Response postAttendanceImportFingerprint(array $data = [], array<string|resource> $files) Create "/attendance/import-fingerprint" POST request to the Talenta api.
*
* @see \Ianriizky\TalentaApi\Services\Api\PayrollPaymentSchedule
*
* @method static \Illuminate\Http\Client\Response getCompanyPayrollPaymentSchedule(array|string|null $query = null) Create "/company/me/payroll-payment-schedule" GET request to the Talenta api.
* @method static \Illuminate\Http\Client\Response getPayrollPaymentScheduleHistory(string $company_id, array|string|null $query = null) Create "/payroll-payment-schedule/:company_id/history" GET request to the Talenta api.
*
* @see \Ianriizky\TalentaApi\Services\Api\Report
*
* @method static \Illuminate\Http\Client\Response getTurnoverReport(string $user_id, array|string|null $query = null) Create "/report/:user_id/turnover" GET request to the Talenta api.
Expand Down
201 changes: 201 additions & 0 deletions tests/Api/PayrollPaymentScheduleTest.php
@@ -0,0 +1,201 @@
<?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\PayrollPaymentSchedule
*/
class PayrollPaymentScheduleTest extends ApiTestCase
{
public function test_getCompanyPayrollPaymentSchedule_response_200_master_data_payroll_payment_schedule()
{
$jsonPath = 'payroll_payment_schedule/getCompanyPayrollPaymentSchedule/200_master_data_payroll_payment_schedule.json';

$this->factory->fakeUsingJsonPath($jsonPath);

tap(TalentaApi::getCompanyPayrollPaymentSchedule([
// 'limit' => 'x',
// 'page' => '1x',
'user_id' => '8002',
// 'year' => '2021',
// 'month' => 'x',
// 'status' => 'pending',
]), function ($response) use ($jsonPath) {
$this->assertInstanceOf(Response::class, $response);

$response->assertSameWithJsonPath($jsonPath);
});

$this->factory->assertSentCount(1);
}

public function test_getCompanyPayrollPaymentSchedule_response_200_payroll_payment_schedule_transaction()
{
$jsonPath = 'payroll_payment_schedule/getCompanyPayrollPaymentSchedule/200_payroll_payment_schedule_transaction.json';

$this->factory->fakeUsingJsonPath($jsonPath);

tap(TalentaApi::getCompanyPayrollPaymentSchedule([
// 'limit' => 'x',
// 'page' => '1x',
'user_id' => '8002',
'year' => '2021',
// 'month' => 'x',
// 'status' => '',
]), function ($response) use ($jsonPath) {
$this->assertInstanceOf(Response::class, $response);

$response->assertSameWithJsonPath($jsonPath);
});

$this->factory->assertSentCount(1);
}

public function test_getCompanyPayrollPaymentSchedule_response_200_empty_response()
{
$jsonPath = 'payroll_payment_schedule/getCompanyPayrollPaymentSchedule/200_empty_response.json';

$this->factory->fakeUsingJsonPath($jsonPath);

tap(TalentaApi::getCompanyPayrollPaymentSchedule([
// 'limit' => 'x',
// 'page' => '1x',
'user_id' => '935848',
// 'year' => 'x',
// 'month' => 'x',
]), function ($response) use ($jsonPath) {
$this->assertInstanceOf(Response::class, $response);

$response->assertSameWithJsonPath($jsonPath);
});

$this->factory->assertSentCount(1);
}

public function test_getCompanyPayrollPaymentSchedule_response_401()
{
$jsonPath = 'payroll_payment_schedule/getCompanyPayrollPaymentSchedule/401.json';

$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_UNAUTHORIZED);

$this->expectException(RequestException::class);
$this->expectExceptionCode(HttpResponse::HTTP_UNAUTHORIZED);

try {
TalentaApi::getCompanyPayrollPaymentSchedule([
// 'limit' => '3',
// 'page' => '1',
'user_id' => '935848',
// 'year' => '',
// 'month' => '',
]);
} catch (RequestException $th) {
$th->response->assertSameWithJsonPath($jsonPath);

throw $th;
}

$this->factory->assertSentCount(1);
}

public function test_getCompanyPayrollPaymentSchedule_response_400()
{
$jsonPath = 'payroll_payment_schedule/getCompanyPayrollPaymentSchedule/400.json';

$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_BAD_REQUEST);

$this->expectException(RequestException::class);
$this->expectExceptionCode(HttpResponse::HTTP_BAD_REQUEST);

try {
TalentaApi::getCompanyPayrollPaymentSchedule([
'limit' => 'x',
'page' => '1x',
'user_id' => '-8002',
'year' => '2021x',
'month' => 'x',
'status' => 'pending',
]);
} catch (RequestException $th) {
$th->response->assertSameWithJsonPath($jsonPath);

throw $th;
}

$this->factory->assertSentCount(1);
}

public function test_getPayrollPaymentScheduleHistory_response_200()
{
$jsonPath = 'payroll_payment_schedule/getPayrollPaymentScheduleHistory/200.json';

$this->factory->fakeUsingJsonPath($jsonPath);

tap(TalentaApi::getPayrollPaymentScheduleHistory('me', [
'limit' => '20',
'page' => '1',
'user_id' => '935848',
// 'month' => '4',
'year' => '2022',
]), function ($response) use ($jsonPath) {
$this->assertInstanceOf(Response::class, $response);

$response->assertSameWithJsonPath($jsonPath);
});

$this->factory->assertSentCount(1);
}

public function test_getPayrollPaymentScheduleHistory_response_200_empty_data()
{
$jsonPath = 'payroll_payment_schedule/getPayrollPaymentScheduleHistory/200_empty_data.json';

$this->factory->fakeUsingJsonPath($jsonPath);

tap(TalentaApi::getPayrollPaymentScheduleHistory('me', [
'limit' => '20',
'page' => '1',
'user_id' => '935848',
'month' => '12',
'year' => '2022',
]), function ($response) use ($jsonPath) {
$this->assertInstanceOf(Response::class, $response);

$response->assertSameWithJsonPath($jsonPath);
});

$this->factory->assertSentCount(1);
}

public function test_getPayrollPaymentScheduleHistory_response_400()
{
$jsonPath = 'payroll_payment_schedule/getPayrollPaymentScheduleHistory/400.json';

$this->factory->fakeUsingJsonPath($jsonPath, HttpResponse::HTTP_BAD_REQUEST);

$this->expectException(RequestException::class);
$this->expectExceptionCode(HttpResponse::HTTP_BAD_REQUEST);

try {
TalentaApi::getPayrollPaymentScheduleHistory('me', [
'limit' => '200',
'page' => '1x',
'user_id' => '935848',
'month' => '12x',
'year' => '2022x',
]);
} catch (RequestException $th) {
$th->response->assertSameWithJsonPath($jsonPath);

throw $th;
}

$this->factory->assertSentCount(1);
}
}
@@ -0,0 +1,7 @@
{
"message": "payroll payment schedule not found for company id 3053",
"data": {
"payroll_payment_schedule": null,
"total": 0
}
}
@@ -0,0 +1,100 @@
{
"message": "get company payroll payment schedule successfully",
"data": {
"payroll_payment_schedule": [
{
"id": 2400,
"name": "MAHECUSTOM",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-12-16 11:13:05"
},
{
"id": 2262,
"name": "RF",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-11-22 10:29:01"
},
{
"id": 2004,
"name": "WAREHOUSEWEEKLY",
"payment_schedule_date": "",
"type": "weekly",
"status": -1,
"created_date": "2021-09-13 17:30:22"
},
{
"id": 1782,
"name": "NADIA",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-07-29 15:15:37"
},
{
"id": 1702,
"name": "ASASSA",
"payment_schedule_date": "",
"type": "weekly",
"status": -1,
"created_date": "2021-07-09 12:18:42"
},
{
"id": 1701,
"name": "TEST",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-07-09 12:15:30"
},
{
"id": 1496,
"name": "ALLOWANCE",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-05-11 16:31:38"
},
{
"id": 1291,
"name": "GAJIB",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-03-09 18:22:49"
},
{
"id": 1290,
"name": "GAJIA",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-03-09 18:22:24"
},
{
"id": 1281,
"name": "TES1",
"payment_schedule_date": "",
"type": "monthly",
"status": -1,
"created_date": "2021-03-05 10:25:19"
}
],
"total": 27,
"pagination": {
"current_page": 1,
"first_page_url": "/v2/payroll-payment-schedule/679?user_id=8002&page=1&per-page=10",
"from": 1,
"last_page": 3,
"last_page_url": "/v2/payroll-payment-schedule/679?user_id=8002&page=3&per-page=10",
"next_page_url": "/v2/payroll-payment-schedule/679?user_id=8002&page=2&per-page=10",
"path": "/v2/payroll-payment-schedule/679",
"per_page": 10,
"to": 10,
"total": 27
}
}
}

0 comments on commit 3496d8b

Please sign in to comment.