Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webapi): Return 410 GONE for notification checks on deleted dialogs #1387

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum NotificationConditionType
}

[GenerateOneOf]
public sealed partial class NotificationConditionResult : OneOfBase<NotificationConditionDto, ValidationError, EntityNotFound>;
public sealed partial class NotificationConditionResult : OneOfBase<NotificationConditionDto, ValidationError, EntityNotFound, EntityDeleted>;

internal sealed class NotificationConditionQueryHandler : IRequestHandler<NotificationConditionQuery, NotificationConditionResult>
{
Expand All @@ -41,6 +41,7 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
.Include(x => x.Activities
.Where(x => request.TransmissionId == null || x.TransmissionId == request.TransmissionId)
.Where(x => x.TypeId == request.ActivityType))
.IgnoreQueryFilters()
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
cancellationToken: cancellationToken);

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

if (dialog.Deleted)
{
return new EntityDeleted<DialogEntity>(request.DialogId);
}

var conditionMet = dialog.Activities.Count == 0
? request.ConditionType == NotificationConditionType.NotExists
: request.ConditionType == NotificationConditionType.Exists;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public override async Task HandleAsync(NotificationConditionQuery req, Cancellat
await result.Match(
dto => SendOkAsync(dto, ct),
validationError => this.BadRequestAsync(validationError, ct),
notFound => this.NotFoundAsync(notFound, ct));
notFound => this.NotFoundAsync(notFound, ct),
deleted => this.GoneAsync(deleted, ct));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.NotificationCondition;
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create;
using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Delete;
using Digdir.Domain.Dialogporten.Application.Integration.Tests.Common;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities;
using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Transmissions;
Expand Down Expand Up @@ -39,12 +40,7 @@ public async Task SendNotification_Should_Be_True_When_Conditions_Are_Met(
var response = await Application.Send(createDialogCommand);
response.TryPickT0(out var dialogId, out _);

var notificationConditionQuery = new NotificationConditionQuery
{
DialogId = dialogId.Value,
ActivityType = activityType,
ConditionType = conditionType,
};
var notificationConditionQuery = CreateNotificationConditionQuery(dialogId.Value, activityType, conditionType);

if (activityType is DialogActivityType.Values.TransmissionOpened)
{
Expand Down Expand Up @@ -79,12 +75,7 @@ private static void AddActivityRequirements(
public async Task NotFound_Should_Be_Returned_When_Dialog_Does_Not_Exist()
{
// Arrange
var notificationConditionQuery = new NotificationConditionQuery
{
DialogId = Guid.NewGuid(),
ActivityType = DialogActivityType.Values.Information,
ConditionType = NotificationConditionType.Exists,
};
var notificationConditionQuery = CreateNotificationConditionQuery(Guid.NewGuid());

// Act
var queryResult = await Application.Send(notificationConditionQuery);
Expand All @@ -94,4 +85,37 @@ public async Task NotFound_Should_Be_Returned_When_Dialog_Does_Not_Exist()
queryResult.IsT2.Should().BeTrue();
notFound.Should().NotBeNull();
}

[Fact]
public async Task Gone_Should_Be_Returned_When_Dialog_Is_Deleted()
{
// Arrange
var createDialogCommand = DialogGenerator.GenerateSimpleFakeDialog();

var response = await Application.Send(createDialogCommand);
response.TryPickT0(out var dialogId, out _);

await Application.Send(new DeleteDialogCommand { Id = dialogId.Value });

var notificationConditionQuery = CreateNotificationConditionQuery(dialogId.Value);

// Act
var queryResult = await Application.Send(notificationConditionQuery);

// Assert
queryResult.TryPickT3(out var deleted, out _);
queryResult.IsT3.Should().BeTrue();
deleted.Should().NotBeNull();
deleted.Message.Should().Contain(dialogId.Value.ToString());
}

private static NotificationConditionQuery CreateNotificationConditionQuery(Guid dialogId,
DialogActivityType.Values activityType = DialogActivityType.Values.Information,
NotificationConditionType conditionType = NotificationConditionType.Exists)
=> new()
{
DialogId = dialogId,
ActivityType = activityType,
ConditionType = conditionType,
};
}
Loading