Skip to content

Commit

Permalink
return object on post of order (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
acn-sbuad authored Sep 25, 2023
1 parent 2927d5a commit 260d3a5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
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

0 comments on commit 260d3a5

Please sign in to comment.