Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return object on post of order #250

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public async Task<ActionResult<NotificationOrderExt>> Post(EmailNotificationOrde
}

string selfLink = registeredOrder!.GetSelfLink();
return Accepted(selfLink, registeredOrder!.Id.ToString());
return Accepted(selfLink, new OrderIdExt(registeredOrder!.Id));
}
}
27 changes: 27 additions & 0 deletions src/Altinn.Notifications/Models/OrderIdExt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Text.Json.Serialization;

namespace Altinn.Notifications.Models
{
/// <summary>
/// A class representing a container for an order id.
/// </summary>
/// <remarks>
/// External representaion to be used in the API.
/// </remarks>
public class OrderIdExt
{
/// <summary>
/// The order id
/// </summary>
[JsonPropertyName("orderId")]
public Guid OrderId { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="OrderIdExt"/> class.
/// </summary>
public OrderIdExt(Guid orderId)
{
OrderId = orderId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrderIdExt>(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();
}
Expand Down Expand Up @@ -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<OrderIdExt>(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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<OrderIdExt>(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]
Expand All @@ -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<OrderIdExt>(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()
Expand Down
Loading