Skip to content

Commit

Permalink
- Finish api for Fingerprint module with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianriizky committed May 8, 2022
1 parent 9c153d4 commit 4370ff5
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Services/Api/Fingerprint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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#630f960f-aeee-43d6-876d-765f41ab6a52
*/
trait Fingerprint
{
/**
* Create "/attendance/import-fingerprint" POST request to the Talenta api.
*
* Submit Attendance Import Fingerprint.
*
* @param array $data
* @param array<string|resource> $files
* @return \Illuminate\Http\Client\Response
*
* @see https://documenter.getpostman.com/view/12246328/TWDZHvj1#6493f000-0157-42a5-af73-eb40cf9bb4cd
*/
protected function postAttendanceImportFingerprint(array $data = [], array $files): Response
{
return $this->request
->attach($files)
->post('/attendance/import-fingerprint', $data);
}
}
5 changes: 5 additions & 0 deletions src/Services/TalentaApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
* @method \Illuminate\Http\Client\Response getEmployeeInformalEducation(string $user_id, array $data = []) Create "/employee/informal-education/:user_id/list" GET request to the Talenta api.
* @method \Illuminate\Http\Client\Response getEmployeeInformalEducationDetail(string $user_id, string $informal_education_id, array $data = []) Create "/employee/informal-education/:user_id/detail/:informal_education_id" GET request to the Talenta api.
*
* @see \Ianriizky\TalentaApi\Services\Api\Fingerprint
*
* @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\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 @@ -59,6 +63,7 @@ class TalentaApi
use Api\Company;
use Api\Employee;
use Api\CostCenter;
use Api\Fingerprint;
use Api\Report;
use Concerns\HandleAuthentication;
use Concerns\HandleHTTPClient;
Expand Down
4 changes: 4 additions & 0 deletions src/Support/Facades/TalentaApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
* @method static \Illuminate\Http\Client\Response getEmployeeInformalEducation(string $user_id, array $data = []) Create "/employee/informal-education/:user_id/list" GET request to the Talenta api.
* @method static \Illuminate\Http\Client\Response getEmployeeInformalEducationDetail(string $user_id, string $informal_education_id, array $data = []) Create "/employee/informal-education/:user_id/detail/:informal_education_id" GET request to the Talenta api.
*
* @see \Ianriizky\TalentaApi\Services\Api\Fingerprint
*
* @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\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
74 changes: 74 additions & 0 deletions tests/Api/FingerprintTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Ianriizky\TalentaApi\Tests\Api;

use Ianriizky\TalentaApi\Support\Facades\TalentaApi;
use Ianriizky\TalentaApi\Tests\ApiTestCase;
use Illuminate\Http\Client\Request;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\Client\Response;
use Illuminate\Http\Response as HttpResponse;
use Illuminate\Http\UploadedFile;

/**
* @see \Ianriizky\TalentaApi\Services\Api\Fingerprint
*/
class FingerprintTest extends ApiTestCase
{
public function test_postAttendanceImportFingerprint_response_200()
{
$jsonPath = 'fingerprint/postAttendanceImportFingerprint/200.json';

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

tap(TalentaApi::postAttendanceImportFingerprint([
'user_id' => '571919',
'token' => '9b12964f1f03e7b0de26be6a68dcdd56',
], [
[
'name' => 'fingerprint',
'contents' => UploadedFile::fake()->create('fingerprint.csv'),
],
]), function ($response) use ($jsonPath) {
$this->assertInstanceOf(Response::class, $response);

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

$this->factory->assertSentCount(1);
$this->factory->assertSent(function (Request $request) {
return $request->hasFile('fingerprint');
});
}

public function test_postAttendanceImportFingerprint_response_400_automatic_import_attendance_not_exists()
{
$jsonPath = 'fingerprint/postAttendanceImportFingerprint/400_automatic_import_attendance_not_exists.json';

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

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

try {
TalentaApi::postAttendanceImportFingerprint([
'user_id' => '571919',
'token' => '9b12964f1f03e7b0de26be6a68dcdd56',
], [
[
'name' => 'fingerprint',
'contents' => UploadedFile::fake()->create('fingerprint.csv'),
],
]);
} catch (RequestException $th) {
$th->response->assertSameWithJsonPath($jsonPath);

throw $th;
}

$this->factory->assertSentCount(1);
$this->factory->assertSent(function (Request $request) {
return $request->hasFile('fingerprint');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"message": "Success processed import attendance",
"data": {
"status": 200
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"message": "input validation error",
"errors": [
"automatic import attendance setting not exists"
]
}

0 comments on commit 4370ff5

Please sign in to comment.