Skip to content

Commit

Permalink
SMS OrderMapper methos overloading fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
khanrn committed Jan 26, 2024
1 parent dd3023b commit 0533acd
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/Altinn.Notifications/Altinn.Notifications.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="Altinn.Common.PEP" Version="1.3.0" />
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="JWTCookieAuthentication" Version="3.0.1" />
<PackageReference Include="libphonenumber-csharp" Version="8.13.28" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<ActionResult<OrderIdExt>> Post(EmailNotificationOrderRequestEx
return Forbid();
}

var orderRequest = emailNotificationOrderRequest.ForEmailMapToOrderRequest(creator);
var orderRequest = emailNotificationOrderRequest.MapToOrderRequest(creator);
(NotificationOrder? registeredOrder, ServiceError? error) = await _orderRequestService.RegisterNotificationOrder(orderRequest);

if (error != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task<ActionResult<OrderIdExt>> Post(SmsNotificationOrderRequestExt
return Forbid();
}

NotificationOrderRequest orderRequest = smsNotificationOrderRequest.ForSmsMapToOrderRequest(creator);
NotificationOrderRequest orderRequest = smsNotificationOrderRequest.MapToOrderRequest(creator);
(NotificationOrder? registeredOrder, ServiceError? error) = await _orderRequestService.RegisterNotificationOrder(orderRequest);

if (error != null)
Expand Down
4 changes: 2 additions & 2 deletions src/Altinn.Notifications/Mappers/OrderMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class OrderMapper
/// <summary>
/// Maps a <see cref="EmailNotificationOrderRequestExt"/> to a <see cref="NotificationOrderRequest"/>
/// </summary>
public static NotificationOrderRequest ForEmailMapToOrderRequest(this EmailNotificationOrderRequestExt extRequest, string creator)
public static NotificationOrderRequest MapToOrderRequest(this EmailNotificationOrderRequestExt extRequest, string creator)
{
var emailTemplate = new EmailTemplate(null, extRequest.Subject, extRequest.Body, (EmailContentType)extRequest.ContentType);

Expand All @@ -37,7 +37,7 @@ public static NotificationOrderRequest ForEmailMapToOrderRequest(this EmailNotif
/// <summary>
/// Maps a <see cref="SmsNotificationOrderRequestExt"/> to a <see cref="NotificationOrderRequest"/>
/// </summary>
public static NotificationOrderRequest ForSmsMapToOrderRequest(this SmsNotificationOrderRequestExt extRequest, string creator)
public static NotificationOrderRequest MapToOrderRequest(this SmsNotificationOrderRequestExt extRequest, string creator)
{
INotificationTemplate smsTemplate = new SmsTemplate(extRequest.SenderNumber, extRequest.Body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Altinn.Notifications.Models;

using FluentValidation;
using PhoneNumbers;

namespace Altinn.Notifications.Validators;

Expand Down Expand Up @@ -49,6 +50,20 @@ internal static bool IsValidMobileNumber(string? mobileNumber)

Match match = regex.Match(mobileNumber);

return match.Success;
if (!match.Success)
{
return false;
}

PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.GetInstance();

mobileNumber = !mobileNumber.StartsWith("+")
? mobileNumber.StartsWith("00")
? "+" + mobileNumber.Remove(0, 2)
: "+47" + mobileNumber
: mobileNumber;

PhoneNumber phoneNumber = phoneNumberUtil.Parse(mobileNumber, null);
return phoneNumberUtil.IsValidNumber(phoneNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void ForEmailMapToOrderRequest_RecipientsProvided_AreEquivalent()
};

// Act
var actual = orderRequestExt.ForEmailMapToOrderRequest("ttd");
var actual = orderRequestExt.MapToOrderRequest("ttd");

// Assert
Assert.Equivalent(expected, actual, true);
Expand Down Expand Up @@ -172,7 +172,7 @@ public void ForEmailMapToOrderRequest_SendTimeLocalConvertedToUtc_AreEquivalent(
};

// Act
var actual = orderRequestExt.ForEmailMapToOrderRequest("ttd");
var actual = orderRequestExt.MapToOrderRequest("ttd");

// Assert
Assert.Equivalent(expected, actual, true);
Expand Down Expand Up @@ -212,7 +212,7 @@ public void ForSmsMapToOrderRequest_RecipientsProvided_AreEquivalent()
};

// Act
var actual = orderRequestExt.ForSmsMapToOrderRequest("ttd");
var actual = orderRequestExt.MapToOrderRequest("ttd");

// Assert
Assert.Equivalent(expected, actual, true);
Expand Down Expand Up @@ -244,7 +244,7 @@ public void ForSmsMapToOrderRequest_SendTimeLocalConvertedToUtc_AreEquivalent()
};

// Act
var actual = orderRequestExt.ForSmsMapToOrderRequest("ttd");
var actual = orderRequestExt.MapToOrderRequest("ttd");

// Assert
Assert.Equivalent(expected, actual, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void Validate_SendTimePassed_ReturnsFalse()
var order = new SmsNotificationOrderRequestExt()
{
SenderNumber = "+4740000001",
Recipients = new List<RecipientExt>() { new RecipientExt() { MobileNumber = "+4740000000" } },
Recipients = new List<RecipientExt>() { new RecipientExt() { MobileNumber = "+4740085041" } },
Body = "This is an SMS body",
RequestedSendTime = DateTime.UtcNow.AddDays(-1)
};
Expand Down Expand Up @@ -154,7 +154,7 @@ public void Validate_BodyMissing_ReturnsFalse()
[InlineData("+4790000000", true)]
[InlineData("+4750000004", false)]
[InlineData("+47900000001", false)]
[InlineData("+14790000000", true)]
[InlineData("+14790000000", false)]
[InlineData("004790000002", true)]
[InlineData("", false)]
[InlineData("111100000", false)]
Expand Down

0 comments on commit 0533acd

Please sign in to comment.