Skip to content

Commit

Permalink
Make forget command idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
pablothedude committed Jan 16, 2025
1 parent 33aa8cd commit c9a1f10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/Surfnet/Stepup/Identity/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,8 +1003,6 @@ public function expressPreferredLocale(Locale $preferredLocale): void

public function forget(): void
{
$this->assertNotForgotten();

if ($this->registrationAuthorities->count() !== 0) {
throw new DomainException('Cannot forget an identity that is currently accredited as an RA(A)');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ public function an_identity_can_be_forgotten(): void
* @group command-handler
* @group sensitive-data
*/
public function an_identity_may_not_be_forgotten_twice(): void
public function an_identity_may_be_forgotten_twice(): void
{
$this->expectExceptionMessage("Operation on this Identity is not allowed: it has been forgotten");
$this->expectException(DomainException::class);

$identityId = new IdentityId('A');
$institution = new Institution('Helsingin Yliopisto');
$nameId = new NameId('urn:eeva-kuopio');
Expand All @@ -178,6 +175,11 @@ public function an_identity_may_not_be_forgotten_twice(): void
->with(new IsEqual($nameId), new IsEqual($institution))
->andReturn($this->createIdentity($identityId->getIdentityId()));

$this->sensitiveDataService
->shouldReceive('forgetSensitiveData')
->once()
->with(new IsEqual($identityId));

$this->sraaRepository->shouldReceive('contains')->once()->with(new IsEqual($nameId))->andReturn(false);

$command = new ForgetIdentityCommand();
Expand Down Expand Up @@ -207,7 +209,10 @@ public function an_identity_may_not_be_forgotten_twice(): void
),
new IdentityForgottenEvent($identityId, $institution),
])
->when($command);
->when($command)
->then([
new IdentityForgottenEvent($identityId, $institution),
]);
}

/**
Expand Down

0 comments on commit c9a1f10

Please sign in to comment.