- ajout une colonne new country pour enum - fix des test v2 - fix du handler - fix des middleware - fix du timestamp checker - fix des stats fix du api handler - ajout du middleware json only - remove crm-id du client en faveur du hashcode seulement - fix du route service provider - déplacement de la route arcradia en dehors du customer
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\ApiV2;
|
|
|
|
use App\Enums\ApiError;
|
|
use App\Enums\ApiStatus;
|
|
use App\Models\Service;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Tests\CreatesApplication;
|
|
|
|
class ApiTest extends ApiBase
|
|
{
|
|
use CreatesApplication;
|
|
use DatabaseTransactions;
|
|
|
|
public function testTimestampMiddleware()
|
|
{
|
|
$response = $this->callApi('get', route('apiV2.ping'));
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
|
|
$response = $this->json('get', route('apiV2.ping'), ['timestamp' => time()], [
|
|
'X-API-TIMESTAMP' => time() + 119
|
|
]);
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
|
|
$response = $this->json('get', route('apiV2.ping'), ['timestamp' => time()], [
|
|
'X-API-TIMESTAMP' => time() + 121
|
|
]);
|
|
$json = $response->decodeResponseJson();
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::KO());
|
|
$json->assertFragment(['data' => [
|
|
'code' => ApiError::wrongTimeStamp()->value,
|
|
'message' => ApiError::wrongTimeStamp()->label
|
|
]]);
|
|
}
|
|
|
|
/**
|
|
* route: apiV2.authenticate
|
|
*/
|
|
public function testApiAuthenticate()
|
|
{
|
|
extract($this->getCustomer());
|
|
$response = $this->callApi(
|
|
'post',
|
|
route('apiV2.authenticate'),
|
|
['bearer_pwd' => $service->bearer_pwd],
|
|
['Authorization' => sprintf('Bearer %s', $service->bearer_token)]
|
|
);
|
|
|
|
$json = $response->decodeResponseJson();
|
|
|
|
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
|
|
$this->assertNotEmpty($json->json('data'));
|
|
$this->assertNotEmpty($json->json('data.api_token'));
|
|
$this->assertEquals(Service::findOrFail($service->id)->api_token, $json->json('data.api_token'));
|
|
}
|
|
}
|