feat: soft-delete for teamer accounts
addresses #869dv9br3
This commit is contained in:
@@ -466,6 +466,73 @@ class UserDataHandlerTest extends TestCase
|
||||
$this->assertSame(2, $user->getBusProPersonId());
|
||||
}
|
||||
|
||||
/**
|
||||
* A deleted account still has to be matched by email, otherwise the caller takes the
|
||||
* person for unknown and creates a second account for them - which would resurrect
|
||||
* them under a new row and defeat the deletion entirely. Nothing is written to it.
|
||||
*/
|
||||
public function testFindLocalUserReturnsADeletedEmailMatchWithoutWritingToIt(): void
|
||||
{
|
||||
$user = (new User())
|
||||
->setFirstName('First')
|
||||
->setLastName('Last')
|
||||
->setEmail('[email protected]')
|
||||
->setBusProAddressId(1)
|
||||
->setBusProPersonId(2)
|
||||
;
|
||||
$user->setDeleted();
|
||||
|
||||
$profileResponse = $this->createProfileResponse();
|
||||
|
||||
$repository = $this->createMock(ObjectRepository::class);
|
||||
$repository
|
||||
->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->willReturn(null);
|
||||
|
||||
$repository
|
||||
->expects($this->once())
|
||||
->method('findBy')
|
||||
->with([
|
||||
'email' => '[email protected]',
|
||||
])
|
||||
->willReturn([$user]);
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with(User::class)
|
||||
->willReturn($repository);
|
||||
|
||||
$handler = new UserDataHandler($this->entityManager, $this->logger);
|
||||
$resolvedUser = $handler->findLocalUser($profileResponse);
|
||||
|
||||
$this->assertSame($user, $resolvedUser);
|
||||
$this->assertSame(1, $user->getBusProAddressId());
|
||||
$this->assertSame(2, $user->getBusProPersonId());
|
||||
}
|
||||
|
||||
public function testDisableForRevokedCrmRolesLeavesADeletedAccountAlone(): void
|
||||
{
|
||||
$user = (new User())
|
||||
->setFirstName('First')
|
||||
->setLastName('Last')
|
||||
->setEmail('[email protected]')
|
||||
->setRoles(['ROLE_TEAMER'])
|
||||
;
|
||||
$user->setDeleted();
|
||||
|
||||
$this->entityManager
|
||||
->expects($this->never())
|
||||
->method('flush');
|
||||
|
||||
$handler = new UserDataHandler($this->entityManager, $this->logger);
|
||||
$handler->disableForRevokedCrmRoles($user);
|
||||
|
||||
$this->assertFalse($user->isDisabled());
|
||||
$this->assertSame(['ROLE_TEAMER'], $user->getAssignedRoles());
|
||||
}
|
||||
|
||||
private function createProfileResponse(?int $addressId = 200, ?int $personId = 100): ProfileResponse
|
||||
{
|
||||
$address = (new BusProAddress())
|
||||
|
||||
Reference in New Issue
Block a user