-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,8 +181,19 @@ public async Task Post_ServiceReturnsError_ServerError() | |
public async Task Post_ServiceReturnsOrder_Accepted() | ||
{ | ||
// Arrange | ||
string expectedFromAddress = "[email protected]"; | ||
|
||
Mock<IEmailNotificationOrderService> serviceMock = new(); | ||
serviceMock.Setup(s => s.RegisterEmailNotificationOrder(It.IsAny<NotificationOrderRequest>())) | ||
.Callback<NotificationOrderRequest>(orderRequest => | ||
{ | ||
var emailTemplate = orderRequest.Templates | ||
.OfType<EmailTemplate>() | ||
.FirstOrDefault(); | ||
|
||
Assert.NotNull(emailTemplate); | ||
Assert.Equal(expectedFromAddress, emailTemplate.FromAddress); | ||
}) | ||
.ReturnsAsync((_order, null)); | ||
|
||
HttpClient client = GetTestClient(orderService: serviceMock.Object); | ||
|
@@ -205,6 +216,55 @@ public async Task Post_ServiceReturnsOrder_Accepted() | |
serviceMock.VerifyAll(); | ||
} | ||
|
||
[Fact] | ||
public async Task Post_OrderWithoutFromAddress_NullUsedAsServiceInput_Accepted() | ||
{ | ||
// Arrange | ||
Check warning on line 222 in test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs GitHub Actions / Build, test & analyze
Check warning on line 222 in test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs GitHub Actions / Build, test & analyze
Check warning on line 222 in test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs GitHub Actions / Analyze (csharp)
Check warning on line 222 in test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs GitHub Actions / Analyze (csharp)
|
||
|
||
Mock<IEmailNotificationOrderService> serviceMock = new(); | ||
|
||
serviceMock.Setup(s => s.RegisterEmailNotificationOrder(It.IsAny<NotificationOrderRequest>())) | ||
.Callback<NotificationOrderRequest>(orderRequest => | ||
{ | ||
var emailTemplate = orderRequest.Templates | ||
.OfType<EmailTemplate>() | ||
.FirstOrDefault(); | ||
|
||
Assert.NotNull(emailTemplate); | ||
Assert.Null(emailTemplate.FromAddress); | ||
}) | ||
.ReturnsAsync((_order, null)); | ||
|
||
HttpClient client = GetTestClient(orderService: serviceMock.Object); | ||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", PrincipalUtil.GetOrgToken("ttd")); | ||
|
||
EmailNotificationOrderRequestExt request = new() | ||
{ | ||
Body = "email-body", | ||
ContentType = EmailContentType.Html, | ||
Recipients = new List<RecipientExt>() { new RecipientExt() { EmailAddress = "[email protected]" }, new RecipientExt() { EmailAddress = "[email protected]" } }, | ||
SendersReference = "senders-reference", | ||
RequestedSendTime = DateTime.UtcNow, | ||
Subject = "email-subject", | ||
}; | ||
|
||
HttpRequestMessage httpRequestMessage = new(HttpMethod.Post, _basePath) | ||
{ | ||
Content = new StringContent(request.Serialize(), Encoding.UTF8, "application/json") | ||
}; | ||
|
||
// Act | ||
HttpResponseMessage response = await client.SendAsync(httpRequestMessage); | ||
string actualOrderId = await response.Content.ReadAsStringAsync(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); | ||
Assert.Equal($"{_order.Id}", actualOrderId); | ||
|
||
serviceMock.VerifyAll(); | ||
} | ||
|
||
private HttpClient GetTestClient(IValidator<EmailNotificationOrderRequestExt>? validator = null, IEmailNotificationOrderService? orderService = null) | ||
{ | ||
if (validator == null) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,21 +71,6 @@ public void Validate_SendTimePassed_ReturnsFalse() | |
Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("Send time must be in the future. Leave blank to send immediately.")); | ||
} | ||
|
||
[Fact] | ||
public void Validate_FromAddressMissing_ReturnsFalse() | ||
{ | ||
var order = new EmailNotificationOrderRequestExt() | ||
{ | ||
Subject = "This is an email subject", | ||
Recipients = new List<RecipientExt>() { new RecipientExt() { Id = "16069412345", EmailAddress = "[email protected]" } }, | ||
Body = "This is an email body" | ||
}; | ||
|
||
var actual = _validator.Validate(order); | ||
Assert.False(actual.IsValid); | ||
Assert.Contains(actual.Errors, a => a.ErrorMessage.Equals("'From Address' must not be empty.")); | ||
} | ||
|
||
[Fact] | ||
public void Validate_SubjectMissing_ReturnsFalse() | ||
{ | ||
|