Skip to content

Commit b1d06b7

Browse files
authored
It is possible to cancel deletion processes with expired grace periods (#989)
* fix: throw if deletion grace period is expired * test: write a test for it
1 parent 9b49f85 commit b1d06b7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Modules/Devices/src/Devices.Domain/DomainErrors.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public static DomainError GracePeriodHasNotYetExpired()
6464
"The deletion via this deletion process cannot be started because the grace period has not yet expired.");
6565
}
6666

67+
public static DomainError GracePeriodHasAlreadyExpired()
68+
{
69+
return new DomainError("error.platform.validation.device.gracePeriodHasAlreadyExpired",
70+
"You cannot perform this action, because the grace period of this deletion process has already expired.");
71+
}
72+
6773
public static DomainError DeletionProcessMustBePastDueApproval()
6874
{
6975
return new DomainError("error.platform.validation.device.noDeletionProcessIsPastDueApproval", "No deletion process is past due approval.");

Modules/Devices/src/Devices.Domain/Entities/Identities/IdentityDeletionProcess.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ public void CancelAsOwner(IdentityAddress address, DeviceId cancelledByDevice)
181181
if (Status != DeletionProcessStatus.Approved)
182182
throw new DomainException(DomainErrors.DeletionProcessMustBeInStatus(DeletionProcessStatus.Approved));
183183

184+
if (GracePeriodEndsAt < SystemTime.UtcNow)
185+
throw new DomainException(DomainErrors.GracePeriodHasAlreadyExpired());
186+
184187
ChangeStatus(DeletionProcessStatus.Cancelled, address, address);
185188
CancelledAt = SystemTime.UtcNow;
186189
CancelledByDevice = cancelledByDevice;

Modules/Devices/test/Devices.Domain.Tests/Identities/CancelDeletionProcessAsOwnerTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ public void Throws_when_deletion_process_is_in_wrong_status()
5858
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.device.deletionProcessIsNotInRequiredStatus");
5959
}
6060

61+
[Fact]
62+
public void Throws_when_grace_period_has_expired()
63+
{
64+
// Arrange
65+
var identity = TestDataGenerator.CreateIdentityWithApprovedDeletionProcess();
66+
67+
SystemTime.Set(DateTime.UtcNow.AddDays(IdentityDeletionConfiguration.Instance.LengthOfGracePeriodInDays));
68+
69+
// Act
70+
var acting = () => identity.CancelDeletionProcessAsOwner(identity.DeletionProcesses[0].Id, identity.Devices[0].Id);
71+
72+
// Assert
73+
acting.Should().Throw<DomainException>().Which.Code.Should().Be("error.platform.validation.device.gracePeriodHasAlreadyExpired");
74+
}
75+
6176
[Fact]
6277
public void Raises_domain_events()
6378
{

0 commit comments

Comments
 (0)