From 97bde73777e4430b98f7f424c2450c73ee673ef6 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Sun, 17 May 2026 13:12:58 +0200 Subject: [PATCH] Refactored GetNotificationsAsync() date handling --- .../NotificationsFeatureTests.cs | 20 ++++++++++++++++++- .../Shop/Notifications/NotificationService.cs | 5 +++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/LiteCharms.Features.Tests/NotificationsFeatureTests.cs b/LiteCharms.Features.Tests/NotificationsFeatureTests.cs index 2c7518b..7ee7e9a 100644 --- a/LiteCharms.Features.Tests/NotificationsFeatureTests.cs +++ b/LiteCharms.Features.Tests/NotificationsFeatureTests.cs @@ -1,4 +1,5 @@ -using LiteCharms.Features.Shop.Notifications; +using LiteCharms.Features.Models; +using LiteCharms.Features.Shop.Notifications; using LiteCharms.Features.Shop.Notifications.Events; namespace LiteCharms.Features.Tests; @@ -34,6 +35,23 @@ public class NotificationsFeatureTests(CommonFixture fixture, ITestOutputHelper foreach (var error in createResult.Errors) output.WriteLine(error.Message); } + [Fact] + public async Task GetNotifications_ShouldReturn_AllNotifications() + { + DateRange range = new() + { + From = DateOnly.FromDateTime(new DateTime(2026, 05, 01, 0, 0, 0, DateTimeKind.Utc)), + To = DateOnly.FromDateTime(DateTime.UtcNow), + MaxRecords = 10 + }; + + var getResult = await notificationService.GetNotificationsAsync(range); + + Assert.True(getResult.IsSuccess); + + foreach (var error in getResult.Errors) output.WriteLine(error.Message); + } + [Fact] public async Task ProcessEmailNotificationsEvent_ShouldSucceed() { diff --git a/LiteCharms.Features/Shop/Notifications/NotificationService.cs b/LiteCharms.Features/Shop/Notifications/NotificationService.cs index 59493e4..63eb992 100644 --- a/LiteCharms.Features/Shop/Notifications/NotificationService.cs +++ b/LiteCharms.Features/Shop/Notifications/NotificationService.cs @@ -63,8 +63,8 @@ public class NotificationService(IDbContextFactory contextFactory { try { - var fromDate = range.From.ToDateTime(TimeOnly.MinValue); - var toDate = range.To.ToDateTime(TimeOnly.MaxValue); + var fromDate = range.From.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc); + var toDate = range.To.ToDateTime(TimeOnly.MaxValue, DateTimeKind.Utc); using var context = await contextFactory.CreateDbContextAsync(cancellationToken); @@ -96,6 +96,7 @@ public class NotificationService(IDbContextFactory contextFactory return Result.Fail(new Error($"Notification with id {request.NotificationId} not found.")); notification.Processed = request.Processed; + notification.UpdatedAt = DateTime.UtcNow; if (request.HasError) {