From 6479fd6183128c40ae6d16d6c7a7865ea0511025 Mon Sep 17 00:00:00 2001 From: Luciano Righetti Date: Mon, 24 Jan 2022 11:43:40 +0100 Subject: [PATCH] chg: clean test --- .../Api/Inbox/CreateInboxEntryApiTest.php | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php b/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php index 8434d62..a1fd077 100644 --- a/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php +++ b/tests/TestCase/Api/Inbox/CreateInboxEntryApiTest.php @@ -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