From 3de469ca5401ba28f1b60d6dbbda17a7c50b67b6 Mon Sep 17 00:00:00 2001 From: Hallgeir Garnes-Gutvik Date: Mon, 23 Sep 2024 16:20:14 +0200 Subject: [PATCH] Add SMS address point in NotificationOrderRequest for recipients with only phone no. (#613) * Correct comment typo * In test, add recipient with only mobile phone no. to catch scenario of #608. Includes indentation formatting * When mapping order requests, also add SMS address points for phone no. --- .../Mappers/OrderMapper.cs | 5 +++++ .../NotificationOrderRequestResponseExt.cs | 2 +- .../TestingMappers/OrderMapperTests.cs | 20 ++++++++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Altinn.Notifications/Mappers/OrderMapper.cs b/src/Altinn.Notifications/Mappers/OrderMapper.cs index 50a7ff38..0bb80cb3 100644 --- a/src/Altinn.Notifications/Mappers/OrderMapper.cs +++ b/src/Altinn.Notifications/Mappers/OrderMapper.cs @@ -29,6 +29,11 @@ public static NotificationOrderRequest MapToOrderRequest(this NotificationOrderR addresses.Add(new EmailAddressPoint(r.EmailAddress)); } + if (!string.IsNullOrEmpty(r.MobileNumber)) + { + addresses.Add(new SmsAddressPoint(r.MobileNumber)); + } + return new Recipient(addresses, r.OrganizationNumber, r.NationalIdentityNumber); }) .ToList(); diff --git a/src/Altinn.Notifications/Models/NotificationOrderRequestResponseExt.cs b/src/Altinn.Notifications/Models/NotificationOrderRequestResponseExt.cs index ed701b5e..6b4688e0 100644 --- a/src/Altinn.Notifications/Models/NotificationOrderRequestResponseExt.cs +++ b/src/Altinn.Notifications/Models/NotificationOrderRequestResponseExt.cs @@ -6,7 +6,7 @@ namespace Altinn.Notifications.Models; /// A class representing a container for an order id. /// /// -/// External representaion to be used in the API. +/// External representation to be used in the API. /// public class NotificationOrderRequestResponseExt { diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs index 56c5770c..bc768c85 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs @@ -140,8 +140,8 @@ public void ForEmailMapToOrderRequest_RecipientsProvided_AreEquivalent() NotificationChannel = NotificationChannel.Email, Recipients = new List() { - new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient1@domain.com") } }, - new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient2@domain.com") } } + new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient1@domain.com") } }, + new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient2@domain.com") } } } }; @@ -222,8 +222,8 @@ public void ForSmsMapToOrderRequest_RecipientsProvided_AreEquivalent() NotificationChannel = NotificationChannel.Sms, Recipients = new List() { - new Recipient() { AddressInfo = new List() { new SmsAddressPoint("+4740000001") } }, - new Recipient() { AddressInfo = new List() { new SmsAddressPoint("+4740000002") } } + new Recipient() { AddressInfo = new List() { new SmsAddressPoint("+4740000001") } }, + new Recipient() { AddressInfo = new List() { new SmsAddressPoint("+4740000002") } } } }; @@ -289,7 +289,12 @@ public void MapToOrderRequest_AreEquivalent(NotificationChannelExt extChannel, N { Body = "sms-body", }, - Recipients = new List() { new RecipientExt() { EmailAddress = "recipient1@domain.com" }, new RecipientExt() { NationalIdentityNumber = "123456" } }, + Recipients = new List() + { + new RecipientExt() { EmailAddress = "recipient1@domain.com" }, + new RecipientExt() { NationalIdentityNumber = "123456" }, + new RecipientExt() { MobileNumber = "+4712345678" } + }, SendersReference = "senders-reference", RequestedSendTime = sendTime, ConditionEndpoint = new Uri("https://vg.no"), @@ -315,8 +320,9 @@ public void MapToOrderRequest_AreEquivalent(NotificationChannelExt extChannel, N RequestedSendTime = sendTime, Recipients = new List() { - new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient1@domain.com") } }, - new Recipient() { NationalIdentityNumber = "123456" } + new Recipient() { AddressInfo = new List() { new EmailAddressPoint("recipient1@domain.com") } }, + new Recipient() { NationalIdentityNumber = "123456" }, + new Recipient() { AddressInfo = new List() { new SmsAddressPoint("+4712345678") } } }, ConditionEndpoint = new Uri("https://vg.no"), IgnoreReservation = true,