chg: clean test

pull/86/head
Luciano Righetti 2022-01-24 11:43:40 +01:00
parent e9e9c7f43e
commit 6479fd6183
1 changed files with 20 additions and 12 deletions

View File

@ -7,6 +7,7 @@ namespace App\Test\TestCase\Api\Users;
use Cake\TestSuite\TestCase;
use App\Test\Fixture\AuthKeysFixture;
use App\Test\Helper\ApiTestTrait;
use Authentication\PasswordHasher\DefaultPasswordHasher;
class CreateInboxEntryApiTest extends TestCase
{
@ -31,24 +32,31 @@ class CreateInboxEntryApiTest extends TestCase
$_SERVER['REMOTE_ADDR'] = '::1';
$url = sprintf("%s/%s/%s", self::ENDPOINT, 'User', 'Registration');
$password = 'Password12345!';
$email = 'john@example.com';
$this->post(
$url,
[
'email' => 'john@example.com',
'password' => 'Password12345!'
'email' => $email,
'password' => $password
]
);
$this->assertResponseOk();
$response = $this->getJsonResponseAsArray();
$userId = $response['data']['id'];
$createdInboxMessage = $this->getRecordFromDb(
'Inbox',
[
'id' => $userId,
'scope' => 'User',
'action' => 'Registration'
]
);
$this->assertResponseOk();
$this->assertResponseContains('"email": "john@example.com"');
$this->assertDbRecordExists(
'Inbox',
[
'id' => 3, // hacky, but `data` is json string cannot verify the value because of the hashed password
'scope' => 'User',
'action' => 'Registration',
]
);
$this->assertTrue((new DefaultPasswordHasher())->check($password, $createdInboxMessage['data']['password']));
$this->assertEquals($email, $createdInboxMessage['data']['email']);
}
public function testAddUserRegistrationInboxNotAllowedAsRegularUser(): void