diff --git a/src/Altinn.Notifications.Core/Models/Notification/EmailNotification.cs b/src/Altinn.Notifications.Core/Models/Notification/EmailNotification.cs index 0607229e..2040f3c1 100644 --- a/src/Altinn.Notifications.Core/Models/Notification/EmailNotification.cs +++ b/src/Altinn.Notifications.Core/Models/Notification/EmailNotification.cs @@ -1,4 +1,5 @@ using Altinn.Notifications.Core.Enums; +using Altinn.Notifications.Core.Models.Recipients; namespace Altinn.Notifications.Core.Models.Notification; @@ -20,14 +21,9 @@ public class EmailNotification : INotification public NotificationChannel NotificationChannel { get; } = NotificationChannel.Email; /// - /// Get the id of the recipient of the email notification + /// Gets the recipient of the notification /// - public string? RecipientId { get; internal set; } - - /// - /// Get or sets the to address of the email notification - /// - public string ToAddress { get; internal set; } = string.Empty; + public EmailRecipient Recipient { get; internal set; } = new(); /// /// Get or sets the send result of the notification diff --git a/src/Altinn.Notifications.Core/Models/Notification/SmsNotification.cs b/src/Altinn.Notifications.Core/Models/Notification/SmsNotification.cs index 54077d4d..3fa5c2b7 100644 --- a/src/Altinn.Notifications.Core/Models/Notification/SmsNotification.cs +++ b/src/Altinn.Notifications.Core/Models/Notification/SmsNotification.cs @@ -1,4 +1,5 @@ using Altinn.Notifications.Core.Enums; +using Altinn.Notifications.Core.Models.Recipients; namespace Altinn.Notifications.Core.Models.Notification; @@ -20,14 +21,9 @@ public class SmsNotification : INotification public NotificationChannel NotificationChannel { get; } = NotificationChannel.Sms; /// - /// Get the id of the recipient of the sms notification + /// Get the recipient of the notification /// - public string? RecipientId { get; internal set; } - - /// - /// Get or sets the mobilenumber of the sms notification - /// - public string RecipientNumber { get; internal set; } = string.Empty; + public SmsRecipient Recipient { get; internal set; } = new(); /// public NotificationResult SendResult { get; internal set; } = new(SmsNotificationResultType.New, DateTime.UtcNow); diff --git a/src/Altinn.Notifications.Core/Models/Recipient.cs b/src/Altinn.Notifications.Core/Models/Recipient.cs index c46f5712..ab3ca0f0 100644 --- a/src/Altinn.Notifications.Core/Models/Recipient.cs +++ b/src/Altinn.Notifications.Core/Models/Recipient.cs @@ -8,29 +8,27 @@ namespace Altinn.Notifications.Core.Models; public class Recipient { /// - /// Gets the recipient id + /// Gets the recipient's organisation number /// - public string RecipientId { get; set; } = string.Empty; + public string? OrganisationNumber { get; set; } = null; /// - /// Gets a list of address points for the recipient + /// Gets the recipient's national identity number /// - public List AddressInfo { get; set; } = new List(); + public string? NationalIdentityNumber { get; set; } = null; /// - /// Initializes a new instance of the class. + /// Gets a list of address points for the recipient /// - public Recipient(string recipientId, List addressInfo) - { - RecipientId = recipientId; - AddressInfo = addressInfo; - } + public List AddressInfo { get; set; } = new List(); /// /// Initializes a new instance of the class. /// - public Recipient(List addressInfo) + public Recipient(List addressInfo, string? organisationNumber = null, string? nationalIdentityNumber = null) { + OrganisationNumber = organisationNumber; + NationalIdentityNumber = nationalIdentityNumber; AddressInfo = addressInfo; } diff --git a/src/Altinn.Notifications.Core/Models/Recipients/EmailRecipient.cs b/src/Altinn.Notifications.Core/Models/Recipients/EmailRecipient.cs index c1f5d4ab..82d9477b 100644 --- a/src/Altinn.Notifications.Core/Models/Recipients/EmailRecipient.cs +++ b/src/Altinn.Notifications.Core/Models/Recipients/EmailRecipient.cs @@ -6,9 +6,14 @@ namespace Altinn.Notifications.Core.Models.Recipients; public class EmailRecipient { /// - /// Gets or sets the recipient id + /// Gets or sets the recipient's organisation number /// - public string? RecipientId { get; set; } = null; + public string? OrganisationNumber { get; set; } = null; + + /// + /// Gets or sets the recipient's national identity number + /// + public string? NationalIdentityNumber { get; set; } = null; /// /// Gets or sets the toaddress diff --git a/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs b/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs index c182a4f0..e70c7976 100644 --- a/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs +++ b/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs @@ -6,9 +6,14 @@ namespace Altinn.Notifications.Core.Models.Recipients; public class SmsRecipient { /// - /// Gets or sets the recipient id + /// Gets or sets the recipient's organisation number /// - public string? RecipientId { get; set; } = null; + public string? OrganisationNumber { get; set; } = null; + + /// + /// Gets or sets the recipient's national identity number + /// + public string? NationalIdentityNumber { get; set; } = null; /// /// Gets or sets the mobile number diff --git a/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs b/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs index cee52a61..9e055446 100644 --- a/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs +++ b/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs @@ -4,6 +4,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.Interfaces; @@ -44,13 +45,20 @@ public async Task CreateNotification(Guid orderId, DateTime requestedSendTime, R { EmailAddressPoint? addressPoint = recipient.AddressInfo.Find(a => a.AddressType == AddressType.Email) as EmailAddressPoint; + EmailRecipient emailRecipient = new() + { + OrganisationNumber = recipient.OrganisationNumber, + NationalIdentityNumber = recipient.NationalIdentityNumber, + ToAddress = addressPoint?.EmailAddress ?? string.Empty + }; + if (!string.IsNullOrEmpty(addressPoint?.EmailAddress)) { - await CreateNotificationForRecipient(orderId, requestedSendTime, recipient.RecipientId, addressPoint.EmailAddress, EmailNotificationResultType.New); + await CreateNotificationForRecipient(orderId, requestedSendTime, emailRecipient, EmailNotificationResultType.New); } else { - await CreateNotificationForRecipient(orderId, requestedSendTime, recipient.RecipientId, string.Empty, EmailNotificationResultType.Failed_RecipientNotIdentified); + await CreateNotificationForRecipient(orderId, requestedSendTime, emailRecipient, EmailNotificationResultType.Failed_RecipientNotIdentified); } } @@ -81,15 +89,14 @@ public async Task UpdateSendStatus(EmailSendOperationResult sendOperationResult) await _repository.UpdateSendStatus(sendOperationResult.NotificationId, (EmailNotificationResultType)sendOperationResult.SendResult!, sendOperationResult.OperationId); } - private async Task CreateNotificationForRecipient(Guid orderId, DateTime requestedSendTime, string recipientId, string toAddress, EmailNotificationResultType result) + private async Task CreateNotificationForRecipient(Guid orderId, DateTime requestedSendTime, EmailRecipient recipient, EmailNotificationResultType result) { var emailNotification = new EmailNotification() { Id = _guid.NewGuid(), OrderId = orderId, RequestedSendTime = requestedSendTime, - ToAddress = toAddress, - RecipientId = string.IsNullOrEmpty(recipientId) ? null : recipientId, + Recipient = recipient, SendResult = new(result, _dateTime.UtcNow()) }; diff --git a/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs b/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs index dd0c267a..dcbbbff8 100644 --- a/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs +++ b/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs @@ -45,8 +45,9 @@ public async Task ProcessOrderRetry(NotificationOrder order) EmailAddressPoint? addressPoint = recipient.AddressInfo.Find(a => a.AddressType == AddressType.Email) as EmailAddressPoint; if (!emailRecipients.Exists(er => - er.RecipientId == (string.IsNullOrEmpty(recipient.RecipientId) ? null : recipient.RecipientId) - && er.ToAddress.Equals(addressPoint?.EmailAddress))) + er.NationalIdentityNumber == recipient.NationalIdentityNumber + && er.OrganisationNumber == recipient.OrganisationNumber + && er.ToAddress == addressPoint?.EmailAddress)) { await _emailService.CreateNotification(order.Id, order.RequestedSendTime, recipient); } diff --git a/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs b/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs index 7ee71fb3..3e7662e8 100644 --- a/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs +++ b/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs @@ -4,6 +4,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.Interfaces; @@ -44,13 +45,20 @@ public async Task CreateNotification(Guid orderId, DateTime requestedSendTime, R { SmsAddressPoint? addressPoint = recipient.AddressInfo.Find(a => a.AddressType == AddressType.Sms) as SmsAddressPoint; + SmsRecipient smsRecipient = new() + { + OrganisationNumber = recipient.OrganisationNumber, + NationalIdentityNumber = recipient.NationalIdentityNumber, + MobileNumber = addressPoint?.MobileNumber ?? string.Empty + }; + if (!string.IsNullOrEmpty(addressPoint?.MobileNumber)) { - await CreateNotificationForRecipient(orderId, requestedSendTime, recipient.RecipientId, addressPoint!.MobileNumber, SmsNotificationResultType.New, smsCount); + await CreateNotificationForRecipient(orderId, requestedSendTime, smsRecipient, SmsNotificationResultType.New, smsCount); } else { - await CreateNotificationForRecipient(orderId, requestedSendTime, recipient.RecipientId, string.Empty, SmsNotificationResultType.Failed_RecipientNotIdentified); + await CreateNotificationForRecipient(orderId, requestedSendTime, smsRecipient, SmsNotificationResultType.Failed_RecipientNotIdentified); } } @@ -75,15 +83,14 @@ public async Task UpdateSendStatus(SmsSendOperationResult sendOperationResult) await _repository.UpdateSendStatus(sendOperationResult.NotificationId, sendOperationResult.SendResult, sendOperationResult.GatewayReference); } - private async Task CreateNotificationForRecipient(Guid orderId, DateTime requestedSendTime, string recipientId, string recipientNumber, SmsNotificationResultType type, int smsCount = 0) + private async Task CreateNotificationForRecipient(Guid orderId, DateTime requestedSendTime, SmsRecipient recipient, SmsNotificationResultType type, int smsCount = 0) { var smsNotification = new SmsNotification() { Id = _guid.NewGuid(), OrderId = orderId, RequestedSendTime = requestedSendTime, - RecipientNumber = recipientNumber, - RecipientId = string.IsNullOrEmpty(recipientId) ? null : recipientId, + Recipient = recipient, SendResult = new(type, _dateTime.UtcNow()) }; diff --git a/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs b/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs index ab72874c..072ca943 100644 --- a/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs +++ b/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs @@ -50,8 +50,9 @@ public async Task ProcessOrderRetry(NotificationOrder order) SmsAddressPoint? addressPoint = recipient.AddressInfo.Find(a => a.AddressType == AddressType.Sms) as SmsAddressPoint; if (!smsRecipients.Exists(sr => - sr.RecipientId == (string.IsNullOrEmpty(recipient.RecipientId) ? null : recipient.RecipientId) - && sr.MobileNumber.Equals(addressPoint?.MobileNumber))) + sr.NationalIdentityNumber == recipient.NationalIdentityNumber + && sr.OrganisationNumber == recipient.OrganisationNumber + && sr.MobileNumber == addressPoint?.MobileNumber)) { await _smsService.CreateNotification(order.Id, order.RequestedSendTime, recipient, smsCount); } diff --git a/src/Altinn.Notifications.Persistence/Migration/v0.26/01-alter-tables.sql b/src/Altinn.Notifications.Persistence/Migration/v0.26/01-alter-tables.sql new file mode 100644 index 00000000..a7b47af9 --- /dev/null +++ b/src/Altinn.Notifications.Persistence/Migration/v0.26/01-alter-tables.sql @@ -0,0 +1,18 @@ +-- Modify table emailnotifications: Remove the recipientid column +ALTER TABLE notifications.emailnotifications +DROP COLUMN IF EXISTS recipientid; + +-- Modify table smsnotifications: Add new columns recipientorgno and recipientnin +ALTER TABLE notifications.emailnotifications +ADD COLUMN IF NOT EXISTS recipientorgno text, +ADD COLUMN IF NOT EXISTS recipientnin text; + + +-- Modify table smsnotifications: Remove the recipientid column +ALTER TABLE notifications.smsnotifications +DROP COLUMN IF EXISTS recipientid; + +-- Modify table smsnotifications: Add new columns recipientorgno and recipientnin +ALTER TABLE notifications.smsnotifications +ADD COLUMN IF NOT EXISTS recipientorgno text, +ADD COLUMN IF NOT EXISTS recipientnin text; \ No newline at end of file diff --git a/src/Altinn.Notifications.Persistence/Migration/v0.26/02-alter-types.sql b/src/Altinn.Notifications.Persistence/Migration/v0.26/02-alter-types.sql new file mode 100644 index 00000000..15b9153a --- /dev/null +++ b/src/Altinn.Notifications.Persistence/Migration/v0.26/02-alter-types.sql @@ -0,0 +1,3 @@ +ALTER TYPE public.emailnotificationresulttype ADD VALUE IF NOT EXISTS 'Failed_RecipientReserved'; + +ALTER TYPE public.smsnotificationresulttype ADD VALUE IF NOT EXISTS 'Failed_Recipientreserved'; diff --git a/src/Altinn.Notifications.Persistence/Migration/v0.26/03-alter-procedures.sql b/src/Altinn.Notifications.Persistence/Migration/v0.26/03-alter-procedures.sql new file mode 100644 index 00000000..16a16e59 --- /dev/null +++ b/src/Altinn.Notifications.Persistence/Migration/v0.26/03-alter-procedures.sql @@ -0,0 +1,92 @@ +drop procedure if exists notifications.insertemailnotification( +IN _orderid uuid, +IN _alternateid uuid, +IN _recipientid text, +IN _toaddress text, +IN _result text, +IN _resulttime timestamp with time zone, +IN _expirytime timestamp with time zone); + +drop procedure if exists notifications.insertsmsnotification( +IN _orderid uuid, +IN _alternateid uuid, +IN _recipientid text, +IN _mobilenumber text, +IN _result text, +IN _resulttime timestamp with time zone, +IN _expirytime timestamp with time zone); + + +CREATE OR REPLACE PROCEDURE notifications.insertemailnotification( +_orderid uuid, +_alternateid uuid, +_recipientorgno TEXT, +_recipientnin TEXT, +_toaddress TEXT, +_result text, +_resulttime timestamptz, +_expirytime timestamptz) +LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE +__orderid BIGINT := (SELECT _id from notifications.orders + where alternateid = _orderid); +BEGIN + +INSERT INTO notifications.emailnotifications( +_orderid, +alternateid, +recipientorgno, +recipientnin, +toaddress, result, +resulttime, +expirytime) +VALUES ( +__orderid, +_alternateid, +_recipientorgno, +_recipientnin, +_toaddress, +_result::emailnotificationresulttype, +_resulttime, +_expirytime); +END; +$BODY$; + + +CREATE OR REPLACE PROCEDURE notifications.insertsmsnotification( +_orderid uuid, +_alternateid uuid, +_recipientorgno TEXT, +_recipientnin TEXT, +_mobilenumber TEXT, +_result text, +_resulttime timestamptz, +_expirytime timestamptz) +LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE +__orderid BIGINT := (SELECT _id from notifications.orders + where alternateid = _orderid); +BEGIN + +INSERT INTO notifications.smsnotifications( +_orderid, +alternateid, +recipientorgno, +recipientnin, +mobilenumber, +result, +resulttime, +expirytime) +VALUES ( +__orderid, +_alternateid, +_recipientorgno, +_recipientnin, +_mobilenumber, +_result::smsnotificationresulttype, +_resulttime, +_expirytime); +END; +$BODY$; \ No newline at end of file diff --git a/src/Altinn.Notifications.Persistence/Migration/v0.26/04-alter-functions.sql b/src/Altinn.Notifications.Persistence/Migration/v0.26/04-alter-functions.sql new file mode 100644 index 00000000..63638f1a --- /dev/null +++ b/src/Altinn.Notifications.Persistence/Migration/v0.26/04-alter-functions.sql @@ -0,0 +1,103 @@ +CREATE OR REPLACE FUNCTION notifications.getsmsrecipients_v2(_orderid uuid) +RETURNS TABLE( + recipientorgno text, + recipientnin text, + mobilenumber text +) +LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE +__orderid BIGINT := (SELECT _id from notifications.orders + where alternateid = _orderid); +BEGIN +RETURN query + SELECT s.recipientorgno, s.recipientnin, s.mobilenumber + FROM notifications.smsnotifications s + WHERE s._orderid = __orderid; +END; +$BODY$; + +CREATE OR REPLACE FUNCTION notifications.getemailrecipients_v2(_alternateid uuid) +RETURNS TABLE( + recipientorgno text, + recipientnin text, + toaddress text +) +LANGUAGE 'plpgsql' +AS $BODY$ +DECLARE +__orderid BIGINT := (SELECT _id from notifications.orders + where alternateid = _alternateid); +BEGIN +RETURN query + SELECT e.recipientorgno, e.recipientnin, e.toaddress + FROM notifications.emailnotifications e + WHERE e._orderid = __orderid; +END; +$BODY$; + +CREATE OR REPLACE FUNCTION notifications.getsmssummary_v2( + _alternateorderid uuid, + _creatorname text) + RETURNS TABLE( + sendersreference text, + alternateid uuid, + recipientorgno text, + recipientnin text, + mobilenumber text, + result smsnotificationresulttype, + resulttime timestamptz) + LANGUAGE 'plpgsql' +AS $BODY$ + + BEGIN + RETURN QUERY + SELECT o.sendersreference, n.alternateid, n.recipientorgno, n.recipientnin, n.mobilenumber, n.result, n.resulttime + FROM notifications.smsnotifications n + LEFT JOIN notifications.orders o ON n._orderid = o._id + WHERE o.alternateid = _alternateorderid + and o.creatorname = _creatorname; + IF NOT FOUND THEN + RETURN QUERY + SELECT o.sendersreference, NULL::uuid, NULL::text, NULL::text, NULL::text, NULL::smsnotificationresulttype, NULL::timestamptz + FROM notifications.orders o + WHERE o.alternateid = _alternateorderid + and o.creatorname = _creatorname; + END IF; + END; +$BODY$; + +CREATE OR REPLACE FUNCTION notifications.getemailsummary_V2( + _alternateorderid uuid, + _creatorname text) + RETURNS TABLE( + sendersreference text, + alternateid uuid, + recipientorgno text, + recipientnin text, + toaddress text, + result emailnotificationresulttype, + resulttime timestamptz) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 + +AS $BODY$ + + BEGIN + RETURN QUERY + SELECT o.sendersreference, n.alternateid, n.recipientorgno, n.recipientnin, n.toaddress, n.result, n.resulttime + FROM notifications.emailnotifications n + LEFT JOIN notifications.orders o ON n._orderid = o._id + WHERE o.alternateid = _alternateorderid + and o.creatorname = _creatorname; + IF NOT FOUND THEN + RETURN QUERY + SELECT o.sendersreference, NULL::uuid, NULL::text, NULL::text, NULL::text, NULL::emailnotificationresulttype, NULL::timestamptz + FROM notifications.orders o + WHERE o.alternateid = _alternateorderid + and o.creatorname = _creatorname; + END IF; + END; +$BODY$; \ No newline at end of file diff --git a/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs b/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs index 3f0c1142..409d1aab 100644 --- a/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs +++ b/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs @@ -4,8 +4,11 @@ using Altinn.Notifications.Core.Models.Recipients; using Altinn.Notifications.Core.Persistence; using Altinn.Notifications.Persistence.Extensions; + using Microsoft.ApplicationInsights; + using Npgsql; + using NpgsqlTypes; namespace Altinn.Notifications.Persistence.Repository; @@ -18,10 +21,10 @@ public class EmailNotificationRepository : IEmailNotificationRepository private readonly NpgsqlDataSource _dataSource; private readonly TelemetryClient? _telemetryClient; - private const string _insertEmailNotificationSql = "call notifications.insertemailnotification($1, $2, $3, $4, $5, $6)"; // (__orderid, _alternateid, _toaddress, _result, _resulttime, _expirytime) + private const string _insertEmailNotificationSql = "call notifications.insertemailnotification($1, $2, $3, $4, $5, $6, $7, $8)"; // (__orderid, _alternateid, _recipientorgno, _recipientnin, _toaddress, _result, _resulttime, _expirytime) private const string _getEmailNotificationsSql = "select * from notifications.getemails_statusnew_updatestatus()"; private const string _updateEmailStatus = "call notifications.updateemailstatus($1, $2, $3)"; // (_alternateid, _result, _operationid) - private const string _getEmailRecipients = "select * from notifications.getemailrecipients($1)"; // (_orderid) + private const string _getEmailRecipients = "select * from notifications.getemailrecipients_v2($1)"; // (_orderid) /// /// Initializes a new instance of the class. @@ -42,7 +45,9 @@ public async Task AddNotification(EmailNotification notification, DateTime expir pgcom.Parameters.AddWithValue(NpgsqlDbType.Uuid, notification.OrderId); pgcom.Parameters.AddWithValue(NpgsqlDbType.Uuid, notification.Id); - pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, notification.ToAddress); + pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, (object)DBNull.Value); // recipientorgno + pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, (object)DBNull.Value); // recipientnin + pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, notification.Recipient.ToAddress); pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, notification.SendResult.Result.ToString()); pgcom.Parameters.AddWithValue(NpgsqlDbType.TimestampTz, notification.SendResult.ResultTime); pgcom.Parameters.AddWithValue(NpgsqlDbType.TimestampTz, expiry); @@ -105,8 +110,9 @@ public async Task> GetRecipients(Guid orderId) while (await reader.ReadAsync()) { searchResult.Add(new EmailRecipient() - { - RecipientId = reader.GetValue("recipientid"), + { + OrganisationNumber = reader.GetValue("recipientorgno"), + NationalIdentityNumber = reader.GetValue("recipientnin"), ToAddress = reader.GetValue("toaddress") }); } diff --git a/src/Altinn.Notifications.Persistence/Repository/NotificationSummaryRepository.cs b/src/Altinn.Notifications.Persistence/Repository/NotificationSummaryRepository.cs index 5396bab0..fc8d3f58 100644 --- a/src/Altinn.Notifications.Persistence/Repository/NotificationSummaryRepository.cs +++ b/src/Altinn.Notifications.Persistence/Repository/NotificationSummaryRepository.cs @@ -20,8 +20,8 @@ public class NotificationSummaryRepository : INotificationSummaryRepository private readonly NpgsqlDataSource _dataSource; private readonly TelemetryClient? _telemetryClient; - private const string _getEmailNotificationsByOrderIdSql = "select * from notifications.getemailsummary($1, $2)"; // (_alternateorderid, creatorname) - private const string _getSmsNotificationsByOrderIdSql = "select * from notifications.getsmssummary($1, $2)"; // (_alternateorderid, creatorname) + private const string _getEmailNotificationsByOrderIdSql = "select * from notifications.getemailsummary_v2($1, $2)"; // (_alternateorderid, creatorname) + private const string _getSmsNotificationsByOrderIdSql = "select * from notifications.getsmssummary_v2($1, $2)"; // (_alternateorderid, creatorname) /// /// Initializes a new instance of the class. @@ -45,7 +45,8 @@ public NotificationSummaryRepository(NpgsqlDataSource dataSource, TelemetryClien reader.GetValue("alternateid"), new EmailRecipient() { - RecipientId = reader.GetValue("recipientid"), + OrganisationNumber = reader.GetValue("recipientorgno"), + NationalIdentityNumber = reader.GetValue("recipientnin"), ToAddress = reader.GetValue("toaddress") }, new NotificationResult( @@ -75,7 +76,8 @@ public NotificationSummaryRepository(NpgsqlDataSource dataSource, TelemetryClien reader.GetValue("alternateid"), new SmsRecipient() { - RecipientId = reader.GetValue("recipientid"), + OrganisationNumber = reader.GetValue("recipientorgno"), + NationalIdentityNumber = reader.GetValue("recipientnin"), MobileNumber = reader.GetValue("mobilenumber") }, new NotificationResult( diff --git a/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs b/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs index 826b7dab..6167a82b 100644 --- a/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs +++ b/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs @@ -21,9 +21,9 @@ public class SmsNotificationRepository : ISmsNotificationRepository private readonly NpgsqlDataSource _dataSource; private readonly TelemetryClient? _telemetryClient; - private const string _insertSmsNotificationSql = "call notifications.insertsmsnotification($1, $2, $3, $4, $5, $6)"; // (__orderid, _alternateid, _mobilenumber, _result, _resulttime, _expirytime) + private const string _insertSmsNotificationSql = "call notifications.insertsmsnotification($1, $2, $3, $4, $5, $6, $7, $8)"; // (__orderid, _alternateid, _recipientorgno, _recipientnin, _mobilenumber, _result, _resulttime, _expirytime) private const string _getSmsNotificationsSql = "select * from notifications.getsms_statusnew_updatestatus()"; - private const string _getSmsRecipients = "select * from notifications.getsmsrecipients($1)"; // (_orderid) + private const string _getSmsRecipients = "select * from notifications.getsmsrecipients_v2($1)"; // (_orderid) private const string _updateSmsNotificationStatus = @"UPDATE notifications.smsnotifications @@ -51,7 +51,9 @@ public async Task AddNotification(SmsNotification notification, DateTime expiry, pgcom.Parameters.AddWithValue(NpgsqlDbType.Uuid, notification.OrderId); pgcom.Parameters.AddWithValue(NpgsqlDbType.Uuid, notification.Id); - pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, notification.RecipientNumber); + pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, (object)DBNull.Value); // recipientorgno + pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, (object)DBNull.Value); // recipientnin + pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, notification.Recipient.MobileNumber); pgcom.Parameters.AddWithValue(NpgsqlDbType.Text, notification.SendResult.Result.ToString()); pgcom.Parameters.AddWithValue(NpgsqlDbType.TimestampTz, notification.SendResult.ResultTime); pgcom.Parameters.AddWithValue(NpgsqlDbType.TimestampTz, expiry); @@ -74,7 +76,8 @@ public async Task> GetRecipients(Guid orderId) { searchResult.Add(new SmsRecipient() { - RecipientId = reader.GetValue("recipientid"), + OrganisationNumber = reader.GetValue("recipientorgno"), + NationalIdentityNumber = reader.GetValue("recipientnin"), MobileNumber = reader.GetValue("mobilenumber") }); } diff --git a/src/Altinn.Notifications/Mappers/EmailNotificationSummaryMapper.cs b/src/Altinn.Notifications/Mappers/EmailNotificationSummaryMapper.cs index c93f2f2a..0c51ecba 100644 --- a/src/Altinn.Notifications/Mappers/EmailNotificationSummaryMapper.cs +++ b/src/Altinn.Notifications/Mappers/EmailNotificationSummaryMapper.cs @@ -43,6 +43,8 @@ public static EmailNotificationWithResultExt MapToEmailNotificationWithResultExt Succeeded = notification.Succeeded, Recipient = new() { + OrganisationNumber = notification.Recipient.OrganisationNumber, + NationalIdentityNumber = notification.Recipient.NationalIdentityNumber, EmailAddress = notification.Recipient.ToAddress }, SendStatus = new() diff --git a/src/Altinn.Notifications/Mappers/OrderMapper.cs b/src/Altinn.Notifications/Mappers/OrderMapper.cs index a9f599f9..8df7d522 100644 --- a/src/Altinn.Notifications/Mappers/OrderMapper.cs +++ b/src/Altinn.Notifications/Mappers/OrderMapper.cs @@ -1,6 +1,7 @@ using Altinn.Notifications.Core.Enums; using Altinn.Notifications.Core.Models; using Altinn.Notifications.Core.Models.Address; +using Altinn.Notifications.Core.Models.Notification; using Altinn.Notifications.Core.Models.NotificationTemplate; using Altinn.Notifications.Core.Models.Orders; using Altinn.Notifications.Extensions; @@ -23,7 +24,7 @@ public static NotificationOrderRequest MapToOrderRequest(this EmailNotificationO var recipients = new List(); recipients.AddRange( - extRequest.Recipients.Select(r => new Recipient(string.Empty, new List() { new EmailAddressPoint(r.EmailAddress!) }))); + extRequest.Recipients.Select(r => new Recipient(new List() { new EmailAddressPoint(r.EmailAddress!) }))); return new NotificationOrderRequest( extRequest.SendersReference, @@ -44,7 +45,7 @@ public static NotificationOrderRequest MapToOrderRequest(this SmsNotificationOrd List recipients = new(); recipients.AddRange( - extRequest.Recipients.Select(r => new Recipient(string.Empty, new List() { new SmsAddressPoint(r.MobileNumber!) }))); + extRequest.Recipients.Select(r => new Recipient(new List() { new SmsAddressPoint(r.MobileNumber!) }))); return new NotificationOrderRequest( extRequest.SendersReference, @@ -172,6 +173,8 @@ internal static List MapToRecipientExt(this List recipi recipientExt.AddRange( recipients.Select(r => new RecipientExt { + OrganisationNumber = r.OrganisationNumber, + NationalIdentityNumber = r.NationalIdentityNumber, EmailAddress = GetEmailFromAddressList(r.AddressInfo), MobileNumber = GetMobileNumberFromAddressList(r.AddressInfo) })); diff --git a/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs b/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs index 9104fb05..0fc42516 100644 --- a/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs +++ b/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs @@ -43,6 +43,8 @@ public static SmsNotificationWithResultExt MapToSmsNotificationWithResultExt(thi Succeeded = notification.Succeeded, Recipient = new() { + OrganisationNumber = notification.Recipient.OrganisationNumber, + NationalIdentityNumber = notification.Recipient.NationalIdentityNumber, MobileNumber = notification.Recipient.MobileNumber }, SendStatus = new() diff --git a/src/Altinn.Notifications/Models/RecipientExt.cs b/src/Altinn.Notifications/Models/RecipientExt.cs index 826d4446..2ae8d1c3 100644 --- a/src/Altinn.Notifications/Models/RecipientExt.cs +++ b/src/Altinn.Notifications/Models/RecipientExt.cs @@ -21,4 +21,16 @@ public class RecipientExt /// [JsonPropertyName("mobileNumber")] public string? MobileNumber { get; set; } + + /// + /// Gets or sets the organisation number of the recipient + /// + [JsonPropertyName("organisationNumber")] + public string? OrganisationNumber { get; set; } + + /// + /// Gets or sets the national identity number of the recipient + /// + [JsonPropertyName("nationalIdentityNumber")] + public string? NationalIdentityNumber { get; set; } } diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications.Core/SmsNotificationSummaryTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications.Core/SmsNotificationSummaryTests.cs index 4da7c2b6..b63eb665 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications.Core/SmsNotificationSummaryTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications.Core/SmsNotificationSummaryTests.cs @@ -56,7 +56,7 @@ public async Task GetSmsSummary_SingleNeweNotification_ReturnsSummary() Assert.Equal(SmsNotificationResultType.New, actualNotification.ResultStatus.Result); Assert.NotEmpty(actualNotification.Recipient.MobileNumber); Assert.Equal(notification.Id, actualNotification.Id); - Assert.Equivalent(notification.RecipientNumber, actualNotification.Recipient.MobileNumber); + Assert.Equivalent(notification.Recipient, actualNotification.Recipient); return true; }, error => diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs index 546a94f4..7ffe0400 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs @@ -49,8 +49,11 @@ public async Task AddNotification() Id = notificationId, OrderId = orderId, RequestedSendTime = DateTime.UtcNow, - RecipientId = "12345678", - RecipientNumber = "999999999", + Recipient = new() + { + NationalIdentityNumber = "16069412345", + MobileNumber = "999999999" + } }; await repo.AddNotification(smsNotification, DateTime.UtcNow); @@ -93,8 +96,7 @@ public async Task GetRecipients() (NotificationOrder order, SmsNotification smsNotification) = await PostgreUtil.PopulateDBWithOrderAndSmsNotification(); _orderIdsToDelete.Add(order.Id); - string expectedNumber = smsNotification.RecipientNumber; - string? expectedRecipientId = smsNotification.RecipientId; + SmsRecipient expectedRecipient = smsNotification.Recipient; // Act List actual = await repo.GetRecipients(order.Id); @@ -103,8 +105,9 @@ public async Task GetRecipients() // Assert Assert.Single(actual); - Assert.Equal(expectedNumber, actualRecipient.MobileNumber); - Assert.Equal(expectedRecipientId, actualRecipient.RecipientId); + Assert.Equal(expectedRecipient.MobileNumber, actualRecipient.MobileNumber); + Assert.Equal(expectedRecipient.NationalIdentityNumber, actualRecipient.NationalIdentityNumber); + Assert.Equal(expectedRecipient.OrganisationNumber, actualRecipient.OrganisationNumber); } [Fact] diff --git a/test/Altinn.Notifications.IntegrationTests/Utils/TestdataUtil.cs b/test/Altinn.Notifications.IntegrationTests/Utils/TestdataUtil.cs index 683ca98b..3d89995e 100644 --- a/test/Altinn.Notifications.IntegrationTests/Utils/TestdataUtil.cs +++ b/test/Altinn.Notifications.IntegrationTests/Utils/TestdataUtil.cs @@ -21,7 +21,10 @@ public static (NotificationOrder Order, SmsNotification Notification) GetOrderAn Id = Guid.NewGuid(), OrderId = order.Id, RequestedSendTime = order.RequestedSendTime, - RecipientNumber = addressPoint!.MobileNumber, + Recipient = new() + { + MobileNumber = addressPoint!.MobileNumber, + }, SendResult = new(SmsNotificationResultType.New, DateTime.UtcNow) }; @@ -40,7 +43,10 @@ public static (NotificationOrder Order, EmailNotification Notification) GetOrder Id = Guid.NewGuid(), OrderId = order.Id, RequestedSendTime = order.RequestedSendTime, - ToAddress = addressPoint!.EmailAddress, + Recipient = new() + { + ToAddress = addressPoint!.EmailAddress + }, SendResult = new(EmailNotificationResultType.New, DateTime.UtcNow) }; diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs index adda28f8..69f13232 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingModels/NotificationOrderTests.cs @@ -46,7 +46,7 @@ public NotificationOrderTests() { new Recipient() { - RecipientId = "recipient1", + NationalIdentityNumber = "nationalidentitynumber", AddressInfo = new() { new EmailAddressPoint() @@ -92,7 +92,7 @@ public NotificationOrderTests() new JsonObject() { { - "recipientId", "recipient1" + "nationalIdentityNumber", "nationalidentitynumber" }, { "addressInfo", new JsonArray() diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs index 8eb1ce25..374ccd6c 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs @@ -87,10 +87,13 @@ public async Task CreateEmailNotification_ToAddressDefined_ResultNew() { Id = id, OrderId = orderId, - RecipientId = "skd", + Recipient = new() + { + OrganisationNumber = "skd-orgno", + ToAddress = "skd@norge.no" + }, RequestedSendTime = requestedSendTime, - SendResult = new(EmailNotificationResultType.New, dateTimeOutput), - ToAddress = "skd@norge.no" + SendResult = new(EmailNotificationResultType.New, dateTimeOutput) }; var repoMock = new Mock(); @@ -99,7 +102,7 @@ public async Task CreateEmailNotification_ToAddressDefined_ResultNew() var service = GetTestService(repo: repoMock.Object, guidOutput: id, dateTimeOutput: dateTimeOutput); // Act - await service.CreateNotification(orderId, requestedSendTime, new Recipient("skd", new List() { new EmailAddressPoint("skd@norge.no") })); + await service.CreateNotification(orderId, requestedSendTime, new Recipient(new List() { new EmailAddressPoint("skd@norge.no") }, organisationNumber: "skd-orgno")); // Assert repoMock.Verify(r => r.AddNotification(It.Is(e => AssertUtils.AreEquivalent(expected, e)), It.Is(d => d == expectedExpiry)), Times.Once); @@ -119,7 +122,10 @@ public async Task CreateEmailNotification_ToAddressMissing_ResultFailedRecipient { Id = id, OrderId = orderId, - RecipientId = "skd", + Recipient = new() + { + OrganisationNumber = "skd-orgno" + }, RequestedSendTime = requestedSendTime, SendResult = new(EmailNotificationResultType.Failed_RecipientNotIdentified, dateTimeOutput), }; @@ -130,7 +136,7 @@ public async Task CreateEmailNotification_ToAddressMissing_ResultFailedRecipient var service = GetTestService(repo: repoMock.Object, guidOutput: id, dateTimeOutput: dateTimeOutput); // Act - await service.CreateNotification(orderId, requestedSendTime, new Recipient("skd", new List())); + await service.CreateNotification(orderId, requestedSendTime, new Recipient(new List(), organisationNumber: "skd-orgno")); // Assert repoMock.Verify(); diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailOrderProcessingServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailOrderProcessingServiceTests.cs index 0a5364bf..6df242e6 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailOrderProcessingServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailOrderProcessingServiceTests.cs @@ -60,11 +60,11 @@ public async Task ProcessOrder_ExpectedInputToService() RequestedSendTime = requested, Recipients = new List() { - new Recipient("skd", new List() { new EmailAddressPoint("test@test.com") }) + new(new List() { new EmailAddressPoint("test@test.com") }, organisationNumber: "skd-orgno") } }; - Recipient expectedRecipient = new("skd", new List() { new EmailAddressPoint("test@test.com") }); + Recipient expectedRecipient = new(new List() { new EmailAddressPoint("test@test.com") }, organisationNumber: "skd-orgno"); var serviceMock = new Mock(); serviceMock.Setup(s => s.CreateNotification(It.IsAny(), It.Is(d => d.Equals(requested)), It.Is(r => AssertUtils.AreEquivalent(expectedRecipient, r)))); @@ -87,7 +87,7 @@ public async Task ProcessOrder_ServiceThrowsException_RepositoryNotCalled() NotificationChannel = NotificationChannel.Email, Recipients = new List() { - new Recipient() + new() } }; @@ -118,9 +118,10 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() NotificationChannel = NotificationChannel.Email, Recipients = new List() { - new Recipient(), - new Recipient("skd", new List() { new EmailAddressPoint("test@test.com") }), - new Recipient(new List() { new EmailAddressPoint("test@domain.com") }) + new(), + new(new List() { new EmailAddressPoint("test@test.com") }, nationalIdentityNumber: "enduser-nin"), + new(new List() { new EmailAddressPoint("test@test.com") }, organisationNumber : "skd-orgNo"), + new(new List() { new EmailAddressPoint("test@domain.com") }) } }; @@ -128,7 +129,11 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() serviceMock.Setup(s => s.CreateNotification(It.IsAny(), It.IsAny(), It.IsAny())); var emailRepoMock = new Mock(); - emailRepoMock.Setup(e => e.GetRecipients(It.IsAny())).ReturnsAsync(new List() { new EmailRecipient() { RecipientId = "skd", ToAddress = "test@test.com" } }); + emailRepoMock.Setup(e => e.GetRecipients(It.IsAny())).ReturnsAsync(new List() + { + new() { OrganisationNumber = "skd-orgNo", ToAddress = "test@test.com" }, + new() { NationalIdentityNumber = "enduser-nin", ToAddress = "test@test.com" } + }); var service = GetTestService(emailRepo: emailRepoMock.Object, emailService: serviceMock.Object); @@ -136,8 +141,8 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() await service.ProcessOrderRetry(order); // Assert - serviceMock.Verify(s => s.CreateNotification(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); emailRepoMock.Verify(e => e.GetRecipients(It.IsAny()), Times.Once); + serviceMock.Verify(s => s.CreateNotification(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); } private static EmailOrderProcessingService GetTestService( diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs index 3ed63410..9f493e9e 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsNotificationServiceTests.cs @@ -43,7 +43,7 @@ public async Task CreateNotifications_NewSmsNotification_RepositoryCalledOnce() var service = GetTestService(repo: repoMock.Object); // Act - await service.CreateNotification(Guid.NewGuid(), DateTime.UtcNow, new Recipient("recipientId", new List() { new SmsAddressPoint("999999999") })); + await service.CreateNotification(Guid.NewGuid(), DateTime.UtcNow, new Recipient(new List() { new SmsAddressPoint("999999999") }, nationalIdentityNumber: "enduser-nin")); // Assert repoMock.Verify(r => r.AddNotification(It.IsAny(), It.IsAny()), Times.Once); @@ -64,7 +64,10 @@ public async Task CreateNotification_RecipientNumberIsDefined_ResultNew() Id = id, OrderId = orderId, RequestedSendTime = requestedSendTime, - RecipientNumber = "+4799999999", + Recipient = new() + { + MobileNumber = "+4799999999" + }, SendResult = new(SmsNotificationResultType.New, dateTimeOutput), }; diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs index 40127650..00873f8d 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs @@ -33,15 +33,15 @@ public async Task ProcessOrder_ExpectedInputToService() RequestedSendTime = requested, Recipients = new List() { - new Recipient("end-user", new List() { new SmsAddressPoint("+4799999999") }) + new Recipient(new List() { new SmsAddressPoint("+4799999999") }, nationalIdentityNumber: "enduser-nin") } }; - Recipient expectedRecipient = new("end-user", new List() { new SmsAddressPoint("+4799999999") }); + Recipient expectedRecipient = new(new List() { new SmsAddressPoint("+4799999999") }, nationalIdentityNumber: "enduser-nin"); var serviceMock = new Mock(); serviceMock.Setup(s => s.CreateNotification(It.IsAny(), It.Is(d => d.Equals(requested)), It.Is(r => AssertUtils.AreEquivalent(expectedRecipient, r)))); - + var service = GetTestService(smsService: serviceMock.Object); // Act @@ -89,7 +89,8 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() Recipients = new List() { new Recipient(), - new Recipient("end-user", new List() { new SmsAddressPoint("+4799999999") }), + new Recipient(new List() { new SmsAddressPoint("+4799999999") }, nationalIdentityNumber: "enduser-nin"), + new Recipient(new List() { new SmsAddressPoint("+4799999999") }, organisationNumber: "skd-orgNo"), new Recipient(new List() { new SmsAddressPoint("+4749999999") }) } }; @@ -98,7 +99,12 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() serviceMock.Setup(s => s.CreateNotification(It.IsAny(), It.IsAny(), It.IsAny())); var smsRepoMock = new Mock(); - smsRepoMock.Setup(e => e.GetRecipients(It.IsAny())).ReturnsAsync(new List() { new SmsRecipient() { RecipientId = "end-user", MobileNumber = "+4799999999" } }); + smsRepoMock.Setup(e => e.GetRecipients(It.IsAny())).ReturnsAsync( + new List() + { + new SmsRecipient() { NationalIdentityNumber = "enduser-nin", MobileNumber = "+4799999999" }, + new SmsRecipient() { OrganisationNumber = "skd-orgNo", MobileNumber = "+4799999999" } + }); var service = GetTestService(smsRepo: smsRepoMock.Object, smsService: serviceMock.Object); diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs index 6ef64a39..5d54b292 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs @@ -37,6 +37,7 @@ public void MapToEmailNotificationWithResultExt_NotificationWithFailedResult_Are Succeeded = false, Recipient = new() { + NationalIdentityNumber = "16069412345", EmailAddress = "recipient@domain.com" }, SendStatus = new() @@ -52,7 +53,7 @@ public void MapToEmailNotificationWithResultExt_NotificationWithFailedResult_Are false, new EmailRecipient() { - RecipientId = "12345678910", + NationalIdentityNumber = "16069412345", ToAddress = "recipient@domain.com" }, new NotificationResult( @@ -80,6 +81,7 @@ public void MapToEmailNotificationWithResultExt_NotificationWithSuccessResult_Ar Succeeded = true, Recipient = new() { + OrganisationNumber = "12345678910", EmailAddress = "recipient@domain.com" }, SendStatus = new() @@ -95,7 +97,7 @@ public void MapToEmailNotificationWithResultExt_NotificationWithSuccessResult_Ar true, new EmailRecipient() { - RecipientId = "12345678910", + OrganisationNumber = "12345678910", ToAddress = "recipient@domain.com" }, new NotificationResult( diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs index aad67f8a..232b8aed 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/OrderMapperTests.cs @@ -84,7 +84,7 @@ public void MapToRecipientExt_AllPropertiesPresent_AreEquivalent() // Arrange Recipient input = new() { - RecipientId = "16069412345", + NationalIdentityNumber = "16069412345", AddressInfo = new List() { new EmailAddressPoint("input@domain.com"), @@ -94,6 +94,7 @@ public void MapToRecipientExt_AllPropertiesPresent_AreEquivalent() RecipientExt expected = new() { + NationalIdentityNumber = "16069412345", EmailAddress = "input@domain.com", MobileNumber = "+4740000001" }; diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs index 0d248d16..60b1eff5 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs @@ -37,6 +37,7 @@ public void MapToSmsNotificationWithResultExt_NotificationWithFailedResult_AreEq Succeeded = false, Recipient = new() { + OrganisationNumber = "12345678910", MobileNumber = "+4799999999" }, SendStatus = new() @@ -52,7 +53,7 @@ public void MapToSmsNotificationWithResultExt_NotificationWithFailedResult_AreEq false, new SmsRecipient() { - RecipientId = "12345678910", + OrganisationNumber = "12345678910", MobileNumber = "+4799999999" }, new NotificationResult( @@ -80,6 +81,7 @@ public void MapToSmsNotificationWithResultExt_NotificationWithSuccessResult_AreE Succeeded = true, Recipient = new() { + NationalIdentityNumber = "16069412345", MobileNumber = "+4799999999" }, SendStatus = new() @@ -95,7 +97,7 @@ public void MapToSmsNotificationWithResultExt_NotificationWithSuccessResult_AreE true, new SmsRecipient() { - RecipientId = "12345678910", + NationalIdentityNumber = "16069412345", MobileNumber = "+4799999999" }, new NotificationResult(