|
5 | 5 | use Contexts\Authorization\Domain\Factories\UserIdentityFactory; |
6 | 6 | use Contexts\Authorization\Domain\Role\Models\RoleId; |
7 | 7 | use Contexts\Authorization\Domain\Services\UserEmailUniquenessService; |
| 8 | +use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException; |
8 | 9 | use Contexts\Authorization\Domain\UserIdentity\Exceptions\UserNotFoundException; |
9 | 10 | use Contexts\Authorization\Domain\UserIdentity\Models\Email; |
10 | 11 | use Contexts\Authorization\Domain\UserIdentity\Models\Password; |
|
15 | 16 | use Contexts\Authorization\Infrastructure\Persistence\UserPersistence; |
16 | 17 | use Contexts\Authorization\Infrastructure\Records\RoleRecord; |
17 | 18 | use Contexts\Authorization\Infrastructure\Records\UserRecord; |
18 | | -use Illuminate\Database\Eloquent\ModelNotFoundException; |
19 | | -use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException; |
20 | 19 |
|
21 | 20 | beforeEach(function () { |
22 | 21 | $this->userLabelUniquenessService = mock(UserEmailUniquenessService::class); |
|
27 | 26 | $email = new Email('test@example.com'); |
28 | 27 | $password = Password::createFromPlainText('password123'); |
29 | 28 | $user = $this->userFactory->create(UserId::null(), $email, $password, 'My User'); |
30 | | - $userPersistence = new UserPersistence(); |
| 29 | + $userPersistence = new UserPersistence; |
31 | 30 |
|
32 | 31 | $userPersistence->create($user); |
33 | 32 |
|
|
43 | 42 | $email = new Email('retrieve@example.com'); |
44 | 43 | $password = Password::createFromPlainText('password123'); |
45 | 44 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Test User'); |
46 | | - $userPersistence = new UserPersistence(); |
| 45 | + $userPersistence = new UserPersistence; |
47 | 46 | $savedUser = $userPersistence->create($createdUser); |
48 | 47 |
|
49 | 48 | // Retrieve the user using getById |
|
58 | 57 | }); |
59 | 58 |
|
60 | 59 | it('throws an exception when retrieving a non-existent user', function () { |
61 | | - $userPersistence = new UserPersistence(); |
| 60 | + $userPersistence = new UserPersistence; |
62 | 61 |
|
63 | 62 | // Attempt to retrieve a non-existent user |
64 | 63 | $userPersistence->getById(UserId::fromInt(999)); |
|
69 | 68 | $email = new Email('original@example.com'); |
70 | 69 | $password = Password::createFromPlainText('password123'); |
71 | 70 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Original DisplayName'); |
72 | | - $userPersistence = new UserPersistence(); |
| 71 | + $userPersistence = new UserPersistence; |
73 | 72 | $savedUser = $userPersistence->create($createdUser); |
74 | 73 |
|
75 | 74 | // Create an updated version of the user with new email |
|
102 | 101 | }); |
103 | 102 |
|
104 | 103 | it('throws an exception when updating a non-existent user', function () { |
105 | | - $userPersistence = new UserPersistence(); |
| 104 | + $userPersistence = new UserPersistence; |
106 | 105 | $email = new Email('nonexistent@example.com'); |
107 | 106 | $password = Password::createFromPlainText('password123'); |
108 | 107 |
|
|
112 | 111 |
|
113 | 112 | it('can paginate users', function () { |
114 | 113 | // Create multiple test users |
115 | | - $userPersistence = new UserPersistence(); |
| 114 | + $userPersistence = new UserPersistence; |
116 | 115 |
|
117 | 116 | // Create 5 users |
118 | 117 | for ($i = 1; $i <= 5; $i++) { |
|
148 | 147 | }); |
149 | 148 |
|
150 | 149 | it('can filter users with search criteria', function () { |
151 | | - $userPersistence = new UserPersistence(); |
| 150 | + $userPersistence = new UserPersistence; |
152 | 151 | $password = Password::createFromPlainText('password123'); |
153 | 152 |
|
154 | 153 | // Create users with specific display_names and emails |
|
223 | 222 | $email = new Email('delete@example.com'); |
224 | 223 | $password = Password::createFromPlainText('password123'); |
225 | 224 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Test User'); |
226 | | - $userPersistence = new UserPersistence(); |
| 225 | + $userPersistence = new UserPersistence; |
227 | 226 | $savedUser = $userPersistence->create($createdUser); |
228 | 227 |
|
229 | 228 | // Delete the user |
|
237 | 236 | }); |
238 | 237 |
|
239 | 238 | it('throws an exception when deleting a non-existent user', function () { |
240 | | - $userPersistence = new UserPersistence(); |
| 239 | + $userPersistence = new UserPersistence; |
241 | 240 | $email = new Email('nonexistent@example.com'); |
242 | 241 | $password = Password::createFromPlainText('password123'); |
243 | 242 |
|
|
250 | 249 | $email = new Email('password@example.com'); |
251 | 250 | $password = Password::createFromPlainText('oldpassword123'); |
252 | 251 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Password User'); |
253 | | - $userPersistence = new UserPersistence(); |
| 252 | + $userPersistence = new UserPersistence; |
254 | 253 | $savedUser = $userPersistence->create($createdUser); |
255 | 254 |
|
256 | 255 | // Change password |
|
269 | 268 | $email = new Email('role-test@example.com'); |
270 | 269 | $password = Password::createFromPlainText('password123'); |
271 | 270 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Role Test User'); |
272 | | - $userPersistence = new UserPersistence(); |
| 271 | + $userPersistence = new UserPersistence; |
273 | 272 | $savedUser = $userPersistence->create($createdUser); |
274 | 273 |
|
275 | 274 | // Create test roles |
|
324 | 323 | $email = new Email('empty-roles@example.com'); |
325 | 324 | $password = Password::createFromPlainText('password123'); |
326 | 325 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'No Roles User'); |
327 | | - $userPersistence = new UserPersistence(); |
| 326 | + $userPersistence = new UserPersistence; |
328 | 327 | $savedUser = $userPersistence->create($createdUser); |
329 | 328 |
|
330 | 329 | // Create roles and assign them |
|
364 | 363 | $email = new Email('preserve-roles@example.com'); |
365 | 364 | $password = Password::createFromPlainText('password123'); |
366 | 365 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Preserve Roles User'); |
367 | | - $userPersistence = new UserPersistence(); |
| 366 | + $userPersistence = new UserPersistence; |
368 | 367 | $savedUser = $userPersistence->create($createdUser); |
369 | 368 |
|
370 | 369 | // Create roles and assign them |
|
406 | 405 | $email = new Email('no-roles@example.com'); |
407 | 406 | $password = Password::createFromPlainText('password123'); |
408 | 407 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'No Initial Roles'); |
409 | | - $userPersistence = new UserPersistence(); |
| 408 | + $userPersistence = new UserPersistence; |
410 | 409 | $savedUser = $userPersistence->create($createdUser); |
411 | 410 |
|
412 | 411 | // Create a role to assign |
|
435 | 434 | $email = new Email('exists@example.com'); |
436 | 435 | $password = Password::createFromPlainText('password123'); |
437 | 436 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Existing User'); |
438 | | - $userPersistence = new UserPersistence(); |
| 437 | + $userPersistence = new UserPersistence; |
439 | 438 | $userPersistence->create($createdUser); |
440 | 439 |
|
441 | 440 | // Check if the email exists |
|
446 | 445 | }); |
447 | 446 |
|
448 | 447 | it('returns false when no user exists with the given email', function () { |
449 | | - $userPersistence = new UserPersistence(); |
| 448 | + $userPersistence = new UserPersistence; |
450 | 449 |
|
451 | 450 | // Check for a non-existent email |
452 | 451 | $result = $userPersistence->existsByEmail('nonexistent@example.com'); |
|
460 | 459 | $email = new Email('retrieve-by-email@example.com'); |
461 | 460 | $password = Password::createFromPlainText('password123'); |
462 | 461 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Email User'); |
463 | | - $userPersistence = new UserPersistence(); |
| 462 | + $userPersistence = new UserPersistence; |
464 | 463 | $savedUser = $userPersistence->create($createdUser); |
465 | 464 |
|
466 | 465 | // Retrieve the user using getByEmail |
|
474 | 473 | }); |
475 | 474 |
|
476 | 475 | it('throws an auth failure exception when retrieving a user with non-existent email', function () { |
477 | | - $userPersistence = new UserPersistence(); |
| 476 | + $userPersistence = new UserPersistence; |
478 | 477 |
|
479 | 478 | // Attempt to retrieve a non-existent user by email |
480 | 479 | $userPersistence->getByEmailOrThrowAuthFailure('nonexistent-email@example.com'); |
|
485 | 484 | $email = new Email('token-user@example.com'); |
486 | 485 | $password = Password::createFromPlainText('password123'); |
487 | 486 | $createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Token User'); |
488 | | - $userPersistence = new UserPersistence(); |
| 487 | + $userPersistence = new UserPersistence; |
489 | 488 | $savedUser = $userPersistence->create($createdUser); |
490 | 489 |
|
491 | 490 | // Generate a login token for the user |
|
505 | 504 | }); |
506 | 505 |
|
507 | 506 | it('throws an exception when generating a token for a non-existent user', function () { |
508 | | - $userPersistence = new UserPersistence(); |
| 507 | + $userPersistence = new UserPersistence; |
509 | 508 | $email = new Email('nonexistent-token@example.com'); |
510 | 509 | $password = Password::createFromPlainText('password123'); |
511 | 510 | $nonExistentUser = $this->userFactory->create(UserId::fromInt(999), $email, $password, 'NonExistent User'); |
|
0 commit comments