Skip to content

Commit

Permalink
Merge branch 'main' into refactor-webhooks-service
Browse files Browse the repository at this point in the history
  • Loading branch information
lkostrowski committed Oct 1, 2024
2 parents af91de6 + 4fc1062 commit 4da7674
Show file tree
Hide file tree
Showing 19 changed files with 378 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
OrderDetails,
StaffUserTokenCreate,
} from "../generated/graphql";
import { getCompleteMoney } from "../utils/moneyUtils";

// Testmo: https://saleor.testmo.net/repositories/6?group_id=139&case_id=18385
describe("App should calculate taxes for checkout on update shipping address TC: AVATAX_21", () => {
Expand All @@ -21,8 +22,6 @@ describe("App should calculate taxes for checkout on update shipping address TC:
password: process.env.E2E_USER_PASSWORD as string,
};

const CURRENCY = "USD";

const TOTAL_GROSS_PRICE_BEFORE_SHIPPING = 15;
const TOTAL_NET_PRICE_BEFORE_SHIPPING = 13.78;
const TOTAL_TAX_PRICE_BEFORE_SHIPPING = 1.22;
Expand Down Expand Up @@ -55,18 +54,14 @@ describe("App should calculate taxes for checkout on update shipping address TC:
},
})
.expectStatus(200)
.expectJson("data.checkoutCreate.checkout.totalPrice.net", {
amount: TOTAL_GROSS_PRICE_BEFORE_SHIPPING, // no taxes are calculated yet
currency: "USD",
})
.expectJson("data.checkoutCreate.checkout.totalPrice.gross", {
amount: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutCreate.checkout.totalPrice.tax", {
amount: 0,
currency: "USD",
})
.expectJson(
"data.checkoutCreate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
tax: 0,
}),
)
.stores("CheckoutId", "data.checkoutCreate.checkout.id");
});

Expand All @@ -87,18 +82,14 @@ describe("App should calculate taxes for checkout on update shipping address TC:
addressVerification,
)
.expectJson("data.checkoutShippingAddressUpdate.checkout.billingAddress", null)
.expectJson("data.checkoutShippingAddressUpdate.checkout.totalPrice.net", {
amount: TOTAL_NET_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutShippingAddressUpdate.checkout.totalPrice.gross", {
amount: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutShippingAddressUpdate.checkout.totalPrice.tax", {
amount: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: "USD",
});
.expectJson(
"data.checkoutShippingAddressUpdate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
}),
);
});

it("should add a valid billing address", async () => {
Expand All @@ -120,18 +111,14 @@ describe("App should calculate taxes for checkout on update shipping address TC:
"data.checkoutBillingAddressUpdate.checkout.billingAddress",
addressVerification,
)
.expectJson("data.checkoutBillingAddressUpdate.checkout.totalPrice.net", {
amount: TOTAL_NET_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutBillingAddressUpdate.checkout.totalPrice.gross", {
amount: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutBillingAddressUpdate.checkout.totalPrice.tax", {
amount: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: "USD",
});
.expectJson(
"data.checkoutBillingAddressUpdate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
}),
);
});

it("should update delivery method and calculate shipping price", async () => {
Expand All @@ -143,30 +130,23 @@ describe("App should calculate taxes for checkout on update shipping address TC:
.withGraphQLVariables({
"@DATA:TEMPLATE@": "UpdateDeliveryMethod:USA",
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.totalPrice.net", {
currency: "USD",
amount: TOTAL_NET_PRICE_AFTER_SHIPPING,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.totalPrice.gross", {
currency: "USD",
amount: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.totalPrice.tax", {
currency: "USD",
amount: TOTAL_TAX_PRICE_AFTER_SHIPPING,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.shippingPrice.net", {
currency: "USD",
amount: SHIPPING_NET_PRICE,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.shippingPrice.gross", {
currency: "USD",
amount: SHIPPING_GROSS_PRICE,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.shippingPrice.tax", {
currency: "USD",
amount: SHIPPING_TAX_PRICE,
});
.expectStatus(200)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
}),
)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.shippingPrice",
getCompleteMoney({
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
}),
);
});

it("should finalize the checkout", async () => {
Expand All @@ -176,43 +156,23 @@ describe("App should calculate taxes for checkout on update shipping address TC:
.post("/graphql/")
.withGraphQLQuery(CompleteCheckout)
.withGraphQLVariables({ checkoutId: "$S{CheckoutId}" })
.expectJsonMatch({
data: {
checkoutComplete: {
order: {
id: string(),
total: {
gross: {
amount: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
},
net: {
amount: TOTAL_NET_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
},
tax: {
amount: TOTAL_TAX_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
},
},
shippingPrice: {
gross: {
amount: SHIPPING_GROSS_PRICE,
currency: CURRENCY,
},
net: {
amount: SHIPPING_NET_PRICE,
currency: CURRENCY,
},
tax: {
amount: SHIPPING_TAX_PRICE,
currency: CURRENCY,
},
},
},
},
},
})
.expectStatus(200)
.expectJson(
"data.checkoutComplete.order.total",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
}),
)
.expectJson(
"data.checkoutComplete.order.shippingPrice",
getCompleteMoney({
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
}),
)
.stores("OrderID", "data.checkoutComplete.order.id");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OrderDetails,
StaffUserTokenCreate,
} from "../generated/graphql";
import { getCompleteMoney } from "../utils/moneyUtils";

// Testmo: https://saleor.testmo.net/repositories/6?group_id=139&case_id=18384
describe("App should calculate taxes for checkout with product with tax class TC: AVATAX_20", () => {
Expand All @@ -19,8 +20,6 @@ describe("App should calculate taxes for checkout with product with tax class TC
password: process.env.E2E_USER_PASSWORD as string,
};

const CURRENCY = "USD";

const TOTAL_GROSS_PRICE_BEFORE_SHIPPING = 15;
const TOTAL_NET_PRICE_BEFORE_SHIPPING = 13.78;
const TOTAL_TAX_PRICE_BEFORE_SHIPPING = 1.22;
Expand All @@ -47,18 +46,14 @@ describe("App should calculate taxes for checkout with product with tax class TC
},
})
.expectStatus(200)
.expectJson("data.checkoutCreate.checkout.totalPrice.net", {
amount: TOTAL_NET_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutCreate.checkout.totalPrice.gross", {
amount: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson("data.checkoutCreate.checkout.totalPrice.tax", {
amount: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: "USD",
})
.expectJson(
"data.checkoutCreate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
}),
)
.stores("CheckoutId", "data.checkoutCreate.checkout.id");
});

Expand All @@ -71,30 +66,23 @@ describe("App should calculate taxes for checkout with product with tax class TC
.withGraphQLVariables({
"@DATA:TEMPLATE@": "UpdateDeliveryMethod:USA",
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.totalPrice.net", {
currency: "USD",
amount: TOTAL_NET_PRICE_AFTER_SHIPPING,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.totalPrice.gross", {
currency: "USD",
amount: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.totalPrice.tax", {
currency: "USD",
amount: TOTAL_TAX_PRICE_AFTER_SHIPPING,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.shippingPrice.net", {
currency: "USD",
amount: SHIPPING_NET_PRICE,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.shippingPrice.gross", {
currency: "USD",
amount: SHIPPING_GROSS_PRICE,
})
.expectJson("data.checkoutDeliveryMethodUpdate.checkout.shippingPrice.tax", {
currency: "USD",
amount: SHIPPING_TAX_PRICE,
});
.expectStatus(200)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
}),
)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.shippingPrice",
getCompleteMoney({
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
}),
);
});

it("should finalize the checkout", async () => {
Expand All @@ -104,43 +92,23 @@ describe("App should calculate taxes for checkout with product with tax class TC
.post("/graphql/")
.withGraphQLQuery(CompleteCheckout)
.withGraphQLVariables({ checkoutId: "$S{CheckoutId}" })
.expectJsonMatch({
data: {
checkoutComplete: {
order: {
id: string(),
total: {
gross: {
amount: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
},
net: {
amount: TOTAL_NET_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
},
tax: {
amount: TOTAL_TAX_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
},
},
shippingPrice: {
gross: {
amount: SHIPPING_GROSS_PRICE,
currency: CURRENCY,
},
net: {
amount: SHIPPING_NET_PRICE,
currency: CURRENCY,
},
tax: {
amount: SHIPPING_TAX_PRICE,
currency: CURRENCY,
},
},
},
},
},
})
.expectStatus(200)
.expectJson(
"data.checkoutComplete.order.total",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
}),
)
.expectJson(
"data.checkoutComplete.order.shippingPrice",
getCompleteMoney({
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
}),
)
.stores("OrderID", "data.checkoutComplete.order.id");
});

Expand Down
Loading

0 comments on commit 4da7674

Please sign in to comment.