Skip to content

Commit 198bebd

Browse files
authored
feat(webapi): Return 410 GONE for notification checks on deleted dialogs (#1387)
<!--- Provide a general summary of your changes in the Title above --> ## Description <!--- Describe your changes in detail --> ## Related Issue(s) - #1386 ## Verification - [ ] **Your** code builds clean without any errors or warnings - [ ] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced error handling for deleted entities in the notification condition query. - Added a new response type for deleted dialogs, improving clarity in error reporting. - **Bug Fixes** - Improved response handling for scenarios where a requested dialog has been deleted. - **Tests** - Introduced a new test case to verify correct behavior when querying a deleted dialog. - Refactored test methods for improved readability and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 431fe16 commit 198bebd

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/NotificationCondition/NotificationConditionQuery.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum NotificationConditionType
2323
}
2424

2525
[GenerateOneOf]
26-
public sealed partial class NotificationConditionResult : OneOfBase<NotificationConditionDto, ValidationError, EntityNotFound>;
26+
public sealed partial class NotificationConditionResult : OneOfBase<NotificationConditionDto, ValidationError, EntityNotFound, EntityDeleted>;
2727

2828
internal sealed class NotificationConditionQueryHandler : IRequestHandler<NotificationConditionQuery, NotificationConditionResult>
2929
{
@@ -41,6 +41,7 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
4141
.Include(x => x.Activities
4242
.Where(x => request.TransmissionId == null || x.TransmissionId == request.TransmissionId)
4343
.Where(x => x.TypeId == request.ActivityType))
44+
.IgnoreQueryFilters()
4445
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
4546
cancellationToken: cancellationToken);
4647

@@ -49,6 +50,11 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
4950
return new EntityNotFound<DialogEntity>(request.DialogId);
5051
}
5152

53+
if (dialog.Deleted)
54+
{
55+
return new EntityDeleted<DialogEntity>(request.DialogId);
56+
}
57+
5258
var conditionMet = dialog.Activities.Count == 0
5359
? request.ConditionType == NotificationConditionType.NotExists
5460
: request.ConditionType == NotificationConditionType.Exists;

src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivities/NotificationCondition/NotificationConditionEndpoint.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public override async Task HandleAsync(NotificationConditionQuery req, Cancellat
2828
await result.Match(
2929
dto => SendOkAsync(dto, ct),
3030
validationError => this.BadRequestAsync(validationError, ct),
31-
notFound => this.NotFoundAsync(notFound, ct));
31+
notFound => this.NotFoundAsync(notFound, ct),
32+
deleted => this.GoneAsync(deleted, ct));
3233
}
3334
}

tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/ServiceOwner/NotificationCondition/NotificationConditionTests.cs

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.NotificationCondition;
22
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create;
3+
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Delete;
34
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common;
45
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;
56
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;
@@ -39,12 +40,7 @@ public async Task SendNotification_Should_Be_True_When_Conditions_Are_Met(
3940
var response = await Application.Send(createDialogCommand);
4041
response.TryPickT0(out var dialogId, out _);
4142

42-
var notificationConditionQuery = new NotificationConditionQuery
43-
{
44-
DialogId = dialogId.Value,
45-
ActivityType = activityType,
46-
ConditionType = conditionType,
47-
};
43+
var notificationConditionQuery = CreateNotificationConditionQuery(dialogId.Value, activityType, conditionType);
4844

4945
if (activityType is DialogActivityType.Values.TransmissionOpened)
5046
{
@@ -79,12 +75,7 @@ private static void AddActivityRequirements(
7975
public async Task NotFound_Should_Be_Returned_When_Dialog_Does_Not_Exist()
8076
{
8177
// Arrange
82-
var notificationConditionQuery = new NotificationConditionQuery
83-
{
84-
DialogId = Guid.NewGuid(),
85-
ActivityType = DialogActivityType.Values.Information,
86-
ConditionType = NotificationConditionType.Exists,
87-
};
78+
var notificationConditionQuery = CreateNotificationConditionQuery(Guid.NewGuid());
8879

8980
// Act
9081
var queryResult = await Application.Send(notificationConditionQuery);
@@ -94,4 +85,37 @@ public async Task NotFound_Should_Be_Returned_When_Dialog_Does_Not_Exist()
9485
queryResult.IsT2.Should().BeTrue();
9586
notFound.Should().NotBeNull();
9687
}
88+
89+
[Fact]
90+
public async Task Gone_Should_Be_Returned_When_Dialog_Is_Deleted()
91+
{
92+
// Arrange
93+
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();
94+
95+
var response = await Application.Send(createDialogCommand);
96+
response.TryPickT0(out var dialogId, out _);
97+
98+
await Application.Send(new DeleteDialogCommand { Id = dialogId.Value });
99+
100+
var notificationConditionQuery = CreateNotificationConditionQuery(dialogId.Value);
101+
102+
// Act
103+
var queryResult = await Application.Send(notificationConditionQuery);
104+
105+
// Assert
106+
queryResult.TryPickT3(out var deleted, out _);
107+
queryResult.IsT3.Should().BeTrue();
108+
deleted.Should().NotBeNull();
109+
deleted.Message.Should().Contain(dialogId.Value.ToString());
110+
}
111+
112+
private static NotificationConditionQuery CreateNotificationConditionQuery(Guid dialogId,
113+
DialogActivityType.Values activityType = DialogActivityType.Values.Information,
114+
NotificationConditionType conditionType = NotificationConditionType.Exists)
115+
=> new()
116+
{
117+
DialogId = dialogId,
118+
ActivityType = activityType,
119+
ConditionType = conditionType,
120+
};
97121
}

0 commit comments

Comments
 (0)