Skip to content

Commit

Permalink
Enhance the logic to ensure all existing unit tests execute successfu…
Browse files Browse the repository at this point in the history
…lly.
  • Loading branch information
Ahmed-Ghanam committed Nov 29, 2024
1 parent 1b58b0d commit 1b0385d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public async Task ProcessOrder(NotificationOrder order)
/// <inheritdoc/>
public async Task ProcessOrderWithoutAddressLookup(NotificationOrder order, List<Recipient> recipients)
{
var emailTemplate = order.Templates[0] as EmailTemplate;
EmailTemplate? emailTemplate = null;
if (order.Templates.Count > 0)
{
emailTemplate = order.Templates[0] as EmailTemplate;
}

foreach (Recipient recipient in recipients)
{
await _emailService.CreateNotification(order.Id, order.RequestedSendTime, recipient, order.IgnoreReservation ?? false, emailTemplate?.Body, emailTemplate?.Subject);
Expand All @@ -66,7 +71,12 @@ public async Task ProcessOrderRetry(NotificationOrder order)
/// <inheritdoc/>
public async Task ProcessOrderRetryWithoutAddressLookup(NotificationOrder order, List<Recipient> recipients)
{
var emailTemplate = order.Templates[0] as EmailTemplate;
EmailTemplate? emailTemplate = null;
if (order.Templates.Count > 0)
{
emailTemplate = order.Templates[0] as EmailTemplate;
}

List<EmailRecipient> emailRecipients = await _emailNotificationRepository.GetRecipients(order.Id);

foreach (Recipient recipient in recipients)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public NotificationOrderTests()
new JsonObject()
{
{ "$", "email" },
{ "type", "Email" },
{ "body", "email-body" },
{ "contentType", "Html" },
{ "fromAddress", "[email protected]" },
{ "subject", "email-subject" },
{ "body", "email-body" },
{ "contentType", "Html" }
{ "type", "Email" }
}
}
},
Expand All @@ -93,12 +93,6 @@ public NotificationOrderTests()
{
new JsonObject()
{
{
"nationalIdentityNumber", "nationalidentitynumber"
},
{
"isReserved", false
},
{
"addressInfo", new JsonArray()
{
Expand All @@ -109,10 +103,16 @@ public NotificationOrderTests()
{ "emailAddress", "[email protected]" }
}
}
},
{
"isReserved", false
},
{
"nationalIdentityNumber", "nationalidentitynumber"
}
}
}
}
}
}.ToJsonString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Altinn.Notifications.Core.Models;
using Altinn.Notifications.Core.Models.Address;
using Altinn.Notifications.Core.Models.Notification;
using Altinn.Notifications.Core.Models.Recipients;
using Altinn.Notifications.Core.Persistence;
using Altinn.Notifications.Core.Services;
using Altinn.Notifications.Core.Services.Interfaces;
Expand Down Expand Up @@ -313,7 +314,9 @@ private static EmailNotificationService GetTestService(IEmailNotificationReposit

if (keywordsService == null)
{
keywordsService = new Mock<IKeywordsService>().Object;
var keywordsServiceMock = new Mock<IKeywordsService>();
keywordsServiceMock.Setup(e => e.ReplaceKeywordsAsync(It.IsAny<EmailRecipient>())).ReturnsAsync((EmailRecipient recipient) => recipient);
keywordsService = keywordsServiceMock.Object;
}

return new EmailNotificationService(guidService.Object, dateTimeService.Object, repo, producer, Options.Create(new KafkaSettings { EmailQueueTopicName = _emailQueueTopicName }), keywordsService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Altinn.Notifications.Core.Models;
using Altinn.Notifications.Core.Models.Address;
using Altinn.Notifications.Core.Models.Notification;
using Altinn.Notifications.Core.Models.Recipients;
using Altinn.Notifications.Core.Persistence;
using Altinn.Notifications.Core.Services;
using Altinn.Notifications.Core.Services.Interfaces;
Expand Down Expand Up @@ -306,7 +307,9 @@ private static SmsNotificationService GetTestService(ISmsNotificationRepository?

if (keywordsService == null)
{
keywordsService = new Mock<IKeywordsService>().Object;
var keywordsServiceMock = new Mock<IKeywordsService>();
keywordsServiceMock.Setup(e => e.ReplaceKeywordsAsync(It.IsAny<SmsRecipient>())).ReturnsAsync((SmsRecipient recipient) => recipient);
keywordsService = keywordsServiceMock.Object;
}

return new SmsNotificationService(guidService.Object, dateTimeService.Object, repo, producer, Options.Create(new KafkaSettings { SmsQueueTopicName = _smsQueueTopicName }), keywordsService);
Expand Down

0 comments on commit 1b0385d

Please sign in to comment.