add: api tests for access logs

pull/9434/head
Luciano Righetti 2023-12-06 11:06:24 +01:00
parent 51e404bb85
commit 656a3293d0
3 changed files with 37 additions and 2 deletions

View File

@ -19,7 +19,7 @@ class AccessLogsFixture extends TestFixture
$this->records = [
[
'id' => self::ACCESS_LOG_1_ID,
'created' => '#000000',
'created' => $faker->dateTime()->getTimestamp(),
'user_id' => UsersFixture::USER_ADMIN_ID,
'org_id' => OrganisationsFixture::ORGANISATION_A_ID,
'request_method' => 0,

View File

@ -253,7 +253,6 @@ trait ApiTestTrait
$_SERVER['CONTENT_TYPE'] = $this->_request['headers']['Content-Type'];
$_SERVER['HTTP_CONTENT_ENCODING'] = $this->_request['headers']['Content-Type'];
$this->_sendRequestOriginal($url, $method, $data);
// Validate response against OpenAPI spec

View File

@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Api\AccessLogs;
use Cake\TestSuite\TestCase;
use App\Test\Fixture\AuthKeysFixture;
use App\Test\Fixture\AccessLogsFixture;
use App\Test\Helper\ApiTestTrait;
class IndexAccessLogsApiTest extends TestCase
{
use ApiTestTrait;
protected const ENDPOINT = '/admin/accessLogs/index';
protected $fixtures = [
'app.Organisations',
'app.Users',
'app.AuthKeys',
'app.AccessLogs',
];
public function testIndexAccessLogs(): void
{
$this->skipOpenApiValidations();
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
$this->get(self::ENDPOINT);
$this->assertResponseOk();
$this->assertResponseContains(sprintf('"id": %d', AccessLogsFixture::ACCESS_LOG_1_ID));
}
}