diff --git a/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs b/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs index 61086d0c..d8f705ef 100644 --- a/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs +++ b/src/Altinn.Notifications/Controllers/EmailNotificationOrdersController.cs @@ -66,6 +66,6 @@ public async Task> Post(EmailNotificationOrde } string selfLink = registeredOrder!.GetSelfLink(); - return Accepted(selfLink, registeredOrder!.Id.ToString()); + return Accepted(selfLink, new OrderIdExt(registeredOrder!.Id)); } } diff --git a/src/Altinn.Notifications/Models/OrderIdExt.cs b/src/Altinn.Notifications/Models/OrderIdExt.cs new file mode 100644 index 00000000..f32339f9 --- /dev/null +++ b/src/Altinn.Notifications/Models/OrderIdExt.cs @@ -0,0 +1,27 @@ +using System.Text.Json.Serialization; + +namespace Altinn.Notifications.Models +{ + /// + /// A class representing a container for an order id. + /// + /// + /// External representaion to be used in the API. + /// + public class OrderIdExt + { + /// + /// The order id + /// + [JsonPropertyName("orderId")] + public Guid OrderId { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public OrderIdExt(Guid orderId) + { + OrderId = orderId; + } + } +} diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs index 6c27f27f..d60958ac 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/EmailNotificationOrdersControllerTests.cs @@ -206,12 +206,14 @@ public async Task Post_ServiceReturnsOrder_Accepted() // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string actualOrderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + Assert.NotNull(orderIdObjectExt); + Assert.Equal(_order.Id, orderIdObjectExt.OrderId); Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); - Assert.Equal($"{_order.Id}", actualOrderId); serviceMock.VerifyAll(); } @@ -254,12 +256,15 @@ public async Task Post_OrderWithoutFromAddress_StringEmptyUsedAsServiceInput_Acc // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string actualOrderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + Assert.NotNull(orderIdObjectExt); + Assert.Equal(_order.Id, orderIdObjectExt.OrderId); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + _order.Id, response.Headers?.Location?.ToString()); - Assert.Equal($"{_order.Id}", actualOrderId); serviceMock.VerifyAll(); } diff --git a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs index 55cff340..9eb836e7 100644 --- a/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs +++ b/test/Altinn.Notifications.IntegrationTests/Notifications/EmailNotificationsOrderController/PostTests.cs @@ -1,6 +1,7 @@ using System.Net; using System.Net.Http.Headers; using System.Text; +using System.Text.Json; using Altinn.Notifications.Controllers; using Altinn.Notifications.Core.Enums; @@ -75,12 +76,13 @@ public async Task Post_ServiceReturnsOrderWIthId_Accepted() // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string orderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); - Guid.Parse(orderId); - Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderId, response.Headers?.Location?.ToString()); + Assert.NotNull(orderIdObjectExt); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderIdObjectExt.OrderId, response.Headers?.Location?.ToString()); } [Fact] @@ -97,12 +99,13 @@ public async Task Post_OrderWithoutSendersRef_Accepted() // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); - string orderId = await response.Content.ReadAsStringAsync(); + string respoonseString = await response.Content.ReadAsStringAsync(); + OrderIdExt? orderIdObjectExt = JsonSerializer.Deserialize(respoonseString); // Assert Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); - Guid.Parse(orderId); - Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderId, response.Headers?.Location?.ToString()); + Assert.NotNull(orderIdObjectExt); + Assert.Equal("http://localhost:5090/notifications/api/v1/orders/" + orderIdObjectExt.OrderId, response.Headers?.Location?.ToString()); } public async void Dispose()