-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e for metadata, digital checkout, and click and collect (#1606)
- Loading branch information
Showing
10 changed files
with
618 additions
and
6 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
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
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 | ||
} | ||
} | ||
} |
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,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
109
apps/avatax/e2e/tests/checkout_with_click_and_collect.spec.ts
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,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
159
apps/avatax/e2e/tests/checkout_with_customer_metadata.spec.ts
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,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, | ||
}), | ||
); | ||
}); | ||
}); |
Oops, something went wrong.