Skip to content

Commit 9eafaab

Browse files
authored
ensure failed lookup requests are persisted too (#490)
* ensure failed lookup requests are persisted too. * updated unit test
1 parent 7c09d5f commit 9eafaab

File tree

4 files changed

+4
-17
lines changed

4 files changed

+4
-17
lines changed

src/Altinn.Notifications.Core/Services/OrderRequestService.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ public async Task<NotificationOrderRequestResponse> RegisterNotificationOrder(No
5151
var copiedRecipents = orderRequest.Recipients.Select(r => r.DeepCopy()).ToList();
5252
var lookupResult = await GetRecipientLookupResult(copiedRecipents, orderRequest.NotificationChannel);
5353

54-
if (lookupResult?.Status == RecipientLookupStatus.Failed)
55-
{
56-
return new NotificationOrderRequestResponse()
57-
{
58-
RecipientLookup = lookupResult
59-
};
60-
}
61-
6254
var templates = SetSenderIfNotDefined(orderRequest.Templates);
6355

6456
var order = new NotificationOrder(

src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public async Task<ActionResult<NotificationOrderRequestResponseExt>> Post(EmailN
7373
var orderRequest = emailNotificationOrderRequest.MapToOrderRequest(creator);
7474
NotificationOrderRequestResponse result = await _orderRequestService.RegisterNotificationOrder(orderRequest);
7575

76-
if (result.RecipientLookup?.Status == RecipientLookupStatus.Failed)
77-
{
78-
return BadRequest(result);
79-
}
80-
8176
return Accepted(result.OrderId!.GetSelfLinkFromOrderId(), result.MapToExternal());
8277
}
8378
}

test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public async Task Post_ValidAccessToken_ServiceReturnsSuccessRequestResult_Accep
247247
}
248248

249249
[Fact]
250-
public async Task Post_ServiceReturnsFailedLookupStatus_BadRequest()
250+
public async Task Post_ServiceReturnsFailedLookupStatus_Accepted()
251251
{
252252
// Arrange
253253
Mock<IOrderRequestService> serviceMock = new();
@@ -276,7 +276,7 @@ public async Task Post_ServiceReturnsFailedLookupStatus_BadRequest()
276276
string respoonseString = await response.Content.ReadAsStringAsync();
277277

278278
// Assert
279-
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
279+
Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
280280
NotificationOrderRequestResponseExt? responseObject = JsonSerializer.Deserialize<NotificationOrderRequestResponseExt>(respoonseString, _options);
281281
Assert.Null(responseObject?.OrderId);
282282
Assert.Equal(RecipientLookupStatusExt.Failed, responseObject!.RecipientLookup!.Status);

test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/OrderRequestServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public async Task RegisterNotificationOrder_ForSms_NoSenderNumberDefaultInserted
213213
}
214214

215215
[Fact]
216-
public async Task RegisterNotificationOrder_LookupFails_NoOrderCreated()
216+
public async Task RegisterNotificationOrder_LookupFails_OrderCreated()
217217
{
218218
// Arrange
219219
DateTime sendTime = DateTime.UtcNow;
@@ -243,7 +243,7 @@ public async Task RegisterNotificationOrder_LookupFails_NoOrderCreated()
243243

244244
// Assert
245245
Assert.Equal(RecipientLookupStatus.Failed, actual.RecipientLookup?.Status);
246-
repoMock.Verify(r => r.Create(It.IsAny<NotificationOrder>()), Times.Never);
246+
repoMock.Verify(r => r.Create(It.IsAny<NotificationOrder>()), Times.Once);
247247
}
248248

249249
[Fact]

0 commit comments

Comments
 (0)