2022-01-10 11:58:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Test\TestCase\Api\Users;
|
|
|
|
|
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
use App\Test\Fixture\AuthKeysFixture;
|
2023-04-07 14:08:27 +02:00
|
|
|
use App\Test\Fixture\IndividualsFixture;
|
2022-01-10 11:58:52 +01:00
|
|
|
use App\Test\Fixture\OrganisationsFixture;
|
|
|
|
use App\Test\Fixture\RolesFixture;
|
|
|
|
use App\Test\Helper\ApiTestTrait;
|
|
|
|
|
|
|
|
class AddUserApiTest extends TestCase
|
|
|
|
{
|
|
|
|
use ApiTestTrait;
|
|
|
|
|
2022-01-19 16:22:44 +01:00
|
|
|
protected const ENDPOINT = '/users/add';
|
2022-01-10 11:58:52 +01:00
|
|
|
|
|
|
|
protected $fixtures = [
|
2022-01-10 16:19:58 +01:00
|
|
|
'app.Organisations',
|
2022-01-10 11:58:52 +01:00
|
|
|
'app.Individuals',
|
|
|
|
'app.Roles',
|
|
|
|
'app.Users',
|
|
|
|
'app.AuthKeys'
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testAddUser(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
2023-04-07 14:08:27 +02:00
|
|
|
'individual_id' => IndividualsFixture::INDIVIDUAL_B_ID,
|
2022-01-10 11:58:52 +01:00
|
|
|
'organisation_id' => OrganisationsFixture::ORGANISATION_A_ID,
|
|
|
|
'role_id' => RolesFixture::ROLE_REGULAR_USER_ID,
|
|
|
|
'disabled' => false,
|
2023-04-07 14:08:27 +02:00
|
|
|
'username' => 'test123',
|
2022-01-10 11:58:52 +01:00
|
|
|
'password' => 'Password123456!',
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2023-04-07 14:08:27 +02:00
|
|
|
print_r($this->getJsonResponseAsArray());
|
|
|
|
|
2022-01-10 11:58:52 +01:00
|
|
|
$this->assertResponseOk();
|
2023-04-07 14:08:27 +02:00
|
|
|
$this->assertResponseContains('"username": "test123"');
|
|
|
|
$this->assertDbRecordExists('Users', ['username' => 'test123']);
|
2022-01-10 11:58:52 +01:00
|
|
|
}
|
|
|
|
|
2022-01-11 17:17:04 +01:00
|
|
|
public function testAddUserNotAllowedAsRegularUser(): void
|
2022-01-10 11:58:52 +01:00
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
|
|
|
$this->post(
|
|
|
|
self::ENDPOINT,
|
|
|
|
[
|
2023-04-07 14:08:27 +02:00
|
|
|
'individual_id' => IndividualsFixture::INDIVIDUAL_B_ID,
|
2022-01-10 11:58:52 +01:00
|
|
|
'organisation_id' => OrganisationsFixture::ORGANISATION_A_ID,
|
|
|
|
'role_id' => RolesFixture::ROLE_REGULAR_USER_ID,
|
|
|
|
'disabled' => false,
|
|
|
|
'username' => 'test',
|
|
|
|
'password' => 'Password123456!'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseCode(405);
|
2023-04-07 14:08:27 +02:00
|
|
|
$this->assertDbRecordNotExists('Users', ['username' => 'test123']);
|
2022-01-10 11:58:52 +01:00
|
|
|
}
|
|
|
|
}
|