Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fix: add lock file, tests and changeset
Signed-off-by: Jayaraman N R <[email protected]>
  • Loading branch information
range123 committed Oct 20, 2022
commit 769c2185b8bb39bc0a3682b37ac8efd16aa77712
5 changes: 5 additions & 0 deletions .changeset/modern-poems-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reactioncommerce/api-plugin-shipments-flat-rate": patch
---

allow nested properties to be accessible for shipment restrictions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ const mockHydratedOrderItems = {
variantId: "tMkp5QwZog5ihYTfG",
weight: 50,
width: 10,
tags: [Array]
tags: [Array],
subtotal: {
amount: 12.99,
currencyCode: "USD"
},
parcel: {
height: 10,
weight: 50,
width: 10,
length: 10
}
};

const mockHydratedOrder = {
Expand Down Expand Up @@ -814,3 +824,82 @@ test("deny method - multiple attributes - item value is less than $100 AND item

expect(allowedMethods).toEqual([]);
});

/*
* Tests with nested item/attribute restrictions
*/
test("deny method - nested attribute - subtotal.amount is less than $100, item restricted", async () => {
const mockMethodRestrictions = [
{
_id: "allow001",
methodIds: [
"stviZaLdqRvTKW6J5"
],
type: "allow",
destination: {
country: [
"US"
]
}
},
{
_id: "deny001",
methodIds: [
"stviZaLdqRvTKW6J5"
],
type: "deny",
attributes: [
{
property: "subtotal.amount",
value: 100,
propertyType: "int",
operator: "lt"
}
]
}
];

mockContext.collections.FlatRateFulfillmentRestrictions.toArray.mockReturnValue(Promise.resolve(mockMethodRestrictions));

const allowedMethods = await filterShippingMethods(mockContext, mockShippingMethod, mockHydratedOrder);

expect(allowedMethods).toEqual([]);
});

test("deny method - nested attributes - parcel.weight is greater than 50, no item restrictions", async () => {
const mockMethodRestrictions = [
{
_id: "allow001",
methodIds: [
"stviZaLdqRvTKW6J5"
],
type: "allow",
destination: {
country: [
"US"
]
}
},
{
_id: "deny001",
methodIds: [
"stviZaLdqRvTKW6J5"
],
type: "deny",
attributes: [
{
property: "parcel.weight",
value: 50,
propertyType: "int",
operator: "gt"
}
]
}
];

mockContext.collections.FlatRateFulfillmentRestrictions.toArray.mockReturnValue(Promise.resolve(mockMethodRestrictions));

const allowedMethods = await filterShippingMethods(mockContext, mockShippingMethod, mockHydratedOrder);

expect(allowedMethods).toEqual(mockShippingMethod);
});
8 changes: 5 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.