Skip to content

Commit

Permalink
Fixed ReturnResponse error DTO.
Browse files Browse the repository at this point in the history
  • Loading branch information
yallie committed Sep 7, 2023
1 parent a197037 commit a9a839b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
22 changes: 20 additions & 2 deletions PochtaSdk.Tests/OtpravkaClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,21 @@ public void CreateOrder()

CreatedOrderID = result.ResultIDs.First();
TestContext.Progress.WriteLine("Created an order: {0}", CreatedOrderID);

CreatedOrderBarcode = result.Orders.First().Barcode;
TestContext.Progress.WriteLine("Order barcode: {0}", CreatedOrderBarcode);
}

private long CreatedOrderID { get; set; } = 920755995;
private long CreatedOrderID { get; set; } = 1208576339;

private string CreatedOrderBarcode { get; set; } = "80082288939742";

[Test, Ordered]
public void GetOrderByIdentity()
{
Assert.That(CreatedOrderID, Is.Not.EqualTo(0));
var result = Client.GetOrder(CreatedOrderID);

Assert.That(result, Is.Not.Null);
Assert.That(result.ID, Is.EqualTo(CreatedOrderID));
}
Expand Down Expand Up @@ -716,8 +722,20 @@ public void SearchForOrdersByGroupName()
Assert.That(order.GroupName, Is.EqualTo("002"));
}

[Test, Ordered, Explicit("Fails with DIRECT_SHIPMENT_NOT_FOUND error")]
public void CreateDirectReturnOrderThenDeleteIt()
{
Assert.That(CreatedOrderBarcode, Is.Not.Null.And.Not.Empty);

var ret = Client.CreateReturn(CreatedOrderBarcode);
TestContext.Progress.WriteLine($"Created return: {ret.ReturnBarcode}");

Client.DeleteReturn(ret.ReturnBarcode);
TestContext.Progress.WriteLine($"Deleted return: {ret.ReturnBarcode}");
}

[Test, Explicit("Fails with INTERNAL_ERROR error, code 1002, http status 500")]
public void CreateReturnOrderThenDeleteIt()
public void CreateSeparateReturnOrderThenDeleteIt()
{
var order = new ReturnOrder
{
Expand Down
35 changes: 3 additions & 32 deletions PochtaSdk/Otpravka/ReturnResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,14 @@ public class ReturnResponse : IHasErrors
/// Список ошибок
/// </summary>
[DataMember(Name = "errors")]
public Error[] Errors { get; set; }

private IEnumerable<ErrorWithCode> ErrorsWithCodes
{
get
{
var errors = Errors ?? Enumerable.Empty<Error>();

// sometimes we have errors holding arrays or error-with-codes
var errorsWithCodes =
from err in errors
orderby err.Position
from ewc in err.ErrorCodes ?? Enumerable.Empty<ErrorWithCode>()
orderby ewc.Position
select ewc;

// and sometimes we have flat errors with error-codes
var moreErrors =
from err in errors
orderby err.Position
where err.ErrorCode.HasValue
select new ErrorWithCode
{
Code = err.ErrorCode.Value,
Description = err.ErrorCode.Value.GetDisplayName(),
};

return errorsWithCodes.Concat(moreErrors);
}
}
public ErrorWithCode[] Errors { get; set; }

/// <inheritdoc/>
public bool HasErrors() => ErrorsWithCodes.Any();
public bool HasErrors() => Errors.Any();

/// <inheritdoc/>
public string GetErrorMessage() =>
string.Join(". ", ErrorsWithCodes
string.Join(". ", Errors
.Select(e => e.Description.Coalesce(e.Code.GetDisplayName(), string.Empty)
.Trim(". \r\n\v".ToCharArray())));
}
Expand Down

0 comments on commit a9a839b

Please sign in to comment.