Skip to content

Commit

Permalink
fix(notification): get notification details (#135)
Browse files Browse the repository at this point in the history
fix swagger description
change NotificationTopicId to nullable for endpoint Get: /api/notification to prevend database query exceptions

---------

Refs: CPLP-2934
Co-authored-by: Phil Schneider <[email protected]>
Reviewed-by: Phil Schneider <[email protected]>
  • Loading branch information
qxz2mqe and Phil91 authored Jul 12, 2023
1 parent a17cfd6 commit 2619d15
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public NotificationController(INotificationBusinessLogic logic)
/// <param name="notificationTopicId">OPTIONAL: Topic of the notifications</param>
/// <param name="onlyDueDate">OPTIONAL: If true only notifications with a due date will be returned</param>
/// <param name="sorting">Defines the sorting of the list</param>
/// <param name="doneState">Defines the done state</param>
/// <param name="doneState">OPTIONAL: Defines the done state</param>
/// <response code="200">Collection of the unread notifications for the user.</response>
/// <response code="400">NotificationType or NotificationStatus don't exist.</response>
[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public record NotificationDetailData(
Guid Id,
DateTimeOffset Created,
NotificationTypeId TypeId,
NotificationTopicId NotificationTopic,
NotificationTopicId? NotificationTopic,
bool IsRead,
string? Content,
DateTimeOffset? DueDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,27 @@ public async Task GetAllAsDetailsByUserIdUntracked_WithDoneState_ReturnsExpected
}
}

[Fact]
public async Task GetAllAsDetailsByUserIdUntracked_WithUnlinkedNotificationTypeIdandTopicId_ReturnsExpectedNotificationDetailData()
{
// Arrange
var (sut, context) = await CreateSutWithContext().ConfigureAwait(false);
using var trans = await context.Database.BeginTransactionAsync().ConfigureAwait(false);
context.NotificationTypeAssignedTopics.Remove(new NotificationTypeAssignedTopic(NotificationTypeId.INFO, NotificationTopicId.INFO));
await context.SaveChangesAsync().ConfigureAwait(false);

// Act
var results = await sut.GetAllNotificationDetailsByReceiver(_companyUserId, null, null, null, false, null, null)(0, 15).ConfigureAwait(false);

// Assert
results.Should().NotBeNull();
results!.Count.Should().Be(6);
results.Data.Count().Should().Be(6);
results.Data.Should().AllBeOfType<NotificationDetailData>();
results.Data.Where(x => x.NotificationTopic == null).Should().ContainSingle();

await trans.RollbackAsync().ConfigureAwait(false);
}
#endregion

#region GetNotificationByIdAndIamUserId
Expand All @@ -382,6 +403,30 @@ public async Task GetNotificationByIdAndIamUserId_ForExistingUser_GetsExpectedNo
result.Should().NotBeNull();
result.IsUserReceiver.Should().BeTrue();
result.NotificationDetailData.IsRead.Should().BeTrue();
result.NotificationDetailData.NotificationTopic.Should().Be(NotificationTopicId.INFO);
}

[Fact]
public async Task GetNotificationByIdAndIamUserId_WithoutLinkedTopic_GetsExpectedNotification()
{
// Arrange
var (sut, context) = await CreateSutWithContext().ConfigureAwait(false);
using var trans = await context.Database.BeginTransactionAsync().ConfigureAwait(false);
context.NotificationTypeAssignedTopics.Remove(new NotificationTypeAssignedTopic(NotificationTypeId.INFO, NotificationTopicId.INFO));
await context.SaveChangesAsync().ConfigureAwait(false);

// Act
var result = await sut
.GetNotificationByIdAndValidateReceiverAsync(new Guid("500E4D2C-9919-4CA8-B75B-D523FBC99259"), _companyUserId)
.ConfigureAwait(false);

// Assert
result.Should().NotBeNull();
result.IsUserReceiver.Should().BeTrue();
result.NotificationDetailData.IsRead.Should().BeTrue();
result.NotificationDetailData.NotificationTopic.Should().BeNull();

await trans.RollbackAsync().ConfigureAwait(false);
}

#endregion
Expand Down

0 comments on commit 2619d15

Please sign in to comment.