ldc-crm/tests/Feature/ApiV2/ApiTest.php
Jérémy Munsch 6987501a98 CRM API V2
2021-03-27 08:29:31 +01:00

53 lines
1.7 KiB
PHP

<?php
namespace Tests\Feature\ApiV2;
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());
}
/**
* route: apiV2.authenticate
*/
public function testApiAuthenticate()
{
extract($this->getCustomer());
$response = $this->callApi(
'post',
route('apiV2.authenticate'),
[],
['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'));
}
}