diff --git a/src/Altinn.Notifications/Mappers/OrderMapper.cs b/src/Altinn.Notifications/Mappers/OrderMapper.cs index 6f302bd7..50a7ff38 100644 --- a/src/Altinn.Notifications/Mappers/OrderMapper.cs +++ b/src/Altinn.Notifications/Mappers/OrderMapper.cs @@ -58,7 +58,7 @@ public static NotificationOrderRequest MapToOrderRequest(this NotificationOrderR creator, templateList, extRequest.RequestedSendTime.ToUniversalTime(), - NotificationChannel.Email, + (NotificationChannel)extRequest.NotificationChannel!, recipients, extRequest.IgnoreReservation, extRequest.ResourceId, diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs index fe744203..56c5770c 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs @@ -266,6 +266,72 @@ public void ForSmsMapToOrderRequest_SendTimeLocalConvertedToUtc_AreEquivalent() Assert.Equivalent(expected, actual, true); } + [Theory] + [InlineData(NotificationChannelExt.Email, NotificationChannel.Email)] + [InlineData(NotificationChannelExt.EmailPreferred, NotificationChannel.EmailPreferred)] + [InlineData(NotificationChannelExt.Sms, NotificationChannel.Sms)] + [InlineData(NotificationChannelExt.SmsPreferred, NotificationChannel.SmsPreferred)] + public void MapToOrderRequest_AreEquivalent(NotificationChannelExt extChannel, NotificationChannel expectedChannel) + { + // Arrange + DateTime sendTime = DateTime.UtcNow; + + NotificationOrderRequestExt ext = new() + { + NotificationChannel = extChannel, + EmailTemplate = new() + { + Subject = "email-subject", + Body = "email-body", + ContentType = EmailContentTypeExt.Html + }, + SmsTemplate = new() + { + Body = "sms-body", + }, + Recipients = new List() { new RecipientExt() { EmailAddress = "recipient1@domain.com" }, new RecipientExt() { NationalIdentityNumber = "123456" } }, + SendersReference = "senders-reference", + RequestedSendTime = sendTime, + ConditionEndpoint = new Uri("https://vg.no"), + IgnoreReservation = true, + ResourceId = "urn:altinn:resource:test" + }; + + NotificationOrderRequest expected = new() + { + SendersReference = "senders-reference", + Creator = new Creator("ttd"), + Templates = new List() + { + new EmailTemplate( + string.Empty, + "email-subject", + "email-body", + EmailContentType.Html), + new SmsTemplate( + string.Empty, + "sms-body") + }, + RequestedSendTime = sendTime, + Recipients = new List() + { + new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient1@domain.com") } }, + new Recipient() { NationalIdentityNumber = "123456" } + }, + ConditionEndpoint = new Uri("https://vg.no"), + IgnoreReservation = true, + ResourceId = "urn:altinn:resource:test" + }; + + expected.NotificationChannel = expectedChannel; + + // Act + var actual = ext.MapToOrderRequest("ttd"); + + // Assert + Assert.Equivalent(expected, actual); + } + [Fact] public void MapToNotificationOrderWithStatusExt_EmailStatusProvided_AreEquivalent() {