From c7e2b010036f1eb2a3e7616cdeb0ce41226c55f3 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 24 Apr 2024 12:23:19 +0200 Subject: [PATCH 01/11] possible to order notification for org --- .../Integrations/IRegisterClient.cs | 17 ++++ .../OrganizationContactPoints.cs | 22 +++++ .../Metrics/MonthlyNotificationMetrics.cs | 2 +- .../Models/Recipient.cs | 8 +- .../Models/Recipients/EmailRecipient.cs | 4 +- .../Models/Recipients/SmsRecipient.cs | 4 +- .../Services/ContactPointService.cs | 90 +++++++++++-------- .../Services/EmailNotificationService.cs | 2 +- .../Services/EmailOrderProcessingService.cs | 2 +- .../Interfaces/IContactPointService.cs | 12 +-- .../Services/OrderRequestService.cs | 2 +- .../Services/SmsNotificationService.cs | 2 +- .../Services/SmsOrderProcessingService.cs | 2 +- .../Configuration/PlatformSettings.cs | 7 +- .../Extensions/ServiceCollectionExtensions.cs | 7 +- .../Register/OrgContactPointLookup.cs | 16 ++++ .../Register/OrgContactPointsList.cs | 15 ++++ .../Register/RegisterClient.cs | 52 +++++++++++ .../Repository/EmailNotificationRepository.cs | 2 +- .../NotificationSummaryRepository.cs | 4 +- .../Repository/SmsNotificationRepository.cs | 2 +- .../Mappers/EmailNotificationSummaryMapper.cs | 2 +- .../Mappers/OrderMapper.cs | 6 +- .../Mappers/SmsNotificationSummaryMapper.cs | 2 +- .../Models/RecipientExt.cs | 6 +- .../EmailNotificationOrderRequestValidator.cs | 4 +- .../SmsNotificationOrderRequestValidator.cs | 4 +- src/Altinn.Notifications/appsettings.json | 4 +- .../EmailNotificationRepositoryTests.cs | 2 +- .../SmsNotificationRepositoryTests.cs | 2 +- .../OrdersController/OrdersControllerTests.cs | 1 - .../ContactPointServiceTests.cs | 44 ++------- .../EmailNotificationServiceTests.cs | 8 +- .../EmailOrderProcessingServiceTests.cs | 12 +-- .../SmsOrderProcessingServiceTests.cs | 8 +- .../EmailNotificationSummaryMapperTests.cs | 4 +- .../SmsNotificationSummaryMapperTests.cs | 4 +- ...lNotificationOrderRequestValidatorTests.cs | 4 +- ...sNotificationOrderRequestValidatorTests.cs | 4 +- 39 files changed, 251 insertions(+), 144 deletions(-) create mode 100644 src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs create mode 100644 src/Altinn.Notifications.Core/Models/ContactPoints/OrganizationContactPoints.cs create mode 100644 src/Altinn.Notifications.Integrations/Register/OrgContactPointLookup.cs create mode 100644 src/Altinn.Notifications.Integrations/Register/OrgContactPointsList.cs create mode 100644 src/Altinn.Notifications.Integrations/Register/RegisterClient.cs diff --git a/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs b/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs new file mode 100644 index 00000000..41e6f022 --- /dev/null +++ b/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs @@ -0,0 +1,17 @@ +using Altinn.Notifications.Core.Models.ContactPoints; + +namespace Altinn.Notifications.Core.Integrations +{ + /// + /// Interface describing a client for the register service + /// + public interface IRegisterClient + { + /// + /// Retrieves contact points for a list of organizations + /// + /// A list of organization numbers to look up contact points for + /// A list of for the provided organizations + public Task> GeOrganizationContactPoints(List organizationNumbers); + } +} diff --git a/src/Altinn.Notifications.Core/Models/ContactPoints/OrganizationContactPoints.cs b/src/Altinn.Notifications.Core/Models/ContactPoints/OrganizationContactPoints.cs new file mode 100644 index 00000000..a95d8cf3 --- /dev/null +++ b/src/Altinn.Notifications.Core/Models/ContactPoints/OrganizationContactPoints.cs @@ -0,0 +1,22 @@ +namespace Altinn.Notifications.Core.Models.ContactPoints; + +/// +/// Class describing the contact points for an organization +/// +public class OrganizationContactPoints +{ + /// + /// Gets or sets the organization number for the organization + /// + public string OrganizationNumber { get; set; } = string.Empty; + + /// + /// Gets or sets a list of official mobile numbers + /// + public List MobileNumberList { get; set; } = []; + + /// + /// Gets or sets a list of official email addresses + /// + public List EmailList { get; set; } = []; +} diff --git a/src/Altinn.Notifications.Core/Models/Metrics/MonthlyNotificationMetrics.cs b/src/Altinn.Notifications.Core/Models/Metrics/MonthlyNotificationMetrics.cs index af6b8bd9..d9af7009 100644 --- a/src/Altinn.Notifications.Core/Models/Metrics/MonthlyNotificationMetrics.cs +++ b/src/Altinn.Notifications.Core/Models/Metrics/MonthlyNotificationMetrics.cs @@ -16,7 +16,7 @@ public class MonthlyNotificationMetrics public int Year { get; set; } /// - /// A list of metrics per organisation + /// A list of metrics per organization /// public List Metrics { get; set; } = []; } diff --git a/src/Altinn.Notifications.Core/Models/Recipient.cs b/src/Altinn.Notifications.Core/Models/Recipient.cs index ed1db806..1fc089dd 100644 --- a/src/Altinn.Notifications.Core/Models/Recipient.cs +++ b/src/Altinn.Notifications.Core/Models/Recipient.cs @@ -10,9 +10,9 @@ namespace Altinn.Notifications.Core.Models; public class Recipient { /// - /// Gets the recipient's organisation number + /// Gets the recipient's organization number /// - public string? OrganisationNumber { get; set; } = null; + public string? OrganizationNumber { get; set; } = null; /// /// Gets the recipient's national identity number @@ -32,9 +32,9 @@ public class Recipient /// /// Initializes a new instance of the class. /// - public Recipient(List addressInfo, string? organisationNumber = null, string? nationalIdentityNumber = null) + public Recipient(List addressInfo, string? organizationNumber = null, string? nationalIdentityNumber = null) { - OrganisationNumber = organisationNumber; + OrganizationNumber = organizationNumber; 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 444489fb..bb99c76c 100644 --- a/src/Altinn.Notifications.Core/Models/Recipients/EmailRecipient.cs +++ b/src/Altinn.Notifications.Core/Models/Recipients/EmailRecipient.cs @@ -6,9 +6,9 @@ namespace Altinn.Notifications.Core.Models.Recipients; public class EmailRecipient { /// - /// Gets or sets the recipient's organisation number + /// Gets or sets the recipient's organization number /// - public string? OrganisationNumber { get; set; } = null; + public string? OrganizationNumber { get; set; } = null; /// /// Gets or sets the recipient's national identity number diff --git a/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs b/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs index b547ca98..70e7cf60 100644 --- a/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs +++ b/src/Altinn.Notifications.Core/Models/Recipients/SmsRecipient.cs @@ -6,9 +6,9 @@ namespace Altinn.Notifications.Core.Models.Recipients; public class SmsRecipient { /// - /// Gets or sets the recipient's organisation number + /// Gets or sets the recipient's organization number /// - public string? OrganisationNumber { get; set; } = null; + public string? OrganizationNumber { get; set; } = null; /// /// Gets or sets the recipient's national identity number diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index dfb19be9..578c9dc2 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -12,13 +12,15 @@ namespace Altinn.Notifications.Core.Services public class ContactPointService : IContactPointService { private readonly IProfileClient _profileClient; + private readonly IRegisterClient _registerClient; /// /// Initializes a new instance of the class. /// - public ContactPointService(IProfileClient profile) + public ContactPointService(IProfileClient profile, IRegisterClient register) { _profileClient = profile; + _registerClient = register; } /// @@ -30,6 +32,11 @@ await AugmentRecipients( { recipient.AddressInfo.Add(new EmailAddressPoint(userContactPoints.Email)); return recipient; + }, + (recipient, orgContactPoints) => + { + recipient.AddressInfo.AddRange(orgContactPoints.EmailList.Select(e => new EmailAddressPoint(e)).ToList()); + return recipient; }); } @@ -42,20 +49,28 @@ await AugmentRecipients( { recipient.AddressInfo.Add(new SmsAddressPoint(userContactPoints.MobileNumber)); return recipient; + }, + (recipient, orgContactPoints) => + { + recipient.AddressInfo.AddRange(orgContactPoints.MobileNumberList.Select(m => new SmsAddressPoint(m)).ToList()); + return recipient; }); } - /// - public async Task> GetContactPointAvailability(List recipients) - { - return await LookupContactPointAvailability(recipients); - } - - private async Task> AugmentRecipients(List recipients, Func createContactPoint) + private async Task> AugmentRecipients( + List recipients, + Func createUserContactPoint, + Func createOrgContactPoint) { List augmentedRecipients = []; - List userContactPointsList = await LookupContactPoints(recipients); + var userLookupTask = LookupUserContactPoints(recipients); + var orgLookupTask = LookupOrganizationContactPoints(recipients); + await Task.WhenAll(userLookupTask, orgLookupTask); + + List userContactPointsList = userLookupTask.Result; + List organizationContactPointList = orgLookupTask.Result; + foreach (Recipient recipient in recipients) { if (!string.IsNullOrEmpty(recipient.NationalIdentityNumber)) @@ -66,7 +81,17 @@ private async Task> AugmentRecipients(List recipients if (userContactPoints != null) { recipient.IsReserved = userContactPoints.IsReserved; - augmentedRecipients.Add(createContactPoint(recipient, userContactPoints)); + augmentedRecipients.Add(createUserContactPoint(recipient, userContactPoints)); + } + } + else if (!string.IsNullOrEmpty(recipient.OrganizationNumber)) + { + OrganizationContactPoints? organizationContactPoints = organizationContactPointList! + .Find(o => o.OrganizationNumber == recipient.OrganizationNumber); + + if (organizationContactPoints != null) + { + augmentedRecipients.Add(createOrgContactPoint(recipient, organizationContactPoints)); } } } @@ -74,43 +99,32 @@ private async Task> AugmentRecipients(List recipients return augmentedRecipients; } - private async Task> LookupContactPoints(List recipients) + private async Task> LookupUserContactPoints(List recipients) { - List userContactPoints = new(); List nins = recipients .Where(r => !string.IsNullOrEmpty(r.NationalIdentityNumber)) .Select(r => r.NationalIdentityNumber!) .ToList(); - Task> ninLookupTask = nins.Count > 0 - ? _profileClient.GetUserContactPoints(nins) - : Task.FromResult(new List()); - - await Task.WhenAll(ninLookupTask); - - userContactPoints.AddRange(ninLookupTask.Result); - - return userContactPoints; + // TODO: ensure all mobile numbers have country code before returning + return nins.Count > 0 + ? await _profileClient.GetUserContactPoints(nins) + : new List(); } - private async Task> LookupContactPointAvailability(List recipients) + private async Task> LookupOrganizationContactPoints(List recipients) { - List contactPointAvailabilityList = new(); - - List nins = recipients - .Where(r => !string.IsNullOrEmpty(r.NationalIdentityNumber)) - .Select(r => r.NationalIdentityNumber!) - .ToList(); - - Task> ninLookupTask = nins.Count > 0 - ? _profileClient.GetUserContactPointAvailabilities(nins) - : Task.FromResult(new List()); - - await Task.WhenAll(ninLookupTask); - - contactPointAvailabilityList.AddRange(ninLookupTask.Result); - - return contactPointAvailabilityList; + /* the output from this function should include an AUHTORIZED list of user registered contact points if notification has a service affiliation + will require the extension of the OrganizationContactPoints class */ + List orgNos = recipients + .Where(r => !string.IsNullOrEmpty(r.OrganizationNumber)) + .Select(r => r.OrganizationNumber!) + .ToList(); + + // TODO: ensure all mobile numbers have country code before returning + return orgNos.Count > 0 + ? await _registerClient.GeOrganizationContactPoints(orgNos) + : new List(); } } } diff --git a/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs b/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs index 0de9d83b..31887656 100644 --- a/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs +++ b/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs @@ -47,7 +47,7 @@ public async Task CreateNotification(Guid orderId, DateTime requestedSendTime, R EmailRecipient emailRecipient = new() { - OrganisationNumber = recipient.OrganisationNumber, + OrganizationNumber = recipient.OrganizationNumber, NationalIdentityNumber = recipient.NationalIdentityNumber, ToAddress = addressPoint?.EmailAddress ?? string.Empty, IsReserved = recipient.IsReserved diff --git a/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs b/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs index 2ef27d34..1bf2b64a 100644 --- a/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs +++ b/src/Altinn.Notifications.Core/Services/EmailOrderProcessingService.cs @@ -60,7 +60,7 @@ public async Task ProcessOrderRetry(NotificationOrder order) if (!emailRecipients.Exists(er => er.NationalIdentityNumber == recipient.NationalIdentityNumber - && er.OrganisationNumber == recipient.OrganisationNumber + && er.OrganizationNumber == recipient.OrganizationNumber && er.ToAddress == addressPoint?.EmailAddress)) { await _emailService.CreateNotification(order.Id, order.RequestedSendTime, recipient, order.IgnoreReservation); diff --git a/src/Altinn.Notifications.Core/Services/Interfaces/IContactPointService.cs b/src/Altinn.Notifications.Core/Services/Interfaces/IContactPointService.cs index fa3e6701..cc4cea26 100644 --- a/src/Altinn.Notifications.Core/Services/Interfaces/IContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/Interfaces/IContactPointService.cs @@ -1,5 +1,4 @@ using Altinn.Notifications.Core.Models; -using Altinn.Notifications.Core.Models.ContactPoints; namespace Altinn.Notifications.Core.Services.Interfaces { @@ -9,7 +8,7 @@ namespace Altinn.Notifications.Core.Services.Interfaces public interface IContactPointService { /// - /// Looks up and adds the email contact points for recipients based on their national identity number or organisation number + /// Looks up and adds the email contact points for recipients based on their national identity number or organization number /// /// List of recipients to retrieve contact points for /// The list of recipients augumented with email address points where available @@ -17,18 +16,11 @@ public interface IContactPointService public Task AddEmailContactPoints(List recipients); /// - /// Looks up and adds the SMS contact points for recipients based on their national identity number or organisation number + /// Looks up and adds the SMS contact points for recipients based on their national identity number or organization number /// /// List of recipients to retrieve contact points for /// The list of recipients augumented with SMS address points where available /// Implementation alters the recipient reference object directly public Task AddSmsContactPoints(List recipients); - - /// - /// Retrieves the availabililty of contact points for the provided recipient based on their national identity number or organisation number - /// - /// List of recipients to check contact point availability for - /// The list of recipients with contact point availability details - public Task> GetContactPointAvailability(List recipients); } } diff --git a/src/Altinn.Notifications.Core/Services/OrderRequestService.cs b/src/Altinn.Notifications.Core/Services/OrderRequestService.cs index b23e664c..552ee4b1 100644 --- a/src/Altinn.Notifications.Core/Services/OrderRequestService.cs +++ b/src/Altinn.Notifications.Core/Services/OrderRequestService.cs @@ -112,7 +112,7 @@ public async Task RegisterNotificationOrder(No .Where(r => channel == NotificationChannel.Email ? !r.AddressInfo.Exists(ap => ap.AddressType == AddressType.Email) : !r.AddressInfo.Exists(ap => ap.AddressType == AddressType.Sms)) - .Select(r => r.OrganisationNumber ?? r.NationalIdentityNumber!) + .Select(r => r.OrganizationNumber ?? r.NationalIdentityNumber!) .Except(isReserved) .ToList() }; diff --git a/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs b/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs index 22607de3..1bde1fb2 100644 --- a/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs +++ b/src/Altinn.Notifications.Core/Services/SmsNotificationService.cs @@ -47,7 +47,7 @@ public async Task CreateNotification(Guid orderId, DateTime requestedSendTime, R SmsRecipient smsRecipient = new() { - OrganisationNumber = recipient.OrganisationNumber, + OrganizationNumber = recipient.OrganizationNumber, NationalIdentityNumber = recipient.NationalIdentityNumber, MobileNumber = addressPoint?.MobileNumber ?? string.Empty, IsReserved = recipient.IsReserved diff --git a/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs b/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs index b6b21009..73e0fe5c 100644 --- a/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs +++ b/src/Altinn.Notifications.Core/Services/SmsOrderProcessingService.cs @@ -63,7 +63,7 @@ public async Task ProcessOrderRetry(NotificationOrder order) if (!smsRecipients.Exists(sr => sr.NationalIdentityNumber == recipient.NationalIdentityNumber - && sr.OrganisationNumber == recipient.OrganisationNumber + && sr.OrganizationNumber == recipient.OrganizationNumber && sr.MobileNumber == addressPoint?.MobileNumber)) { await _smsService.CreateNotification(order.Id, order.RequestedSendTime, recipient, smsCount); diff --git a/src/Altinn.Notifications.Integrations/Configuration/PlatformSettings.cs b/src/Altinn.Notifications.Integrations/Configuration/PlatformSettings.cs index dd15f22d..e6793639 100644 --- a/src/Altinn.Notifications.Integrations/Configuration/PlatformSettings.cs +++ b/src/Altinn.Notifications.Integrations/Configuration/PlatformSettings.cs @@ -6,7 +6,12 @@ public class PlatformSettings { /// - /// Gets or sets the url for the API profile endpoint + /// Gets or sets the url for the profile API /// public string ApiProfileEndpoint { get; set; } = string.Empty; + + /// + /// Gets or sets the url for the register API + /// + public string ApiRegisterEndpoint { get; set; } = string.Empty; } diff --git a/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs b/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs index cade6868..f478642c 100644 --- a/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs +++ b/src/Altinn.Notifications.Integrations/Extensions/ServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using Altinn.Notifications.Integrations.Health; using Altinn.Notifications.Integrations.Kafka.Consumers; using Altinn.Notifications.Integrations.Kafka.Producers; +using Altinn.Notifications.Integrations.Register; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -47,9 +48,9 @@ public static void AddAltinnClients(this IServiceCollection services, IConfigura .Get() ?? throw new ArgumentNullException(nameof(config), "Required PlatformSettings is missing from application configuration"); - services - .Configure(config.GetSection(nameof(PlatformSettings))) - .AddHttpClient(); + services.Configure(config.GetSection(nameof(PlatformSettings))); + services.AddHttpClient(); + services.AddHttpClient(); } /// diff --git a/src/Altinn.Notifications.Integrations/Register/OrgContactPointLookup.cs b/src/Altinn.Notifications.Integrations/Register/OrgContactPointLookup.cs new file mode 100644 index 00000000..15d63776 --- /dev/null +++ b/src/Altinn.Notifications.Integrations/Register/OrgContactPointLookup.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; + +namespace Altinn.Notifications.Integrations.Register +{ + /// + /// A class describing the query model for contact points for organizations + /// + public class OrgContactPointLookup + { + /// + /// Gets or sets the list of organization numbers to lookup contact points for + /// + [JsonPropertyName("organizationNumbers")] + public List OrganizationNumbers { get; set; } = []; + } +} diff --git a/src/Altinn.Notifications.Integrations/Register/OrgContactPointsList.cs b/src/Altinn.Notifications.Integrations/Register/OrgContactPointsList.cs new file mode 100644 index 00000000..bf01db04 --- /dev/null +++ b/src/Altinn.Notifications.Integrations/Register/OrgContactPointsList.cs @@ -0,0 +1,15 @@ +using Altinn.Notifications.Core.Models.ContactPoints; + +namespace Altinn.Notifications.Integrations.Register +{ + /// + /// A list representation of + /// + public class OrgContactPointsList + { + /// + /// A list containing contact points for organizations + /// + public List ContactPointsList { get; set; } = []; + } +} diff --git a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs new file mode 100644 index 00000000..b9f9ba06 --- /dev/null +++ b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs @@ -0,0 +1,52 @@ +using System.Text; +using System.Text.Json; + +using Altinn.Notifications.Core; +using Altinn.Notifications.Core.Integrations; +using Altinn.Notifications.Core.Models.ContactPoints; +using Altinn.Notifications.Core.Shared; +using Altinn.Notifications.Integrations.Configuration; + +using Microsoft.Extensions.Options; + +namespace Altinn.Notifications.Integrations.Register +{ + /// + /// Implementation of the + /// + public class RegisterClient : IRegisterClient + { + private readonly HttpClient _client; + + /// + /// Initializes a new instance of the class. + /// + public RegisterClient(HttpClient client, IOptions settings) + { + _client = client; + _client.BaseAddress = new Uri(settings.Value.ApiRegisterEndpoint); + } + + /// + public async Task> GeOrganizationContactPoints(List organizationNumbers) + { + var lookupObject = new OrgContactPointLookup + { + OrganizationNumbers = organizationNumbers + }; + + HttpContent content = new StringContent(JsonSerializer.Serialize(lookupObject, JsonSerializerOptionsProvider.Options), Encoding.UTF8, "application/json"); + + var response = await _client.PostAsync("organizations/contactpoint/lookup", content); + + if (!response.IsSuccessStatusCode) + { + throw new PlatformHttpException(response, $"RegisterClient.GetUnitContactPoints failed with status code {response.StatusCode}"); + } + + string responseContent = await response.Content.ReadAsStringAsync(); + List? contactPoints = JsonSerializer.Deserialize(responseContent, JsonSerializerOptionsProvider.Options)!.ContactPointsList; + return contactPoints!; + } + } +} diff --git a/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs b/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs index 15c6e354..cb89e94d 100644 --- a/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs +++ b/src/Altinn.Notifications.Persistence/Repository/EmailNotificationRepository.cs @@ -116,7 +116,7 @@ public async Task> GetRecipients(Guid orderId) { searchResult.Add(new EmailRecipient() { - OrganisationNumber = reader.GetValue("recipientorgno"), + OrganizationNumber = 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 fc8d3f58..dc8a84d2 100644 --- a/src/Altinn.Notifications.Persistence/Repository/NotificationSummaryRepository.cs +++ b/src/Altinn.Notifications.Persistence/Repository/NotificationSummaryRepository.cs @@ -45,7 +45,7 @@ public NotificationSummaryRepository(NpgsqlDataSource dataSource, TelemetryClien reader.GetValue("alternateid"), new EmailRecipient() { - OrganisationNumber = reader.GetValue("recipientorgno"), + OrganizationNumber = reader.GetValue("recipientorgno"), NationalIdentityNumber = reader.GetValue("recipientnin"), ToAddress = reader.GetValue("toaddress") }, @@ -76,7 +76,7 @@ public NotificationSummaryRepository(NpgsqlDataSource dataSource, TelemetryClien reader.GetValue("alternateid"), new SmsRecipient() { - OrganisationNumber = reader.GetValue("recipientorgno"), + OrganizationNumber = reader.GetValue("recipientorgno"), NationalIdentityNumber = reader.GetValue("recipientnin"), MobileNumber = reader.GetValue("mobilenumber") }, diff --git a/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs b/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs index 27efc7fc..9d7c47f4 100644 --- a/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs +++ b/src/Altinn.Notifications.Persistence/Repository/SmsNotificationRepository.cs @@ -77,7 +77,7 @@ public async Task> GetRecipients(Guid orderId) { searchResult.Add(new SmsRecipient() { - OrganisationNumber = reader.GetValue("recipientorgno"), + OrganizationNumber = 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 0c51ecba..cc10cc35 100644 --- a/src/Altinn.Notifications/Mappers/EmailNotificationSummaryMapper.cs +++ b/src/Altinn.Notifications/Mappers/EmailNotificationSummaryMapper.cs @@ -43,7 +43,7 @@ public static EmailNotificationWithResultExt MapToEmailNotificationWithResultExt Succeeded = notification.Succeeded, Recipient = new() { - OrganisationNumber = notification.Recipient.OrganisationNumber, + OrganizationNumber = notification.Recipient.OrganizationNumber, NationalIdentityNumber = notification.Recipient.NationalIdentityNumber, EmailAddress = notification.Recipient.ToAddress }, diff --git a/src/Altinn.Notifications/Mappers/OrderMapper.cs b/src/Altinn.Notifications/Mappers/OrderMapper.cs index 16c04ec6..5a6f68a8 100644 --- a/src/Altinn.Notifications/Mappers/OrderMapper.cs +++ b/src/Altinn.Notifications/Mappers/OrderMapper.cs @@ -31,7 +31,7 @@ public static NotificationOrderRequest MapToOrderRequest(this EmailNotificationO addresses.Add(new EmailAddressPoint(r.EmailAddress)); } - return new Recipient(addresses, r.OrganisationNumber, r.NationalIdentityNumber); + return new Recipient(addresses, r.OrganizationNumber, r.NationalIdentityNumber); }) .ToList(); @@ -63,7 +63,7 @@ public static NotificationOrderRequest MapToOrderRequest(this SmsNotificationOrd addresses.Add(new SmsAddressPoint(r.MobileNumber)); } - return new Recipient(addresses, r.OrganisationNumber, r.NationalIdentityNumber); + return new Recipient(addresses, r.OrganizationNumber, r.NationalIdentityNumber); }) .ToList(); @@ -198,7 +198,7 @@ internal static List MapToRecipientExt(this List recipi EmailAddress = GetEmailFromAddressList(r.AddressInfo), MobileNumber = GetMobileNumberFromAddressList(r.AddressInfo), NationalIdentityNumber = r.NationalIdentityNumber, - OrganisationNumber = r.OrganisationNumber, + OrganizationNumber = r.OrganizationNumber, IsReserved = r.IsReserved })); diff --git a/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs b/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs index 0fc42516..97f8f1e3 100644 --- a/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs +++ b/src/Altinn.Notifications/Mappers/SmsNotificationSummaryMapper.cs @@ -43,7 +43,7 @@ public static SmsNotificationWithResultExt MapToSmsNotificationWithResultExt(thi Succeeded = notification.Succeeded, Recipient = new() { - OrganisationNumber = notification.Recipient.OrganisationNumber, + OrganizationNumber = notification.Recipient.OrganizationNumber, NationalIdentityNumber = notification.Recipient.NationalIdentityNumber, MobileNumber = notification.Recipient.MobileNumber }, diff --git a/src/Altinn.Notifications/Models/RecipientExt.cs b/src/Altinn.Notifications/Models/RecipientExt.cs index bac87547..91111f0d 100644 --- a/src/Altinn.Notifications/Models/RecipientExt.cs +++ b/src/Altinn.Notifications/Models/RecipientExt.cs @@ -23,10 +23,10 @@ public class RecipientExt public string? MobileNumber { get; set; } /// - /// Gets or sets the organisation number of the recipient + /// Gets or sets the organization number of the recipient /// - [JsonPropertyName("organisationNumber")] - public string? OrganisationNumber { get; set; } + [JsonPropertyName("organizationNumber")] + public string? OrganizationNumber { get; set; } /// /// Gets or sets the national identity number of the recipient diff --git a/src/Altinn.Notifications/Validators/EmailNotificationOrderRequestValidator.cs b/src/Altinn.Notifications/Validators/EmailNotificationOrderRequestValidator.cs index 445a4313..8552995b 100644 --- a/src/Altinn.Notifications/Validators/EmailNotificationOrderRequestValidator.cs +++ b/src/Altinn.Notifications/Validators/EmailNotificationOrderRequestValidator.cs @@ -23,9 +23,9 @@ public EmailNotificationOrderRequestValidator() { return (!string.IsNullOrWhiteSpace(a.EmailAddress) && IsValidEmail(a.EmailAddress)) || - (!string.IsNullOrWhiteSpace(a.OrganisationNumber) ^ !string.IsNullOrWhiteSpace(a.NationalIdentityNumber)); + (!string.IsNullOrWhiteSpace(a.OrganizationNumber) ^ !string.IsNullOrWhiteSpace(a.NationalIdentityNumber)); })) - .WithMessage("Either a valid email address, organisation number, or national identity number must be provided for each recipient."); + .WithMessage("Either a valid email address, organization number, or national identity number must be provided for each recipient."); RuleFor(order => order.RequestedSendTime) .Must(sendTime => sendTime.Kind != DateTimeKind.Unspecified) diff --git a/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs b/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs index 25a05c1e..9e584153 100644 --- a/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs +++ b/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs @@ -24,9 +24,9 @@ public SmsNotificationOrderRequestValidator() { return (!string.IsNullOrWhiteSpace(a.MobileNumber) && IsValidMobileNumber(a.MobileNumber)) || - (!string.IsNullOrWhiteSpace(a.OrganisationNumber) ^ !string.IsNullOrWhiteSpace(a.NationalIdentityNumber)); + (!string.IsNullOrWhiteSpace(a.OrganizationNumber) ^ !string.IsNullOrWhiteSpace(a.NationalIdentityNumber)); })) - .WithMessage("Either a valid mobile number starting with country code, organisation number, or national identity number must be provided for each recipient."); + .WithMessage("Either a valid mobile number starting with country code, organization number, or national identity number must be provided for each recipient."); RuleFor(order => order.RequestedSendTime) .Must(sendTime => sendTime.Kind != DateTimeKind.Unspecified) diff --git a/src/Altinn.Notifications/appsettings.json b/src/Altinn.Notifications/appsettings.json index 86120c75..71dea0fc 100644 --- a/src/Altinn.Notifications/appsettings.json +++ b/src/Altinn.Notifications/appsettings.json @@ -1,6 +1,8 @@ { "PlatformSettings": { - "ApiProfileEndpoint": "http://localhost:5030/profile/api/v1/" + "ApiProfileEndpoint": "http://localhost:5030/profile/api/v1/", + "ApiRegisterEndpoint": "http://localhost:5020/register/api/v1/" + }, "PostgreSQLSettings": { "MigrationScriptPath": "Migration", diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/EmailNotificationRepositoryTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/EmailNotificationRepositoryTests.cs index 319307bf..b148c8e2 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/EmailNotificationRepositoryTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/EmailNotificationRepositoryTests.cs @@ -108,7 +108,7 @@ public async Task GetRecipients() Assert.Single(actual); Assert.Equal(expectedRecipient.ToAddress, actualRecipient.ToAddress); Assert.Equal(expectedRecipient.NationalIdentityNumber, actualRecipient.NationalIdentityNumber); - Assert.Equal(expectedRecipient.OrganisationNumber, actualRecipient.OrganisationNumber); + Assert.Equal(expectedRecipient.OrganizationNumber, actualRecipient.OrganizationNumber); } [Fact] diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs index fd2426bf..e580ecda 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications.Persistence/SmsNotificationRepositoryTests.cs @@ -107,7 +107,7 @@ public async Task GetRecipients() Assert.Single(actual); Assert.Equal(expectedRecipient.MobileNumber, actualRecipient.MobileNumber); Assert.Equal(expectedRecipient.NationalIdentityNumber, actualRecipient.NationalIdentityNumber); - Assert.Equal(expectedRecipient.OrganisationNumber, actualRecipient.OrganisationNumber); + Assert.Equal(expectedRecipient.OrganizationNumber, actualRecipient.OrganizationNumber); } [Fact] diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/OrdersController/OrdersControllerTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/OrdersController/OrdersControllerTests.cs index eb0ff39d..6340334a 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/OrdersController/OrdersControllerTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/OrdersController/OrdersControllerTests.cs @@ -17,7 +17,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Logging; -using Microsoft.IdentityModel.Protocols.OpenIdConnect; using Moq; diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs index 78055d0e..2bef02de 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs @@ -83,41 +83,7 @@ public async Task AddEmailContactPoints_NationalIdentityNumberAvailable_ProfileS Assert.Equivalent(expectedOutput, input); } - [Fact] - public async Task AddContactPointAvailability_NationalIdentityNUmberAvailable_ProfileServiceCalled() - { - // Arrange - List input = [ - new Recipient() - { - NationalIdentityNumber = "12345678901" - } - ]; - - List expectedOutput = [ - new UserContactPointAvailability() - { - NationalIdentityNumber = "12345678901", - IsReserved = true, - EmailRegistered = true - } - ]; - - var profileClientMock = new Mock(); - profileClientMock - .Setup(p => p.GetUserContactPointAvailabilities(It.Is>(s => s.Contains("12345678901")))) - .ReturnsAsync([new UserContactPointAvailability() { NationalIdentityNumber = "12345678901", EmailRegistered = true, IsReserved = true }]); - - var service = GetTestService(profileClient: profileClientMock.Object); - - // Act - List actual = await service.GetContactPointAvailability(input); - - // Assert - Assert.Equivalent(expectedOutput, actual); - } - - private static ContactPointService GetTestService(IProfileClient? profileClient = null) + private static ContactPointService GetTestService(IProfileClient? profileClient = null, IRegisterClient? registerClient = null) { if (profileClient == null) { @@ -125,7 +91,13 @@ private static ContactPointService GetTestService(IProfileClient? profileClient profileClient = profileClientMock.Object; } - return new ContactPointService(profileClient); + if (registerClient == null) + { + var registerClientMock = new Mock(); + registerClient = registerClientMock.Object; + } + + return new ContactPointService(profileClient, registerClient); } } } diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs index 6e5cf6aa..6124dc3e 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs @@ -89,7 +89,7 @@ public async Task CreateNotification_ToAddressDefined_ResultNew() OrderId = orderId, Recipient = new() { - OrganisationNumber = "skd-orgno", + OrganizationNumber = "skd-orgno", ToAddress = "skd@norge.no" }, RequestedSendTime = requestedSendTime, @@ -102,7 +102,7 @@ public async Task CreateNotification_ToAddressDefined_ResultNew() var service = GetTestService(repo: repoMock.Object, guidOutput: id, dateTimeOutput: dateTimeOutput); // Act - await service.CreateNotification(orderId, requestedSendTime, new Recipient(new List() { new EmailAddressPoint("skd@norge.no") }, organisationNumber: "skd-orgno")); + await service.CreateNotification(orderId, requestedSendTime, new Recipient(new List() { new EmailAddressPoint("skd@norge.no") }, organizationNumber: "skd-orgno")); // Assert repoMock.Verify(r => r.AddNotification(It.Is(e => AssertUtils.AreEquivalent(expected, e)), It.Is(d => d == expectedExpiry)), Times.Once); @@ -193,7 +193,7 @@ public async Task CreateNotification_ToAddressMissing_LookupFails_ResultFailedRe OrderId = orderId, Recipient = new() { - OrganisationNumber = "skd-orgno" + OrganizationNumber = "skd-orgno" }, RequestedSendTime = requestedSendTime, SendResult = new(EmailNotificationResultType.Failed_RecipientNotIdentified, dateTimeOutput), @@ -205,7 +205,7 @@ public async Task CreateNotification_ToAddressMissing_LookupFails_ResultFailedRe var service = GetTestService(repo: repoMock.Object, guidOutput: id, dateTimeOutput: dateTimeOutput); // Act - await service.CreateNotification(orderId, requestedSendTime, new Recipient(new List(), organisationNumber: "skd-orgno")); + await service.CreateNotification(orderId, requestedSendTime, new Recipient(new List(), organizationNumber: "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 952ef016..fa990c1a 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailOrderProcessingServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailOrderProcessingServiceTests.cs @@ -32,12 +32,12 @@ public async Task ProcessOrder_NotificationServiceCalledOnceForEachRecipient() { new() { - OrganisationNumber = "123456", + OrganizationNumber = "123456", AddressInfo = [new EmailAddressPoint("email@test.com")] }, new() { - OrganisationNumber = "654321", + OrganizationNumber = "654321", AddressInfo = [new EmailAddressPoint("email@test.com")] } } @@ -69,11 +69,11 @@ public async Task ProcessOrder_ExpectedInputToNotificationService() RequestedSendTime = requested, Recipients = new List() { - new(new List() { new EmailAddressPoint("test@test.com") }, organisationNumber: "skd-orgno") + new(new List() { new EmailAddressPoint("test@test.com") }, organizationNumber: "skd-orgno") } }; - Recipient expectedRecipient = new(new List() { new EmailAddressPoint("test@test.com") }, organisationNumber: "skd-orgno"); + Recipient expectedRecipient = new(new List() { new EmailAddressPoint("test@test.com") }, organizationNumber: "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)), It.IsAny())); @@ -168,7 +168,7 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() { 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@test.com") }, organizationNumber : "skd-orgNo"), new(new List() { new EmailAddressPoint("test@domain.com") }) } }; @@ -179,7 +179,7 @@ public async Task ProcessOrderRetry_ServiceCalledIfRecipientNotInDatabase() var emailRepoMock = new Mock(); emailRepoMock.Setup(e => e.GetRecipients(It.IsAny())).ReturnsAsync(new List() { - new() { OrganisationNumber = "skd-orgNo", ToAddress = "test@test.com" }, + new() { OrganizationNumber = "skd-orgNo", ToAddress = "test@test.com" }, new() { NationalIdentityNumber = "enduser-nin", ToAddress = "test@test.com" } }); diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs index 4744870d..097e4a7a 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/SmsOrderProcessingServiceTests.cs @@ -67,12 +67,12 @@ public async Task ProcessOrder_NotificationServiceCalledOnceForEachRecipient() { new() { - OrganisationNumber = "123456", + OrganizationNumber = "123456", AddressInfo = [new SmsAddressPoint("+4799999999")] }, new() { - OrganisationNumber = "654321", + OrganizationNumber = "654321", AddressInfo = [new SmsAddressPoint("+4799999999")] } }, @@ -149,7 +149,7 @@ public async Task ProcessOrderRetry_NotificationServiceCalledIfRecipientNotInDat { new Recipient(), 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("+4799999999") }, organizationNumber: "skd-orgNo"), new Recipient(new List() { new SmsAddressPoint("+4749999999") }) }, Templates = [new SmsTemplate("Altinn", "this is the body")] @@ -162,7 +162,7 @@ public async Task ProcessOrderRetry_NotificationServiceCalledIfRecipientNotInDat smsRepoMock.Setup(e => e.GetRecipients(It.IsAny())).ReturnsAsync( [ new SmsRecipient() { NationalIdentityNumber = "enduser-nin", MobileNumber = "+4799999999" }, - new SmsRecipient() { OrganisationNumber = "skd-orgNo", MobileNumber = "+4799999999" } + new SmsRecipient() { OrganizationNumber = "skd-orgNo", MobileNumber = "+4799999999" } ]); var service = GetTestService(smsRepo: smsRepoMock.Object, smsService: notificationServiceMock.Object); diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs index 5d54b292..84c4c32d 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/EmailNotificationSummaryMapperTests.cs @@ -81,7 +81,7 @@ public void MapToEmailNotificationWithResultExt_NotificationWithSuccessResult_Ar Succeeded = true, Recipient = new() { - OrganisationNumber = "12345678910", + OrganizationNumber = "12345678910", EmailAddress = "recipient@domain.com" }, SendStatus = new() @@ -97,7 +97,7 @@ public void MapToEmailNotificationWithResultExt_NotificationWithSuccessResult_Ar true, new EmailRecipient() { - OrganisationNumber = "12345678910", + OrganizationNumber = "12345678910", ToAddress = "recipient@domain.com" }, new NotificationResult( diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs index 60b1eff5..eba5a36e 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingMappers/SmsNotificationSummaryMapperTests.cs @@ -37,7 +37,7 @@ public void MapToSmsNotificationWithResultExt_NotificationWithFailedResult_AreEq Succeeded = false, Recipient = new() { - OrganisationNumber = "12345678910", + OrganizationNumber = "12345678910", MobileNumber = "+4799999999" }, SendStatus = new() @@ -53,7 +53,7 @@ public void MapToSmsNotificationWithResultExt_NotificationWithFailedResult_AreEq false, new SmsRecipient() { - OrganisationNumber = "12345678910", + OrganizationNumber = "12345678910", MobileNumber = "+4799999999" }, new NotificationResult( diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingValidators/EmailNotificationOrderRequestValidatorTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingValidators/EmailNotificationOrderRequestValidatorTests.cs index 4321d176..ab1db755 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingValidators/EmailNotificationOrderRequestValidatorTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingValidators/EmailNotificationOrderRequestValidatorTests.cs @@ -47,7 +47,7 @@ public void Validate_InvalidEmailFormatProvided_ReturnsFalse() var actual = _validator.Validate(order); Assert.False(actual.IsValid); - Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid email address, organisation number, or national identity number must be provided for each recipient.")); + Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid email address, organization number, or national identity number must be provided for each recipient.")); } [Fact] @@ -63,7 +63,7 @@ public void Validate_NoDetailsDefinedForRecipient_ReturnFalse() var actual = _validator.Validate(order); Assert.False(actual.IsValid); - Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid email address, organisation number, or national identity number must be provided for each recipient.")); + Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid email address, organization number, or national identity number must be provided for each recipient.")); } [Fact] diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs index 2f1dc936..51a26bf3 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs @@ -47,7 +47,7 @@ public void Validate_InvalidMobileNumberFormatProvided_ReturnsFalse() var actual = _validator.Validate(order); Assert.False(actual.IsValid); - Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid mobile number starting with country code, organisation number, or national identity number must be provided for each recipient.")); + Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid mobile number starting with country code, organization number, or national identity number must be provided for each recipient.")); } [Fact] @@ -63,7 +63,7 @@ public void Validate_SmsNotDefinedForRecipient_ReturnFalse() var actual = _validator.Validate(order); Assert.False(actual.IsValid); - Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid mobile number starting with country code, organisation number, or national identity number must be provided for each recipient.")); + Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Either a valid mobile number starting with country code, organization number, or national identity number must be provided for each recipient.")); } [Fact] From a19d6669b8ca4a8280ffe039c22c7030f228ce43 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 24 Apr 2024 13:23:54 +0200 Subject: [PATCH 02/11] added register client test --- .../Integrations/IProfileClient.cs | 7 - .../Integrations/IRegisterClient.cs | 2 +- .../UserContactPointAvailability.cs | 32 ----- .../Services/ContactPointService.cs | 2 +- .../Profile/ProfileClient.cs | 22 ---- .../UserContactPointAvailabilityList.cs | 14 -- .../Register/RegisterClient.cs | 4 +- .../Profile/ProfileClientTests.cs | 79 +----------- .../Register/RegisterClientTests.cs | 121 ++++++++++++++++++ 9 files changed, 132 insertions(+), 151 deletions(-) delete mode 100644 src/Altinn.Notifications.Core/Models/ContactPoints/UserContactPointAvailability.cs delete mode 100644 src/Altinn.Notifications.Integrations/Profile/UserContactPointAvailabilityList.cs create mode 100644 test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs diff --git a/src/Altinn.Notifications.Core/Integrations/IProfileClient.cs b/src/Altinn.Notifications.Core/Integrations/IProfileClient.cs index 0ad923ac..4996c5d5 100644 --- a/src/Altinn.Notifications.Core/Integrations/IProfileClient.cs +++ b/src/Altinn.Notifications.Core/Integrations/IProfileClient.cs @@ -13,11 +13,4 @@ public interface IProfileClient /// A list of national identity numbers to look up contact points for /// A list of contact points for the provided national identity numbers public Task> GetUserContactPoints(List nationalIdentityNumbers); - - /// - /// Retrieves contact point availability for a list of users corresponding to a list of national identity numbers - /// - /// A list of national identity numbers to look up contact point availability for - /// A list of for the provided national identity numbers - public Task> GetUserContactPointAvailabilities(List nationalIdentityNumbers); } diff --git a/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs b/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs index 41e6f022..44135b33 100644 --- a/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs +++ b/src/Altinn.Notifications.Core/Integrations/IRegisterClient.cs @@ -12,6 +12,6 @@ public interface IRegisterClient /// /// A list of organization numbers to look up contact points for /// A list of for the provided organizations - public Task> GeOrganizationContactPoints(List organizationNumbers); + public Task> GetOrganizationContactPoints(List organizationNumbers); } } diff --git a/src/Altinn.Notifications.Core/Models/ContactPoints/UserContactPointAvailability.cs b/src/Altinn.Notifications.Core/Models/ContactPoints/UserContactPointAvailability.cs deleted file mode 100644 index 020e83c3..00000000 --- a/src/Altinn.Notifications.Core/Models/ContactPoints/UserContactPointAvailability.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Altinn.Notifications.Core.Models.ContactPoints; - -/// -/// Class describing the contact points of a user -/// -public class UserContactPointAvailability -{ - /// - /// Gets or sets the ID of the user - /// - public int UserId { get; set; } - - /// - /// Gets or sets the national identityt number of the user - /// - public string NationalIdentityNumber { get; set; } = string.Empty; - - /// - /// Gets or sets a boolean indicating whether the user has reserved themselves from electronic communication - /// - public bool IsReserved { get; set; } - - /// - /// Gets or sets a boolean indicating whether the user has registered a mobile number - /// - public bool MobileNumberRegistered { get; set; } - - /// - /// Gets or sets a boolean indicating whether the user has registered an email address - /// - public bool EmailRegistered { get; set; } -} diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index 578c9dc2..f8217d1a 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -123,7 +123,7 @@ will require the extension of the OrganizationContactPoints class */ // TODO: ensure all mobile numbers have country code before returning return orgNos.Count > 0 - ? await _registerClient.GeOrganizationContactPoints(orgNos) + ? await _registerClient.GetOrganizationContactPoints(orgNos) : new List(); } } diff --git a/src/Altinn.Notifications.Integrations/Profile/ProfileClient.cs b/src/Altinn.Notifications.Integrations/Profile/ProfileClient.cs index c80b71d4..b15e585a 100644 --- a/src/Altinn.Notifications.Integrations/Profile/ProfileClient.cs +++ b/src/Altinn.Notifications.Integrations/Profile/ProfileClient.cs @@ -49,26 +49,4 @@ public async Task> GetUserContactPoints(List nat List? contactPoints = JsonSerializer.Deserialize(responseContent, JsonSerializerOptionsProvider.Options)!.ContactPointList; return contactPoints!; } - - /// - public async Task> GetUserContactPointAvailabilities(List nationalIdentityNumbers) - { - var lookupObject = new UserContactPointLookup - { - NationalIdentityNumbers = nationalIdentityNumbers - }; - - HttpContent content = new StringContent(JsonSerializer.Serialize(lookupObject, JsonSerializerOptionsProvider.Options), Encoding.UTF8, "application/json"); - - var response = await _client.PostAsync("users/contactpoint/availability", content); - - if (!response.IsSuccessStatusCode) - { - throw new PlatformHttpException(response, $"ProfileClient.GetUserContactPointAvailabilities failed with status code {response.StatusCode}"); - } - - string responseContent = await response.Content.ReadAsStringAsync(); - List? contactPoints = JsonSerializer.Deserialize(responseContent, JsonSerializerOptionsProvider.Options)!.AvailabilityList; - return contactPoints!; - } } diff --git a/src/Altinn.Notifications.Integrations/Profile/UserContactPointAvailabilityList.cs b/src/Altinn.Notifications.Integrations/Profile/UserContactPointAvailabilityList.cs deleted file mode 100644 index eedbf7aa..00000000 --- a/src/Altinn.Notifications.Integrations/Profile/UserContactPointAvailabilityList.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Altinn.Notifications.Core.Models.ContactPoints; - -namespace Altinn.Notifications.Integrations.Profile; - -/// -/// A list representation of -/// -public class UserContactPointAvailabilityList -{ - /// - /// A list containing contact point availabiliy for users - /// - public List AvailabilityList { get; set; } = []; -} diff --git a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs index b9f9ba06..292a939d 100644 --- a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs +++ b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs @@ -28,7 +28,7 @@ public RegisterClient(HttpClient client, IOptions settings) } /// - public async Task> GeOrganizationContactPoints(List organizationNumbers) + public async Task> GetOrganizationContactPoints(List organizationNumbers) { var lookupObject = new OrgContactPointLookup { @@ -41,7 +41,7 @@ public async Task> GeOrganizationContactPoints(L if (!response.IsSuccessStatusCode) { - throw new PlatformHttpException(response, $"RegisterClient.GetUnitContactPoints failed with status code {response.StatusCode}"); + throw new PlatformHttpException(response, $"RegisterClient.GetOrganizationContactPoints failed with status code {response.StatusCode}"); } string responseContent = await response.Content.ReadAsStringAsync(); diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs index d87f6275..78ad1bab 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs @@ -35,12 +35,7 @@ public ProfileClientTests() if (request!.RequestUri!.AbsolutePath.EndsWith("contactpoint/lookup")) { UserContactPointLookup? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), JsonSerializerOptionsProvider.Options); - return await GetResponse(lookup!); - } - else if (request!.RequestUri!.AbsolutePath.EndsWith("contactpoint/availability")) - { - UserContactPointLookup? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), JsonSerializerOptionsProvider.Options); - return await GetResponse(lookup!); + return await GetResponse(lookup!); } return new HttpResponseMessage(HttpStatusCode.NotFound); @@ -87,39 +82,7 @@ public async Task GetUserContactPoints_FailureResponse_ExceptionIsThrown() Assert.Equal(HttpStatusCode.ServiceUnavailable, exception.Response?.StatusCode); } - [Fact] - public async Task GetUserContactPointAvailabilities_SuccessResponse_NoMatches() - { - // Act - List actual = await _profileClient.GetUserContactPointAvailabilities(["empty-list"]); - - // Assert - Assert.Empty(actual); - } - - [Fact] - public async Task GetUserContactPointAvailabilities_SuccessResponse_TwoElementsInResponse() - { - // Act - List actual = await _profileClient.GetUserContactPointAvailabilities(["populated-list"]); - - // Assert - Assert.Equal(2, actual.Count); - Assert.Contains("01025101038", actual.Select(cp => cp.NationalIdentityNumber)); - } - - [Fact] - public async Task GetUserContactPointAvailabilities_FailureResponse_ExceptionIsThrown() - { - // Act - var exception = await Assert.ThrowsAsync(async () => await _profileClient.GetUserContactPointAvailabilities(["unavailable"])); - - // Assert - Assert.StartsWith("ProfileClient.GetUserContactPointAvailabilities failed with status code", exception.Message); - Assert.Equal(HttpStatusCode.ServiceUnavailable, exception.Response?.StatusCode); - } - - private Task GetResponse(UserContactPointLookup lookup) + private Task GetResponse(UserContactPointLookup lookup) { HttpStatusCode statusCode = HttpStatusCode.OK; object? contentData = null; @@ -127,10 +90,10 @@ private Task GetResponse(UserContactPointLookup lookup) switch (lookup.NationalIdentityNumbers[0]) { case "empty-list": - contentData = GetEmptyListContent(); + contentData = new UserContactPointsList() { ContactPointList = new List() }; break; case "populated-list": - contentData = GetPopulatedListContent(); + contentData = GetPopulatedListContent(); break; case "unavailable": statusCode = HttpStatusCode.ServiceUnavailable; @@ -147,41 +110,13 @@ private Task GetResponse(UserContactPointLookup lookup) }); } - private static object? GetEmptyListContent() + private static object? GetPopulatedListContent() { - if (typeof(T) == typeof(UserContactPointAvailabilityList)) - { - return new UserContactPointAvailabilityList() { AvailabilityList = new List() }; - } - else if (typeof(T) == typeof(UserContactPointsList)) - { - return new UserContactPointsList() { ContactPointList = new List() }; - } - - return null; - } - - private static object? GetPopulatedListContent() - { - if (typeof(T) == typeof(UserContactPointAvailabilityList)) - { - var availabilityList = new List - { - new UserContactPointAvailability() { NationalIdentityNumber = "01025101038", EmailRegistered = true }, - new UserContactPointAvailability() { NationalIdentityNumber = "01025101037", EmailRegistered = false } - }; - return new UserContactPointAvailabilityList() { AvailabilityList = availabilityList }; - } - else if (typeof(T) == typeof(UserContactPointsList)) - { - var contactPointsList = new List + var contactPointsList = new List { new UserContactPoints() { NationalIdentityNumber = "01025101038", Email = string.Empty }, new UserContactPoints() { NationalIdentityNumber = "01025101037", Email = string.Empty } }; - return new UserContactPointsList() { ContactPointList = contactPointsList }; - } - - return null; + return new UserContactPointsList() { ContactPointList = contactPointsList }; } } diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs new file mode 100644 index 00000000..bf484111 --- /dev/null +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs @@ -0,0 +1,121 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Json; +using System.Text.Json; +using System.Threading.Tasks; + +using Altinn.Notifications.Core; +using Altinn.Notifications.Core.Models.ContactPoints; +using Altinn.Notifications.Core.Shared; +using Altinn.Notifications.Integrations.Configuration; +using Altinn.Notifications.Integrations.Register; + +using Microsoft.Extensions.Options; + +using Xunit; + +namespace Altinn.Notifications.IntegrationTests.Notifications.Integrations.Register; + +public class RegisterClientTests +{ + private readonly JsonSerializerOptions _serializerOptions = new() + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase + }; + + private readonly RegisterClient _registerClient; + + public RegisterClientTests() + { + var sblBridgeHttpMessageHandler = new DelegatingHandlerStub(async (request, token) => + { + if (request!.RequestUri!.AbsolutePath.EndsWith("contactpoint/lookup")) + { + OrgContactPointLookup? lookup = JsonSerializer.Deserialize(await request!.Content!.ReadAsStringAsync(token), JsonSerializerOptionsProvider.Options); + return await GetResponse(lookup!); + } + + return new HttpResponseMessage(HttpStatusCode.NotFound); + }); + + PlatformSettings settings = new() + { + ApiRegisterEndpoint = "https://platform.at22.altinn.cloud/register/api/v1/" + }; + + _registerClient = new RegisterClient( + new HttpClient(sblBridgeHttpMessageHandler), + Options.Create(settings)); + } + + [Fact] + public async Task GetOrganizationContactPoints_SuccessResponse_NoMatches() + { + // Act + List actual = await _registerClient.GetOrganizationContactPoints(["empty-list"]); + + // Assert + Assert.Empty(actual); + } + + [Fact] + public async Task GetOrganizationContactPoints_SuccessResponse_TwoElementsInResponse() + { + // Act + List actual = await _registerClient.GetOrganizationContactPoints(["populated-list"]); + + // Assert + Assert.Equal(2, actual.Count); + Assert.Contains("910011154", actual.Select(cp => cp.OrganizationNumber)); + } + + [Fact] + public async Task GetOrganizationContactPoints_FailureResponse_ExceptionIsThrown() + { + // Act + var exception = await Assert.ThrowsAsync(async () => await _registerClient.GetOrganizationContactPoints(["unavailable"])); + + Assert.StartsWith("RegisterClient.GetOrganizationContactPoints failed with status code", exception.Message); + Assert.Equal(HttpStatusCode.ServiceUnavailable, exception.Response?.StatusCode); + } + + private Task GetResponse(OrgContactPointLookup lookup) + { + HttpStatusCode statusCode = HttpStatusCode.OK; + object? contentData = null; + + switch (lookup.OrganizationNumbers[0]) + { + case "empty-list": + contentData = new OrgContactPointsList() { ContactPointsList = new List() }; + break; + case "populated-list": + contentData = GetPopulatedListContent(); + break; + case "unavailable": + statusCode = HttpStatusCode.ServiceUnavailable; + break; + } + + JsonContent? content = (contentData != null) ? JsonContent.Create(contentData, options: _serializerOptions) : null; + + return Task.FromResult( + new HttpResponseMessage() + { + StatusCode = statusCode, + Content = content + }); + } + + private static object? GetPopulatedListContent() + { + var contactPointsList = new List + { + new OrganizationContactPoints() { OrganizationNumber = "910011154", EmailList = [] }, + new OrganizationContactPoints() { OrganizationNumber = "910011155", EmailList = [] } + }; + return new OrgContactPointsList() { ContactPointsList = contactPointsList }; + } +} From 5a442d489b4161964d65f73b3053aa611513376e Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 24 Apr 2024 13:37:58 +0200 Subject: [PATCH 03/11] added tests --- .../ContactPointServiceTests.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs index 2bef02de..bc4c7301 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs @@ -49,6 +49,39 @@ public async Task AddSmsContactPoints_NationalIdentityNumberAvailable_ProfileSer Assert.Equivalent(expectedOutput, input); } + [Fact] + public async Task AddSmsContactPoints_OrganizationNumberAvailable_RegisterServiceCalled() + { + // Arrange + List input = [ + new Recipient() + { + OrganizationNumber = "12345678901" + } + ]; + + List expectedOutput = [ + new Recipient() + { + OrganizationNumber = "12345678901", + AddressInfo = [new SmsAddressPoint("+4799999999")] + } + ]; + + var registerClientMock = new Mock(); + registerClientMock + .Setup(p => p.GetOrganizationContactPoints(It.Is>(s => s.Contains("12345678901")))) + .ReturnsAsync([new OrganizationContactPoints() { OrganizationNumber = "12345678901", MobileNumberList = ["+4799999999"] }]); + + var service = GetTestService(registerClient: registerClientMock.Object); + + // Act + await service.AddSmsContactPoints(input); + + // Assert + Assert.Equivalent(expectedOutput, input); + } + [Fact] public async Task AddEmailContactPoints_NationalIdentityNumberAvailable_ProfileServiceCalled() { @@ -83,6 +116,39 @@ public async Task AddEmailContactPoints_NationalIdentityNumberAvailable_ProfileS Assert.Equivalent(expectedOutput, input); } + [Fact] + public async Task AddEmailContactPoints_OrganizationNumberAvailable_RegisterServiceCalled() + { + // Arrange + List input = [ + new Recipient() + { + OrganizationNumber = "12345678901" + } + ]; + + List expectedOutput = [ + new Recipient() + { + OrganizationNumber = "12345678901", + AddressInfo = [new EmailAddressPoint("email@domain.com")] + } + ]; + + var registerClientMock = new Mock(); + registerClientMock + .Setup(p => p.GetOrganizationContactPoints(It.Is>(s => s.Contains("12345678901")))) + .ReturnsAsync([new OrganizationContactPoints() { OrganizationNumber = "12345678901", EmailList = ["email@domain.com"] }]); + + var service = GetTestService(registerClient: registerClientMock.Object); + + // Act + await service.AddEmailContactPoints(input); + + // Assert + Assert.Equivalent(expectedOutput, input); + } + private static ContactPointService GetTestService(IProfileClient? profileClient = null, IRegisterClient? registerClient = null) { if (profileClient == null) From 609d0332c4c7b9783c4e51de694517cc9fabf485 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 24 Apr 2024 13:42:19 +0200 Subject: [PATCH 04/11] fixed merge errors --- .../Notifications.Integrations/Profile/ProfileClientTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs index 78ad1bab..6db1dd0d 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs @@ -90,7 +90,7 @@ private Task GetResponse(UserContactPointLookup lookup) switch (lookup.NationalIdentityNumbers[0]) { case "empty-list": - contentData = new UserContactPointsList() { ContactPointList = new List() }; + contentData = new UserContactPointsList() { ContactPointsList = new List() }; break; case "populated-list": contentData = GetPopulatedListContent(); @@ -117,6 +117,6 @@ private Task GetResponse(UserContactPointLookup lookup) new UserContactPoints() { NationalIdentityNumber = "01025101038", Email = string.Empty }, new UserContactPoints() { NationalIdentityNumber = "01025101037", Email = string.Empty } }; - return new UserContactPointsList() { ContactPointList = contactPointsList }; + return new UserContactPointsList() { ContactPointsList = contactPointsList }; } } From 2ed95167fbecf74f3552547dbee105e5891da7ad Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 24 Apr 2024 13:58:48 +0200 Subject: [PATCH 05/11] fixed code smells --- .../Profile/ProfileClientTests.cs | 16 +++++----------- .../Register/RegisterClientTests.cs | 16 +++++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs index 6db1dd0d..99be37cd 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs @@ -93,7 +93,11 @@ private Task GetResponse(UserContactPointLookup lookup) contentData = new UserContactPointsList() { ContactPointsList = new List() }; break; case "populated-list": - contentData = GetPopulatedListContent(); + contentData = new List + { + new UserContactPoints() { NationalIdentityNumber = "01025101038", Email = string.Empty }, + new UserContactPoints() { NationalIdentityNumber = "01025101037", Email = string.Empty } + }; break; case "unavailable": statusCode = HttpStatusCode.ServiceUnavailable; @@ -109,14 +113,4 @@ private Task GetResponse(UserContactPointLookup lookup) Content = content }); } - - private static object? GetPopulatedListContent() - { - var contactPointsList = new List - { - new UserContactPoints() { NationalIdentityNumber = "01025101038", Email = string.Empty }, - new UserContactPoints() { NationalIdentityNumber = "01025101037", Email = string.Empty } - }; - return new UserContactPointsList() { ContactPointsList = contactPointsList }; - } } diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs index bf484111..ed3554cd 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs @@ -92,7 +92,11 @@ private Task GetResponse(OrgContactPointLookup lookup) contentData = new OrgContactPointsList() { ContactPointsList = new List() }; break; case "populated-list": - contentData = GetPopulatedListContent(); + contentData = new List + { + new OrganizationContactPoints() { OrganizationNumber = "910011154", EmailList = [] }, + new OrganizationContactPoints() { OrganizationNumber = "910011155", EmailList = [] } + }; break; case "unavailable": statusCode = HttpStatusCode.ServiceUnavailable; @@ -108,14 +112,4 @@ private Task GetResponse(OrgContactPointLookup lookup) Content = content }); } - - private static object? GetPopulatedListContent() - { - var contactPointsList = new List - { - new OrganizationContactPoints() { OrganizationNumber = "910011154", EmailList = [] }, - new OrganizationContactPoints() { OrganizationNumber = "910011155", EmailList = [] } - }; - return new OrgContactPointsList() { ContactPointsList = contactPointsList }; - } } From b288d29e668c3db04938e2acf60b99fb7f257a67 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Wed, 24 Apr 2024 15:10:47 +0200 Subject: [PATCH 06/11] added mobile number check --- .../Altinn.Notifications.Core.csproj | 1 + .../Services/ContactPointService.cs | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Altinn.Notifications.Core/Altinn.Notifications.Core.csproj b/src/Altinn.Notifications.Core/Altinn.Notifications.Core.csproj index fc2fab01..6051eb49 100644 --- a/src/Altinn.Notifications.Core/Altinn.Notifications.Core.csproj +++ b/src/Altinn.Notifications.Core/Altinn.Notifications.Core.csproj @@ -10,6 +10,7 @@ + diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index f8217d1a..dfa87228 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -1,9 +1,13 @@ -using Altinn.Notifications.Core.Integrations; +using System.Text.RegularExpressions; + +using Altinn.Notifications.Core.Integrations; using Altinn.Notifications.Core.Models; using Altinn.Notifications.Core.Models.Address; using Altinn.Notifications.Core.Models.ContactPoints; using Altinn.Notifications.Core.Services.Interfaces; +using PhoneNumbers; + namespace Altinn.Notifications.Core.Services { /// @@ -13,6 +17,7 @@ public class ContactPointService : IContactPointService { private readonly IProfileClient _profileClient; private readonly IRegisterClient _registerClient; + private readonly PhoneNumberUtil _phoneNumberUtil; /// /// Initializes a new instance of the class. @@ -21,6 +26,7 @@ public ContactPointService(IProfileClient profile, IRegisterClient register) { _profileClient = profile; _registerClient = register; + _phoneNumberUtil = PhoneNumberUtil.GetInstance(); } /// @@ -106,7 +112,6 @@ private async Task> LookupUserContactPoints(List r.NationalIdentityNumber!) .ToList(); - // TODO: ensure all mobile numbers have country code before returning return nins.Count > 0 ? await _profileClient.GetUserContactPoints(nins) : new List(); @@ -121,10 +126,36 @@ will require the extension of the OrganizationContactPoints class */ .Select(r => r.OrganizationNumber!) .ToList(); - // TODO: ensure all mobile numbers have country code before returning - return orgNos.Count > 0 - ? await _registerClient.GetOrganizationContactPoints(orgNos) - : new List(); + if (orgNos.Count == 0) + { + return []; + } + + List contactPoints = await _registerClient.GetOrganizationContactPoints(orgNos); + + contactPoints.ForEach(contactPoint => + { + contactPoint.MobileNumberList = contactPoint.MobileNumberList + .Select(mobileNumber => + { + return EnsureCountryCode(mobileNumber); + }) + .ToList(); + }); + + return contactPoints; + } + + /// + /// Checks if number contains country code, if not it adds the country code for Norway if number starts with 4 or 9 + /// + internal string EnsureCountryCode(string mobileNumber) + { + PhoneNumber phoneNumber = _phoneNumberUtil.Parse(mobileNumber, null); + _phoneNumberUtil.IsValidNumber(phoneNumber); + + // todo: wwrite tests and complete logic + return mobileNumber; } } } From fd2ddadf819615e385c74a728128d2e6da660757 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Fri, 26 Apr 2024 16:54:25 +0200 Subject: [PATCH 07/11] New mobile number helper + country code logic --- .../Helpers/MobileNumberHelper.cs | 58 +++++++++++++++++++ .../Services/ContactPointService.cs | 19 +----- .../SmsNotificationOrderRequestValidator.cs | 28 +-------- .../TestingHelpers/MobileNumberHelperTests.cs | 42 ++++++++++++++ .../Profile/ProfileClientTests.cs | 9 ++- .../Register/RegisterClientTests.cs | 9 ++- ...sNotificationOrderRequestValidatorTests.cs | 19 ------ 7 files changed, 117 insertions(+), 67 deletions(-) create mode 100644 src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs create mode 100644 test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs diff --git a/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs b/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs new file mode 100644 index 00000000..85a3a100 --- /dev/null +++ b/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using PhoneNumbers; + +namespace Altinn.Notifications.Core.Helpers +{ + /// + /// Helper class for all mobile number related actions + /// + public static class MobileNumberHelper + { + /// + /// Checks if number contains country code, if not it adds the country code for Norway if number starts with 4 or 9 + /// + /// + /// This method does not validate the number, only ensures that it has a country code. + /// + public static string EnsureCountryCodeIfValidNumber(string mobileNumber) + { + if (mobileNumber.StartsWith("00")) + { + mobileNumber = "+" + mobileNumber.Remove(0, 2); + } + else if (mobileNumber.Length == 8 && (mobileNumber[0] == '9' || mobileNumber[0] == '4')) + { + mobileNumber = "+47" + mobileNumber; + } + + return mobileNumber; + } + + /// + /// Validated as mobile number based on the Altinn 2 regex + /// + /// The string to validate as an mobile number + /// A boolean indicating that the mobile number is valid or not + public static bool IsValidMobileNumber(string? mobileNumber) + { + if (string.IsNullOrEmpty(mobileNumber) || (!mobileNumber.StartsWith('+') && !mobileNumber.StartsWith("00"))) + { + return false; + } + + if (mobileNumber.StartsWith("00")) + { + mobileNumber = "+" + mobileNumber.Remove(0, 2); + } + + PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance(); + PhoneNumber phoneNumber = phoneNumberUtil.Parse(mobileNumber, null); + return phoneNumberUtil.IsValidNumber(phoneNumber); + } + } +} diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index 845660eb..a3082632 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -1,5 +1,4 @@ -using System.Text.RegularExpressions; - +using Altinn.Notifications.Core.Helpers; using Altinn.Notifications.Core.Integrations; using Altinn.Notifications.Core.Models; using Altinn.Notifications.Core.Models.Address; @@ -146,24 +145,12 @@ will require the extension of the OrganizationContactPoints class */ contactPoint.MobileNumberList = contactPoint.MobileNumberList .Select(mobileNumber => { - return EnsureCountryCode(mobileNumber); + return MobileNumberHelper.EnsureCountryCodeIfValidNumber(mobileNumber); }) .ToList(); }); return contactPoints; - } - - /// - /// Checks if number contains country code, if not it adds the country code for Norway if number starts with 4 or 9 - /// - internal string EnsureCountryCode(string mobileNumber) - { - PhoneNumber phoneNumber = _phoneNumberUtil.Parse(mobileNumber, null); - _phoneNumberUtil.IsValidNumber(phoneNumber); - - // todo: wwrite tests and complete logic - return mobileNumber; - } + } } } diff --git a/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs b/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs index 9e584153..425d7e97 100644 --- a/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs +++ b/src/Altinn.Notifications/Validators/SmsNotificationOrderRequestValidator.cs @@ -1,9 +1,7 @@ -using System.Text.RegularExpressions; - +using Altinn.Notifications.Core.Helpers; using Altinn.Notifications.Models; using FluentValidation; -using PhoneNumbers; namespace Altinn.Notifications.Validators; @@ -23,7 +21,7 @@ public SmsNotificationOrderRequestValidator() .Must(recipients => recipients.TrueForAll(a => { return - (!string.IsNullOrWhiteSpace(a.MobileNumber) && IsValidMobileNumber(a.MobileNumber)) || + (!string.IsNullOrWhiteSpace(a.MobileNumber) && MobileNumberHelper.IsValidMobileNumber(a.MobileNumber)) || (!string.IsNullOrWhiteSpace(a.OrganizationNumber) ^ !string.IsNullOrWhiteSpace(a.NationalIdentityNumber)); })) .WithMessage("Either a valid mobile number starting with country code, organization number, or national identity number must be provided for each recipient."); @@ -36,26 +34,4 @@ public SmsNotificationOrderRequestValidator() RuleFor(order => order.Body).NotEmpty(); } - - /// - /// Validated as mobile number based on the Altinn 2 regex - /// - /// The string to validate as an mobile number - /// A boolean indicating that the mobile number is valid or not - internal static bool IsValidMobileNumber(string? mobileNumber) - { - if (string.IsNullOrEmpty(mobileNumber) || (!mobileNumber.StartsWith('+') && !mobileNumber.StartsWith("00"))) - { - return false; - } - - if (mobileNumber.StartsWith("00")) - { - mobileNumber = "+" + mobileNumber.Remove(0, 2); - } - - PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance(); - PhoneNumber phoneNumber = phoneNumberUtil.Parse(mobileNumber, null); - return phoneNumberUtil.IsValidNumber(phoneNumber); - } } diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs new file mode 100644 index 00000000..a27cb31e --- /dev/null +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs @@ -0,0 +1,42 @@ +using Altinn.Notifications.Core.Helpers; +using Altinn.Notifications.Validators; + +using Xunit; + +namespace Altinn.Notifications.Tests.Notifications.Core.TestingHelpers; + +public class MobileNumberHelperTests +{ + [Theory] + [InlineData("99315000", "+4799315000")] + [InlineData("+4799315000", "+4799315000")] + [InlineData("4123", "4123")] + [InlineData("+4699999999", "+4699999999")] + [InlineData("00233517846", "+233517846")] + [InlineData("81549300", "81549300")] + + public void EnsureCountryCodeIfValidNumber(string input, string expectedOutput) + { + string actual = MobileNumberHelper.EnsureCountryCodeIfValidNumber(input); + Assert.Equal(expectedOutput, actual); + } + + [Theory] + [InlineData("+4740000001", true)] + [InlineData("004740000000", true)] + [InlineData("40000001", false)] + [InlineData("90000000", false)] + [InlineData("+4790000000", true)] + [InlineData("+4750000004", false)] + [InlineData("+47900000001", false)] + [InlineData("+14790000000", false)] + [InlineData("004790000002", true)] + [InlineData("", false)] + [InlineData("111100000", false)] + [InlineData("dasdsadSASA", false)] + public void IsValidMobileNumber(string mobileNumber, bool expectedResult) + { + bool actual = MobileNumberHelper.IsValidMobileNumber(mobileNumber); + Assert.Equal(expectedResult, actual); + } +} diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs index 99be37cd..19959ab6 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Profile/ProfileClientTests.cs @@ -93,11 +93,14 @@ private Task GetResponse(UserContactPointLookup lookup) contentData = new UserContactPointsList() { ContactPointsList = new List() }; break; case "populated-list": - contentData = new List - { + contentData = new UserContactPointsList() + { + ContactPointsList = + [ new UserContactPoints() { NationalIdentityNumber = "01025101038", Email = string.Empty }, new UserContactPoints() { NationalIdentityNumber = "01025101037", Email = string.Empty } - }; + ] + }; break; case "unavailable": statusCode = HttpStatusCode.ServiceUnavailable; diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs index ed3554cd..10e538ac 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs @@ -92,11 +92,14 @@ private Task GetResponse(OrgContactPointLookup lookup) contentData = new OrgContactPointsList() { ContactPointsList = new List() }; break; case "populated-list": - contentData = new List - { + contentData = new OrgContactPointsList + { + ContactPointsList = + [ new OrganizationContactPoints() { OrganizationNumber = "910011154", EmailList = [] }, new OrganizationContactPoints() { OrganizationNumber = "910011155", EmailList = [] } - }; + ] + }; break; case "unavailable": statusCode = HttpStatusCode.ServiceUnavailable; diff --git a/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs b/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs index 51a26bf3..a65b51e7 100644 --- a/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications/TestingValidators/SmsNotificationOrderRequestValidatorTests.cs @@ -144,24 +144,5 @@ public void Validate_BodyMissing_ReturnsFalse() var actual = _validator.Validate(order); Assert.False(actual.IsValid); Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("'Body' must not be empty.")); - } - - [Theory] - [InlineData("+4740000001", true)] - [InlineData("004740000000", true)] - [InlineData("40000001", false)] - [InlineData("90000000", false)] - [InlineData("+4790000000", true)] - [InlineData("+4750000004", false)] - [InlineData("+47900000001", false)] - [InlineData("+14790000000", false)] - [InlineData("004790000002", true)] - [InlineData("", false)] - [InlineData("111100000", false)] - [InlineData("dasdsadSASA", false)] - public void IsValidMobileNumber(string mobileNumber, bool expectedResult) - { - bool actual = SmsNotificationOrderRequestValidator.IsValidMobileNumber(mobileNumber); - Assert.Equal(expectedResult, actual); } } From e7c92267b0fbcb97142fc0003addab34baade247 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Fri, 26 Apr 2024 16:58:42 +0200 Subject: [PATCH 08/11] removed unused references --- src/Altinn.Notifications.Core/Services/ContactPointService.cs | 2 -- src/Altinn.Notifications/Altinn.Notifications.csproj | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index a3082632..780b240b 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -16,7 +16,6 @@ public class ContactPointService : IContactPointService { private readonly IProfileClient _profileClient; private readonly IRegisterClient _registerClient; - private readonly PhoneNumberUtil _phoneNumberUtil; /// /// Initializes a new instance of the class. @@ -25,7 +24,6 @@ public ContactPointService(IProfileClient profile, IRegisterClient register) { _profileClient = profile; _registerClient = register; - _phoneNumberUtil = PhoneNumberUtil.GetInstance(); } /// diff --git a/src/Altinn.Notifications/Altinn.Notifications.csproj b/src/Altinn.Notifications/Altinn.Notifications.csproj index 908e6e68..6afcb84a 100644 --- a/src/Altinn.Notifications/Altinn.Notifications.csproj +++ b/src/Altinn.Notifications/Altinn.Notifications.csproj @@ -14,7 +14,6 @@ - From dd5d326c5591752eb19a4b7de5d9259e9fc49526 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Mon, 29 Apr 2024 12:23:13 +0200 Subject: [PATCH 09/11] added tests to confirm number modification --- .../Services/ContactPointService.cs | 24 ++++++++++++------- .../ContactPointServiceTests.cs | 4 +++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index 780b240b..a1571650 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -5,8 +5,6 @@ using Altinn.Notifications.Core.Models.ContactPoints; using Altinn.Notifications.Core.Services.Interfaces; -using PhoneNumbers; - namespace Altinn.Notifications.Core.Services { /// @@ -75,7 +73,7 @@ private async Task> AugmentRecipients( { List augmentedRecipients = []; - var userLookupTask = LookupUserContactPoints(recipients); + var userLookupTask = LookupPersonContactPoints(recipients); var orgLookupTask = LookupOrganizationContactPoints(recipients); await Task.WhenAll(userLookupTask, orgLookupTask); @@ -110,16 +108,26 @@ private async Task> AugmentRecipients( return augmentedRecipients; } - private async Task> LookupUserContactPoints(List recipients) + private async Task> LookupPersonContactPoints(List recipients) { List nins = recipients .Where(r => !string.IsNullOrEmpty(r.NationalIdentityNumber)) .Select(r => r.NationalIdentityNumber!) .ToList(); - return nins.Count > 0 - ? await _profileClient.GetUserContactPoints(nins) - : new List(); + if (nins.Count == 0) + { + return new List(); + } + + List contactPoints = await _profileClient.GetUserContactPoints(nins); + + contactPoints.ForEach(contactPoint => + { + contactPoint.MobileNumber = MobileNumberHelper.EnsureCountryCodeIfValidNumber(contactPoint.MobileNumber); + }); + + return contactPoints; } private async Task> LookupOrganizationContactPoints(List recipients) @@ -149,6 +157,6 @@ will require the extension of the OrganizationContactPoints class */ }); return contactPoints; - } + } } } diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs index bc4c7301..92d2ef09 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/ContactPointServiceTests.cs @@ -38,7 +38,7 @@ public async Task AddSmsContactPoints_NationalIdentityNumberAvailable_ProfileSer var profileClientMock = new Mock(); profileClientMock .Setup(p => p.GetUserContactPoints(It.Is>(s => s.Contains("12345678901")))) - .ReturnsAsync([new UserContactPoints() { NationalIdentityNumber = "12345678901", MobileNumber = "+4799999999", IsReserved = true }]); + .ReturnsAsync([new UserContactPoints() { NationalIdentityNumber = "12345678901", MobileNumber = "99999999", IsReserved = true }]); var service = GetTestService(profileClient: profileClientMock.Object); @@ -47,6 +47,8 @@ public async Task AddSmsContactPoints_NationalIdentityNumberAvailable_ProfileSer // Assert Assert.Equivalent(expectedOutput, input); + string actualMobileNumber = ((SmsAddressPoint)input[0].AddressInfo[0]).MobileNumber; + Assert.Equal("+4799999999", actualMobileNumber); } [Fact] From 277096dcbd352b71ca810b993d3866ec7be4f81c Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Mon, 6 May 2024 10:07:25 +0200 Subject: [PATCH 10/11] fixed pr comments --- .../Helpers/MobileNumberHelper.cs | 8 +------- .../Services/ContactPointService.cs | 2 +- .../Register/RegisterClient.cs | 2 +- .../TestingHelpers/MobileNumberHelperTests.cs | 1 + 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs b/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs index 85a3a100..3e4f5fad 100644 --- a/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs +++ b/src/Altinn.Notifications.Core/Helpers/MobileNumberHelper.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using PhoneNumbers; +using PhoneNumbers; namespace Altinn.Notifications.Core.Helpers { diff --git a/src/Altinn.Notifications.Core/Services/ContactPointService.cs b/src/Altinn.Notifications.Core/Services/ContactPointService.cs index a1571650..fe170001 100644 --- a/src/Altinn.Notifications.Core/Services/ContactPointService.cs +++ b/src/Altinn.Notifications.Core/Services/ContactPointService.cs @@ -117,7 +117,7 @@ private async Task> LookupPersonContactPoints(List(); + return []; } List contactPoints = await _profileClient.GetUserContactPoints(nins); diff --git a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs index 292a939d..56dcd777 100644 --- a/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs +++ b/src/Altinn.Notifications.Integrations/Register/RegisterClient.cs @@ -41,7 +41,7 @@ public async Task> GetOrganizationContactPoints( if (!response.IsSuccessStatusCode) { - throw new PlatformHttpException(response, $"RegisterClient.GetOrganizationContactPoints failed with status code {response.StatusCode}"); + throw await PlatformHttpException.CreateAsync(response); } string responseContent = await response.Content.ReadAsStringAsync(); diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs index a27cb31e..b1708fa4 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingHelpers/MobileNumberHelperTests.cs @@ -34,6 +34,7 @@ public void EnsureCountryCodeIfValidNumber(string input, string expectedOutput) [InlineData("", false)] [InlineData("111100000", false)] [InlineData("dasdsadSASA", false)] + [InlineData("+233242426224", true)] public void IsValidMobileNumber(string mobileNumber, bool expectedResult) { bool actual = MobileNumberHelper.IsValidMobileNumber(mobileNumber); From 54fae38996692e321cbc306e04e9d3bc6d81f343 Mon Sep 17 00:00:00 2001 From: acn-sbuad Date: Tue, 7 May 2024 11:57:27 +0200 Subject: [PATCH 11/11] updated error message in test --- .../Notifications.Integrations/Register/RegisterClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs index 10e538ac..30b803b5 100644 --- a/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs +++ b/test/Altinn.Notifications.Tests/Notifications.Integrations/Register/RegisterClientTests.cs @@ -77,7 +77,7 @@ public async Task GetOrganizationContactPoints_FailureResponse_ExceptionIsThrown // Act var exception = await Assert.ThrowsAsync(async () => await _registerClient.GetOrganizationContactPoints(["unavailable"])); - Assert.StartsWith("RegisterClient.GetOrganizationContactPoints failed with status code", exception.Message); + Assert.StartsWith("503 - Service Unavailable", exception.Message); Assert.Equal(HttpStatusCode.ServiceUnavailable, exception.Response?.StatusCode); }