2022-01-13 16:34:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-01-27 09:30:00 +01:00
|
|
|
namespace App\Test\TestCase\Api\Inbox;
|
2022-01-13 16:34:43 +01:00
|
|
|
|
|
|
|
use Cake\TestSuite\TestCase;
|
|
|
|
use App\Test\Fixture\AuthKeysFixture;
|
|
|
|
use App\Test\Helper\ApiTestTrait;
|
2022-01-24 11:43:40 +01:00
|
|
|
use Authentication\PasswordHasher\DefaultPasswordHasher;
|
2022-01-13 16:34:43 +01:00
|
|
|
|
|
|
|
class CreateInboxEntryApiTest extends TestCase
|
|
|
|
{
|
|
|
|
use ApiTestTrait;
|
|
|
|
|
2022-01-19 16:22:44 +01:00
|
|
|
protected const ENDPOINT = '/inbox/createEntry';
|
2022-01-13 16:34:43 +01:00
|
|
|
|
|
|
|
protected $fixtures = [
|
|
|
|
'app.Inbox',
|
|
|
|
'app.Organisations',
|
|
|
|
'app.Individuals',
|
|
|
|
'app.Roles',
|
|
|
|
'app.Users',
|
|
|
|
'app.AuthKeys'
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testAddUserRegistrationInbox(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::ADMIN_API_KEY);
|
|
|
|
|
|
|
|
// to avoid $this->request->clientIp() to return null
|
|
|
|
$_SERVER['REMOTE_ADDR'] = '::1';
|
|
|
|
|
|
|
|
$url = sprintf("%s/%s/%s", self::ENDPOINT, 'User', 'Registration');
|
2022-01-24 11:43:40 +01:00
|
|
|
$password = 'Password12345!';
|
|
|
|
$email = 'john@example.com';
|
2022-01-13 16:34:43 +01:00
|
|
|
$this->post(
|
|
|
|
$url,
|
|
|
|
[
|
2022-01-24 11:43:40 +01:00
|
|
|
'email' => $email,
|
|
|
|
'password' => $password
|
2022-01-13 16:34:43 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->assertResponseOk();
|
2022-01-24 11:43:40 +01:00
|
|
|
|
|
|
|
$response = $this->getJsonResponseAsArray();
|
|
|
|
$userId = $response['data']['id'];
|
|
|
|
|
|
|
|
$createdInboxMessage = $this->getRecordFromDb(
|
2022-01-13 16:34:43 +01:00
|
|
|
'Inbox',
|
|
|
|
[
|
2022-01-24 11:43:40 +01:00
|
|
|
'id' => $userId,
|
2022-01-13 16:34:43 +01:00
|
|
|
'scope' => 'User',
|
2022-01-24 11:43:40 +01:00
|
|
|
'action' => 'Registration'
|
2022-01-13 16:34:43 +01:00
|
|
|
]
|
|
|
|
);
|
2022-01-24 11:43:40 +01:00
|
|
|
|
|
|
|
$this->assertTrue((new DefaultPasswordHasher())->check($password, $createdInboxMessage['data']['password']));
|
|
|
|
$this->assertEquals($email, $createdInboxMessage['data']['email']);
|
2022-01-13 16:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddUserRegistrationInboxNotAllowedAsRegularUser(): void
|
|
|
|
{
|
|
|
|
$this->setAuthToken(AuthKeysFixture::REGULAR_USER_API_KEY);
|
|
|
|
|
|
|
|
$url = sprintf("%s/%s/%s", self::ENDPOINT, 'User', 'Registration');
|
|
|
|
$this->post(
|
|
|
|
$url,
|
|
|
|
[
|
|
|
|
'email' => 'john@example.com',
|
|
|
|
'password' => 'Password12345!'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResponseCode(405);
|
|
|
|
$this->assertDbRecordNotExists('Inbox', ['id' => 3]);
|
|
|
|
}
|
|
|
|
}
|