Skip to content

Commit

Permalink
Merge branch 'main' into remove-bruno-hack
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofzuraw authored Oct 2, 2024
2 parents ec4b785 + d36e79a commit bd177cc
Show file tree
Hide file tree
Showing 23 changed files with 851 additions and 149 deletions.
6 changes: 6 additions & 0 deletions apps/avatax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# app-avatax

## 1.10.4

### Patch Changes

- f4250c1a: Fixed broken taxes resolving for billing address

## 1.10.3

### Patch Changes
Expand Down
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 @@ -14,6 +14,11 @@
"variantId": "UHJvZHVjdFZhcmlhbnQ6Mzkw",
"id": "UHJvZHVjdDoxNTc=",
"name": "Reversed Monotype Tee"
},
"ProductOnCatalogPromotion": {
"variantId": "UHJvZHVjdFZhcmlhbnQ6MzM1",
"id": "UHJvZHVjdDoxMjk=",
"name": "Dash Force"
}
}
}
13 changes: 11 additions & 2 deletions apps/avatax/e2e/data/templates/order.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
"DraftOrder:PricesWithTax": {
"channelID": "$M{Channel.PricesWithTax.id}"
},
"DraftOrder:PricesWithTax:Address": {
"DraftOrder:Address": {
"billingAddress": "$M{Address.NewYork}",
"shippingAddress": "$M{Address.NewYork}",
"userEmail": "$F{UserEmail}"
},
"DraftOrder:PricesWithTax:ShippingMethod": {
"deliveryMethodId": "$M{Channel.PricesWithTax.deliveryMethodId}"
},
"DraftOrder:PricesWithoutTax": {
"channelID": "$M{Channel.USA.id}"
},
"DraftOrder:PricesWithoutTax:ShippingMethod": {
"deliveryMethodId": "$M{Channel.USA.deliveryMethodId}"
},
"DraftOrder:VoucherCode": {
"voucherCode": "$M{Voucher.Percentage.code}"
}
}
}
28 changes: 27 additions & 1 deletion apps/avatax/e2e/graphql/fragments/OrderDetails.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,30 @@ fragment OrderDetailsFragment on Order {
...Money
}
}
}
undiscountedTotal {
gross {
...Money
}
net {
...Money
}
tax {
...Money
}
}
lines {
id
quantity
totalPrice {
gross {
...Money
}
net {
...Money
}
tax {
...Money
}
}
}
}
10 changes: 10 additions & 0 deletions apps/avatax/e2e/graphql/fragments/OrderDiscounts.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fragment Discounts on OrderDiscount {
name
reason
type
valueType
value
amount {
amount
}
}
6 changes: 3 additions & 3 deletions apps/avatax/e2e/graphql/mutations/CreateOrderLines.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mutation CreateOrderLines($variantId: ID!, $orderId: ID!) {
orderLinesCreate(id: $orderId, input: { quantity: 10, variantId: $variantId }) {
mutation CreateOrderLines($orderId: ID!, $input:[OrderLineCreateInput!]!) {
orderLinesCreate(id: $orderId, input: $input) {
order {
...OrderDetailsFragment
}
Expand All @@ -8,4 +8,4 @@ mutation CreateOrderLines($variantId: ID!, $orderId: ID!) {
quantity
}
}
}
}
14 changes: 14 additions & 0 deletions apps/avatax/e2e/graphql/mutations/DraftOrderUpdateVoucher.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mutation DraftOrderUpdateVoucher($orderId: ID!, $voucherCode: String) {
draftOrderUpdate(id: $orderId, input: {voucherCode: $voucherCode}) {
errors {
...OrderError
}
order {
...OrderDetailsFragment
voucherCode
discounts {
...Discounts
}
}
}
}
3 changes: 3 additions & 0 deletions apps/avatax/e2e/graphql/mutations/OrderAddDiscount.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ mutation OrderDiscountAdd($orderId: ID!, $input: OrderDiscountCommonInput!) {
}
order {
...OrderDetailsFragment
discounts {
...Discounts
}
}
}
}
10 changes: 10 additions & 0 deletions apps/avatax/e2e/graphql/mutations/OrderLineUpdate.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mutation OrderLineUpdate($lineId: ID!, $input: OrderLineInput!) {
orderLineUpdate(id: $lineId, input: $input) {
order {
...OrderDetailsFragment
discounts {
...Discounts
}
}
}
}
59 changes: 9 additions & 50 deletions apps/avatax/e2e/tests/checkout_address_change.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { e2e } from "pactum";
import { string } from "pactum-matchers";
import { describe, it } from "vitest";

import {
Expand All @@ -9,18 +8,14 @@ import {
CheckoutUpdateDeliveryMethod,
CompleteCheckout,
CreateCheckoutNoAddress,
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", () => {
const testCase = e2e("Checkout for product with tax class [pricesEnteredWithTax: True]");
const staffCredentials = {
email: process.env.E2E_USER_NAME as string,
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;
Expand Down Expand Up @@ -60,6 +55,7 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
tax: 0,
currency: CURRENCY,
}),
)
.stores("CheckoutId", "data.checkoutCreate.checkout.id");
Expand Down Expand Up @@ -88,6 +84,7 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: CURRENCY,
}),
);
});
Expand Down Expand Up @@ -117,6 +114,7 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: TOTAL_GROSS_PRICE_BEFORE_SHIPPING,
net: TOTAL_NET_PRICE_BEFORE_SHIPPING,
tax: TOTAL_TAX_PRICE_BEFORE_SHIPPING,
currency: CURRENCY,
}),
);
});
Expand All @@ -137,6 +135,7 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
}),
)
.expectJson(
Expand All @@ -145,6 +144,7 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
currency: CURRENCY,
}),
);
});
Expand All @@ -163,6 +163,7 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
}),
)
.expectJson(
Expand All @@ -171,51 +172,9 @@ describe("App should calculate taxes for checkout on update shipping address TC:
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
currency: CURRENCY,
}),
)
.stores("OrderID", "data.checkoutComplete.order.id");
});

/*
* It takes few seconds for metadata do be populated with `avataxId` key
* That's why we need to do it in a separate step
*/
it("creates token for staff user", async () => {
await testCase
.step("Create token for staff user")
.spec()
.post("/graphql/")
.withGraphQLQuery(StaffUserTokenCreate)
.withGraphQLVariables(staffCredentials)
.expectStatus(200)
.expectJsonLike({
data: {
tokenCreate: {
token: "typeof $V === 'string'",
},
},
})
.stores("StaffUserToken", "data.tokenCreate.token")
.retry();
});

it("should have metadata with 'avataxId' key", async () => {
await testCase
.step("Check if order has metadata with 'avataxId' key")
.spec()
.post("/graphql/")
.withGraphQLQuery(OrderDetails)
.withGraphQLVariables({
id: "$S{OrderID}",
})
.withHeaders({
Authorization: "Bearer $S{StaffUserToken}",
})
.expectStatus(200)
.expectJsonLike("data.order.metadata[key=avataxId]", {
key: "avataxId",
value: "typeof $V === 'string'",
})
.retry(4, 2000);
});
});
56 changes: 6 additions & 50 deletions apps/avatax/e2e/tests/checkout_basic_product_with_tax_code.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { e2e } from "pactum";
import { string } from "pactum-matchers";
import { describe, it } from "vitest";

import {
CheckoutUpdateDeliveryMethod,
CompleteCheckout,
CreateCheckout,
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", () => {
const testCase = e2e("Checkout for product with tax class [pricesEnteredWithTax: True]");
const staffCredentials = {
email: process.env.E2E_USER_NAME as string,
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 @@ -52,6 +46,7 @@ describe("App should calculate taxes for checkout with product with tax class TC
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");
Expand All @@ -73,6 +68,7 @@ describe("App should calculate taxes for checkout with product with tax class TC
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
}),
)
.expectJson(
Expand All @@ -81,6 +77,7 @@ describe("App should calculate taxes for checkout with product with tax class TC
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
currency: CURRENCY,
}),
);
});
Expand All @@ -99,6 +96,7 @@ describe("App should calculate taxes for checkout with product with tax class TC
gross: TOTAL_GROSS_PRICE_AFTER_SHIPPING,
net: TOTAL_NET_PRICE_AFTER_SHIPPING,
tax: TOTAL_TAX_PRICE_AFTER_SHIPPING,
currency: CURRENCY,
}),
)
.expectJson(
Expand All @@ -107,51 +105,9 @@ describe("App should calculate taxes for checkout with product with tax class TC
gross: SHIPPING_GROSS_PRICE,
net: SHIPPING_NET_PRICE,
tax: SHIPPING_TAX_PRICE,
currency: CURRENCY,
}),
)
.stores("OrderID", "data.checkoutComplete.order.id");
});

/*
* It takes few seconds for metadata do be populated with `avataxId` key
* That's why we need to do it in a separate step
*/
it("creates token for staff user", async () => {
await testCase
.step("Create token for staff user")
.spec()
.post("/graphql/")
.withGraphQLQuery(StaffUserTokenCreate)
.withGraphQLVariables(staffCredentials)
.expectStatus(200)
.expectJsonLike({
data: {
tokenCreate: {
token: "typeof $V === 'string'",
},
},
})
.stores("StaffUserToken", "data.tokenCreate.token")
.retry();
});

it("should have metadata with 'avataxId' key", async () => {
await testCase
.step("Check if order has metadata with 'avataxId' key")
.spec()
.post("/graphql/")
.withGraphQLQuery(OrderDetails)
.withGraphQLVariables({
id: "$S{OrderID}",
})
.withHeaders({
Authorization: "Bearer $S{StaffUserToken}",
})
.expectStatus(200)
.expectJsonLike("data.order.metadata[key=avataxId]", {
key: "avataxId",
value: "typeof $V === 'string'",
})
.retry(4, 2000);
});
});
Loading

0 comments on commit bd177cc

Please sign in to comment.