-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PBL-9157 Shopify Orders Partial Refund (#45)
PBL-9157 shopify orders partial refund on orders sync implemented, unit tests added
- Loading branch information
1 parent
01c7161
commit c35a4a4
Showing
5 changed files
with
92 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/ShopifyAccessTests/ShopifyAccessTests/Orders/OrdersTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
using ServiceStack.Text; | ||
using ShopifyAccess; | ||
using ShopifyAccess.Models.Order; | ||
|
||
namespace ShopifyAccessTests.Orders | ||
{ | ||
[ TestFixture ] | ||
public class OrderTests | ||
{ | ||
private static readonly Randomizer _randomizer = new Randomizer(); | ||
|
||
[ Test ] | ||
public void ProcessRefundOrderLineItems_ReturnLineItemQuantityRefundDeducted_WhenIsRefundQuantityLessThanLineItemQuantity() | ||
{ | ||
// Arrange | ||
var quantity = _randomizer.Next( 2, int.MaxValue ); | ||
var refundQuantity = _randomizer.Next( 1, quantity - 1 ); | ||
var shopifyOrderJson = GenerateShopifyOrderJsonWithRefund( quantity, refundQuantity ); | ||
var shopifyOrder = JsonSerializer.DeserializeFromString< ShopifyOrder >( shopifyOrderJson ); | ||
|
||
// Act | ||
ShopifyService.ProcessRefundOrderLineItems( shopifyOrder ); | ||
|
||
// Assert | ||
Assert.That( shopifyOrder.OrderItems[ 0 ].Quantity, Is.EqualTo( quantity - refundQuantity ) ); | ||
} | ||
|
||
[ Test ] | ||
public void ProcessRefundOrderLineItems_LineItemRemovedFromOrder_WhenIsRefundQuantityEqualsToLineItemQuantity_andRestockTypeIsCancel() | ||
{ | ||
// Arrange | ||
var quantity = _randomizer.Next( 2, int.MaxValue ); | ||
var shopifyOrderJson = GenerateShopifyOrderJsonWithRefund( quantity, quantity, restockType: "cancel" ); | ||
var shopifyOrder = JsonSerializer.DeserializeFromString< ShopifyOrder >( shopifyOrderJson ); | ||
|
||
// Act | ||
ShopifyService.ProcessRefundOrderLineItems( shopifyOrder ); | ||
|
||
// Assert | ||
Assert.That( shopifyOrder.OrderItems.Count, Is.EqualTo( 0 ) ); | ||
} | ||
|
||
private static string GenerateShopifyOrderJsonWithRefund( int orderQuantity, int refundQuantity, string restockType = "" ) | ||
{ | ||
var lineItemId = _randomizer.Next(); | ||
return @" | ||
{ | ||
""line_items"": [ | ||
{ | ||
""id"": " + lineItemId + @", | ||
""quantity"": " + orderQuantity + @" | ||
} | ||
], | ||
""refunds"": [ | ||
{ | ||
""refund_line_items"": [ | ||
{ | ||
""line_item_id"": " + lineItemId + @", | ||
""quantity"": " + refundQuantity + @", | ||
""restock_type"": " + restockType + @" | ||
} | ||
] | ||
} | ||
] | ||
}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters