-
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 Fingerprint module with tests
- Loading branch information
Showing
6 changed files
with
126 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,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); | ||
} | ||
} |
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,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'); | ||
}); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/responses/fingerprint/postAttendanceImportFingerprint/200.json
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": "Success processed import attendance", | ||
"data": { | ||
"status": 200 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ngerprint/postAttendanceImportFingerprint/400_automatic_import_attendance_not_exists.json
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": "input validation error", | ||
"errors": [ | ||
"automatic import attendance setting not exists" | ||
] | ||
} |