From 2619d151ee8a1fb0f8eab4294007ab03e9f4d979 Mon Sep 17 00:00:00 2001 From: Md Majid Akhter <101315579+qxz2mqe@users.noreply.github.com> Date: Wed, 12 Jul 2023 19:40:23 +0530 Subject: [PATCH] fix(notification): get notification details (#135) 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 Reviewed-by: Phil Schneider --- .../Controllers/NotificationController.cs | 2 +- .../Models/NotificationDetailData.cs | 2 +- .../NotificationRepositoryTests.cs | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/notifications/Notifications.Service/Controllers/NotificationController.cs b/src/notifications/Notifications.Service/Controllers/NotificationController.cs index 0a8b2fb25f..06bba51a9a 100644 --- a/src/notifications/Notifications.Service/Controllers/NotificationController.cs +++ b/src/notifications/Notifications.Service/Controllers/NotificationController.cs @@ -61,7 +61,7 @@ public NotificationController(INotificationBusinessLogic logic) /// OPTIONAL: Topic of the notifications /// OPTIONAL: If true only notifications with a due date will be returned /// Defines the sorting of the list - /// Defines the done state + /// OPTIONAL: Defines the done state /// Collection of the unread notifications for the user. /// NotificationType or NotificationStatus don't exist. [HttpGet] diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/NotificationDetailData.cs b/src/portalbackend/PortalBackend.DBAccess/Models/NotificationDetailData.cs index eb8d56890c..9d98aedb19 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/NotificationDetailData.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/NotificationDetailData.cs @@ -36,7 +36,7 @@ public record NotificationDetailData( Guid Id, DateTimeOffset Created, NotificationTypeId TypeId, - NotificationTopicId NotificationTopic, + NotificationTopicId? NotificationTopic, bool IsRead, string? Content, DateTimeOffset? DueDate, diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/NotificationRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/NotificationRepositoryTests.cs index 26416b4a2d..31081f0f64 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/NotificationRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/NotificationRepositoryTests.cs @@ -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(); + results.Data.Where(x => x.NotificationTopic == null).Should().ContainSingle(); + + await trans.RollbackAsync().ConfigureAwait(false); + } #endregion #region GetNotificationByIdAndIamUserId @@ -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