Skip to content

Commit

Permalink
It is possible to cancel deletion processes with expired grace periods (
Browse files Browse the repository at this point in the history
#989)

* fix: throw if deletion grace period is expired

* test: write a test for it
  • Loading branch information
tnotheis authored Dec 16, 2024
1 parent 9b49f85 commit b1d06b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Modules/Devices/src/Devices.Domain/DomainErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public static DomainError GracePeriodHasNotYetExpired()
"The deletion via this deletion process cannot be started because the grace period has not yet expired.");
}

public static DomainError GracePeriodHasAlreadyExpired()
{
return new DomainError("error.platform.validation.device.gracePeriodHasAlreadyExpired",
"You cannot perform this action, because the grace period of this deletion process has already expired.");
}

public static DomainError DeletionProcessMustBePastDueApproval()
{
return new DomainError("error.platform.validation.device.noDeletionProcessIsPastDueApproval", "No deletion process is past due approval.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public void CancelAsOwner(IdentityAddress address, DeviceId cancelledByDevice)
if (Status != DeletionProcessStatus.Approved)
throw new DomainException(DomainErrors.DeletionProcessMustBeInStatus(DeletionProcessStatus.Approved));

if (GracePeriodEndsAt < SystemTime.UtcNow)
throw new DomainException(DomainErrors.GracePeriodHasAlreadyExpired());

ChangeStatus(DeletionProcessStatus.Cancelled, address, address);
CancelledAt = SystemTime.UtcNow;
CancelledByDevice = cancelledByDevice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ public void Throws_when_deletion_process_is_in_wrong_status()
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus");
}

[Fact]
public void Throws_when_grace_period_has_expired()
{
// Arrange
var identity = TestDataGenerator.CreateIdentityWithApprovedDeletionProcess();

SystemTime.Set(DateTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays));

// Act
var acting = () => identity.CancelDeletionProcessAsOwner(identity.DeletionProcesses[0].Id, identity.Devices[0].Id);

// Assert
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.device.gracePeriodHasAlreadyExpired");
}

[Fact]
public void Raises_domain_events()
{
Expand Down

0 comments on commit b1d06b7

Please sign in to comment.