Skip to content

Commit

Permalink
Add e2e for metadata, digital checkout, and click and collect (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
szczecha authored Oct 2, 2024
1 parent 2b55c83 commit e850b98
Show file tree
Hide file tree
Showing 10 changed files with 618 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/avatax/e2e/data/maps/channel.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"id": "Q2hhbm5lbDozNg==",
"slug": "channel-us-with-tax",
"deliveryMethodId": "U2hpcHBpbmdNZXRob2Q6MTY=",
"warehouseId": "V2FyZWhvdXNlOjJjYjY1NTk2LTRiOTEtNGRkYS1iMWY4LTA3ZjczOTFiNGMxZA==",
"currency": "USD"
}
}
}
}
5 changes: 5 additions & 0 deletions apps/avatax/e2e/data/maps/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"variantId": "UHJvZHVjdFZhcmlhbnQ6MzM1",
"id": "UHJvZHVjdDoxMjk=",
"name": "Dash Force"
},
"DigitalProduct": {
"variantId": "UHJvZHVjdFZhcmlhbnQ6NDAx",
"id": "UHJvZHVjdDoxNjQ=",
"name": "Gift card 50"
}
}
}
22 changes: 20 additions & 2 deletions apps/avatax/e2e/data/templates/order.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"DraftOrder:PricesWithTax": {
"channelID": "$M{Channel.PricesWithTax.id}"
"input": {
"channelId": "$M{Channel.PricesWithTax.id}"
}
},
"DraftOrder:Address": {
"billingAddress": "$M{Address.NewYork}",
Expand All @@ -11,12 +13,28 @@
"deliveryMethodId": "$M{Channel.PricesWithTax.deliveryMethodId}"
},
"DraftOrder:PricesWithoutTax": {
"channelID": "$M{Channel.USA.id}"
"input": {
"channelId": "$M{Channel.USA.id}"
}
},
"DraftOrder:PricesWithoutTax:ShippingMethod": {
"deliveryMethodId": "$M{Channel.USA.deliveryMethodId}"
},
"DraftOrder:VoucherCode": {
"voucherCode": "$M{Voucher.Percentage.code}"
},
"DraftOrder:LinesAndAddresses": {
"input": {
"channelId": "$M{Channel.PricesWithTax.id}",
"billingAddress": "$M{Address.NewYork}",
"shippingAddress": "$M{Address.NewYork}",
"userEmail": "$F{UserEmail}",
"lines": [
{
"variantId": "$M{Product.Juice.variantId}",
"quantity": 10
}
]
}
}
}
6 changes: 5 additions & 1 deletion apps/avatax/e2e/data/templates/updateDeliveryMethod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
"UpdateDeliveryMethod:USA": {
"deliveryMethodId": "$M{Channel.USA.deliveryMethodId}",
"checkoutId": "$S{CheckoutId}"
},
"UpdateDeliveryMethod:PricesWithTax": {
"deliveryMethodId": "$M{Channel.PricesWithTax.deliveryMethodId}",
"checkoutId": "$S{CheckoutId}"
}
}
}
5 changes: 3 additions & 2 deletions apps/avatax/e2e/graphql/mutations/CreateDraftOrder.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mutation CreateDraftOrder($channelID: ID!) {
draftOrderCreate(input: { channelId: $channelID }) {
mutation CreateDraftOrder($input: DraftOrderCreateInput!) {
draftOrderCreate(input: $input) {
order {
id
...OrderDetailsFragment
}
}
}
24 changes: 24 additions & 0 deletions apps/avatax/e2e/graphql/mutations/UpdateMetadata.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
mutation UpdateMetadata($id: ID!, $input: [MetadataInput!]!) {
updateMetadata(id: $id, input: $input) {
errors {
field
message
}
item {
... on Checkout {
id
metadata {
key
value
}
}
... on Order {
id
metadata {
key
value
}
}
}
}
}
109 changes: 109 additions & 0 deletions apps/avatax/e2e/tests/checkout_with_click_and_collect.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { e2e } from "pactum";
import { describe, it } from "vitest";

import {
CheckoutUpdateDeliveryMethod,
CompleteCheckout,
CreateCheckout,
} from "../generated/graphql";
import { getCompleteMoney } from "../utils/moneyUtils";

// Testmo: https://saleor.testmo.net/repositories/6?group_id=139&case_id=18383
describe("App should calculate taxes for checkout with click and collect TC: AVATAX_19", () => {
const testCase = e2e("Checkout with click and collect [pricesEnteredWithTax: True]");

const CURRENCY = "USD";
const TOTAL_GROSS_PRICE_BEFORE_SHIPPING = 300;
const TOTAL_NET_PRICE_BEFORE_SHIPPING = 275.55;
const TOTAL_TAX_PRICE_BEFORE_SHIPPING = 24.45;

const TOTAL_GROSS_PRICE_AFTER_SHIPPING = 300;
const TOTAL_NET_PRICE_AFTER_SHIPPING = 283.02;
const TOTAL_TAX_PRICE_AFTER_SHIPPING = 16.98;

const SHIPPING_PRICE = 0;

it("should have created a checkout", async () => {
await testCase
.step("Create checkout")
.spec()
.post("/graphql/")
.withGraphQLQuery(CreateCheckout)
.withGraphQLVariables({
"@DATA:TEMPLATE@": "Checkout:PricesWithTax",
})
.expectStatus(200)
.expectJson(
"data.checkoutCreate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: CURRENCY,
}),
)
.stores("CheckoutId", "data.checkoutCreate.checkout.id");
});

it("should add warehouse as delivery method", async () => {
await testCase
.step("Add delivery method")
.spec()
.post("/graphql/")
.withGraphQLQuery(CheckoutUpdateDeliveryMethod)
.withGraphQLVariables({
"@DATA:TEMPLATE@": "UpdateDeliveryMethod:PricesWithTax",
"@OVERRIDES@": {
deliveryMethodId: "$M{Channel.PricesWithTax.warehouseId}",
},
})
.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,
currency: CURRENCY,
}),
)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.shippingPrice",
getCompleteMoney({
gross: SHIPPING_PRICE,
net: SHIPPING_PRICE,
tax: SHIPPING_PRICE,
currency: CURRENCY,
}),
);
});

it("should finalize the checkout", async () => {
await testCase
.step("Complete checkout")
.spec()
.post("/graphql/")
.withGraphQLQuery(CompleteCheckout)
.withGraphQLVariables({ checkoutId: "$S{CheckoutId}" })
.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,
currency: CURRENCY,
}),
)
.expectJson(
"data.checkoutComplete.order.shippingPrice",
getCompleteMoney({
gross: SHIPPING_PRICE,
net: SHIPPING_PRICE,
tax: SHIPPING_PRICE,
currency: CURRENCY,
}),
);
});
});
159 changes: 159 additions & 0 deletions apps/avatax/e2e/tests/checkout_with_customer_metadata.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { e2e } from "pactum";
import { describe, it } from "vitest";

import {
CheckoutUpdateDeliveryMethod,
CompleteCheckout,
CreateCheckout,
UpdateMetadata,
} from "../generated/graphql";
import { getCompleteMoney } from "../utils/moneyUtils";

// Testmo: https://saleor.testmo.net/repositories/6?group_id=139&case_id=16247
describe("App should exempt taxes for checkout with metadata avataxCustomerCode TC: AVATAX_15", () => {
const testCase = e2e("Checkout with avataxCustomerCode [pricesEnteredWithTax: False]");

const metadata = [
{
key: "avataxCustomerCode",
value: "SHOPX",
},
];
const CURRENCY = "USD";
const TOTAL_GROSS_PRICE_BEFORE_SHIPPING = 16.33;
const TOTAL_NET_PRICE_BEFORE_SHIPPING = 15;
const TOTAL_TAX_PRICE_BEFORE_SHIPPING = 1.33;

const SHIPPING_GROSS_PRICE = 75.45;
const SHIPPING_NET_PRICE = 69.31;
const SHIPPING_TAX_PRICE = 6.14;

const TOTAL_GROSS_PRICE_AFTER_SHIPPING = 91.79;
const TOTAL_NET_PRICE_AFTER_SHIPPING = 84.31;
const TOTAL_TAX_PRICE_AFTER_SHIPPING = 7.48;

it("should have created a checkout", async () => {
await testCase
.step("Create checkout")
.spec()
.post("/graphql/")
.withGraphQLQuery(CreateCheckout)
.withGraphQLVariables({
"@DATA:TEMPLATE@": "Checkout:USA",
"@OVERRIDES@": {
lines: [{ quantity: 10, variantId: "$M{Product.Juice.variantId}" }],
channelSlug: "$M{Channel.USA.slug}",
},
})
.expectStatus(200)
.expectJson(
"data.checkoutCreate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: CURRENCY,
}),
)
.stores("CheckoutId", "data.checkoutCreate.checkout.id");
});
it("should update delivery method and calculate shipping price", async () => {
await testCase
.step("Add delivery method")
.spec()
.post("/graphql/")
.withGraphQLQuery(CheckoutUpdateDeliveryMethod)
.withGraphQLVariables({
"@DATA:TEMPLATE@": "UpdateDeliveryMethod:USA",
})
.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,
currency: CURRENCY,
}),
)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.shippingPrice",
getCompleteMoney({
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
currency: CURRENCY,
}),
);
});
it("should apply the customer metadata to the checkout", async () => {
await testCase
.step("Update checkout with customer metadata")
.spec()
.post("/graphql/")
.withGraphQLQuery(UpdateMetadata)
.withGraphQLVariables({
id: "$S{CheckoutId}",
input: metadata,
})
.expectStatus(200)
.expectJson("data.updateMetadata.item.metadata", metadata);
});
it("should update checkout to recalculate taxes after applying the metadata", async () => {
await testCase
.step("Update shipping method to recalculate taxes")
.spec()
.post("/graphql/")
.withGraphQLQuery(CheckoutUpdateDeliveryMethod)
.withGraphQLVariables({
"@DATA:TEMPLATE@": "UpdateDeliveryMethod:USA",
})
.expectStatus(200)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.totalPrice",
getCompleteMoney({
gross: TOTAL_NET_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: 0,
currency: CURRENCY,
}),
)
.expectJson(
"data.checkoutDeliveryMethodUpdate.checkout.shippingPrice",
getCompleteMoney({
gross: SHIPPING_NET_PRICE,
net: SHIPPING_NET_PRICE,
tax: 0,
currency: CURRENCY,
}),
);
});
it("should finalize the checkout", async () => {
await testCase
.step("Complete checkout")
.spec()
.post("/graphql/")
.withGraphQLQuery(CompleteCheckout)
.withGraphQLVariables({ checkoutId: "$S{CheckoutId}" })
.expectStatus(200)
.expectJson(
"data.checkoutComplete.order.total",
getCompleteMoney({
gross: TOTAL_NET_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: 0,
currency: CURRENCY,
}),
)
.expectJson(
"data.checkoutComplete.order.shippingPrice",
getCompleteMoney({
gross: SHIPPING_NET_PRICE,
net: SHIPPING_NET_PRICE,
tax: 0,
currency: CURRENCY,
}),
);
});
});
Loading

0 comments on commit e850b98

Please sign in to comment.