From d695bb9aa6327c2b680992a07146b01ad100eb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20Szcz=C4=99ch?= <30683248+szczecha@users.noreply.github.com> Date: Mon, 9 Jan 2023 10:55:12 +0100 Subject: [PATCH] Fix should make a refund 2107 (#2950) * get/update taxes for tests * update creating shipping and product of tax class --- cypress/e2e/orders/orders.js | 12 +++- cypress/support/api/requests/Product.js | 7 +++ .../support/api/requests/ShippingMethod.js | 8 +++ cypress/support/api/requests/Taxes.js | 59 +++++++++++++++++++ .../api/utils/products/productsUtils.js | 4 ++ cypress/support/api/utils/shippingUtils.js | 2 + cypress/support/api/utils/taxesUtils.js | 31 ++++++++++ 7 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 cypress/support/api/requests/Taxes.js create mode 100644 cypress/support/api/utils/taxesUtils.js diff --git a/cypress/e2e/orders/orders.js b/cypress/e2e/orders/orders.js index 65e13c334..3c2bdd0fc 100644 --- a/cypress/e2e/orders/orders.js +++ b/cypress/e2e/orders/orders.js @@ -28,6 +28,10 @@ import { createShipping, deleteShippingStartsWith, } from "../../support/api/utils/shippingUtils"; +import { + getDefaultTaxClass, + updateTaxConfigurationForChannel, +} from "../../support/api/utils/taxesUtils"; import { selectChannelInPicker } from "../../support/pages/channelsPage"; import { finalizeDraftOrder } from "../../support/pages/draftOrderPage"; @@ -41,6 +45,7 @@ describe("Orders", () => { let shippingMethod; let variantsList; let address; + let taxClass; before(() => { cy.clearSessionData().loginUserViaRequest(); @@ -52,8 +57,11 @@ describe("Orders", () => { getDefaultChannel() .then(channel => { defaultChannel = channel; + updateTaxConfigurationForChannel({ channelSlug: defaultChannel.slug }); + getDefaultTaxClass(); }) - .then(() => { + .then(resp => { + taxClass = resp; cy.fixture("addresses"); }) .then(addresses => { @@ -66,6 +74,7 @@ describe("Orders", () => { channelId: defaultChannel.id, name: randomName, address, + taxClassId: taxClass.id, }); }) .then( @@ -90,6 +99,7 @@ describe("Orders", () => { productTypeId: productTypeResp.id, attributeId: attributeResp.id, categoryId: categoryResp.id, + taxClassId: taxClass.id, }); }, ) diff --git a/cypress/support/api/requests/Product.js b/cypress/support/api/requests/Product.js index 755189e8b..9e39c966d 100644 --- a/cypress/support/api/requests/Product.js +++ b/cypress/support/api/requests/Product.js @@ -102,6 +102,7 @@ export function createProduct({ categoryId, collectionId, description, + taxClassId, }) { const collection = getValueWithDefault( collectionId, @@ -120,6 +121,11 @@ export function createProduct({ ${attributeValuesLine} }]`, ); + const selectedTaxClass = getValueWithDefault( + taxClassId, + `taxClass: "${taxClassId}"`, + `taxClass: ""`, + ); const mutation = `mutation createProduct${descriptionData.mutationVariables}{ productCreate(input:{ ${attributes} @@ -130,6 +136,7 @@ export function createProduct({ ${category} ${collection} ${descriptionData.descriptionLine} + ${selectedTaxClass} }){ product{ id diff --git a/cypress/support/api/requests/ShippingMethod.js b/cypress/support/api/requests/ShippingMethod.js index 024c5c08f..bcb733e3b 100644 --- a/cypress/support/api/requests/ShippingMethod.js +++ b/cypress/support/api/requests/ShippingMethod.js @@ -6,6 +6,7 @@ export function createShippingRate({ type = "PRICE", maxWeight, minWeight, + taxClassId, }) { const maxOrderWeight = getValueWithDefault( maxWeight, @@ -16,6 +17,12 @@ export function createShippingRate({ `minimumOrderWeight: ${minWeight}`, ); + const selectedTaxClass = getValueWithDefault( + taxClassId, + `taxClass: "${taxClassId}"`, + `taxClass: ""`, + ); + const mutation = `mutation{ shippingPriceCreate(input:{ name: "${name}" @@ -23,6 +30,7 @@ export function createShippingRate({ type: ${type} ${minOrderWeight} ${maxOrderWeight} + ${selectedTaxClass} }){ shippingMethod{ id diff --git a/cypress/support/api/requests/Taxes.js b/cypress/support/api/requests/Taxes.js new file mode 100644 index 000000000..3fbbd5a43 --- /dev/null +++ b/cypress/support/api/requests/Taxes.js @@ -0,0 +1,59 @@ +export function getTaxConfigurationList() { + const query = `query{ + taxConfigurations(first:100){ + edges{ + node{ + id + channel{ + id + slug + } + } + } + } + } + `; + return cy + .sendRequestWithQuery(query) + .then(resp => resp.body.data.taxConfigurations.edges); +} + +export function updateTaxes({ + id, + chargeTaxes = true, + taxCalculationStrategy = "FLAT_RATES", +}) { + const mutation = `mutation{ + taxConfigurationUpdate(id:"${id}", input:{ + chargeTaxes:${chargeTaxes} + displayGrossPrices:true + pricesEnteredWithTax:false + removeCountriesConfiguration: [] + taxCalculationStrategy:${taxCalculationStrategy} + updateCountriesConfiguration: [] + }){ + errors{ + field + message + } + } + }`; + return cy.sendRequestWithQuery(mutation); +} + +export function getTaxClassList() { + const query = `query{ + taxClasses(first:100){ + edges{ + node{ + id + name + } + } + } + } + `; + return cy + .sendRequestWithQuery(query) + .then(resp => resp.body.data.taxClasses.edges); +} diff --git a/cypress/support/api/utils/products/productsUtils.js b/cypress/support/api/utils/products/productsUtils.js index 41aca414a..b66e597c8 100644 --- a/cypress/support/api/utils/products/productsUtils.js +++ b/cypress/support/api/utils/products/productsUtils.js @@ -35,6 +35,7 @@ export function createProductInChannel({ trackInventory = true, weight = 1, sku = name, + taxClassId, }) { let product; let variantsList; @@ -49,6 +50,7 @@ export function createProductInChannel({ visibleInListings, collectionId, description, + taxClassId, }) .then(productResp => { product = productResp; @@ -263,6 +265,7 @@ export function createProductInChannelWithoutVariants({ visibleInListings = true, collectionId = null, description = null, + taxClassId, }) { let product; return productRequest @@ -273,6 +276,7 @@ export function createProductInChannelWithoutVariants({ categoryId, collectionId, description, + taxClassId, }) .then(productResp => { product = productResp; diff --git a/cypress/support/api/utils/shippingUtils.js b/cypress/support/api/utils/shippingUtils.js index 0793e2d83..cf252cc05 100644 --- a/cypress/support/api/utils/shippingUtils.js +++ b/cypress/support/api/utils/shippingUtils.js @@ -9,6 +9,7 @@ export function createShipping({ address, price = 1, minProductPrice = 0, + taxClassId, }) { let shippingMethod; let shippingZone; @@ -31,6 +32,7 @@ export function createShipping({ shippingMethodRequest.createShippingRate({ name, shippingZone: shippingZone.id, + taxClassId, }); }); }) diff --git a/cypress/support/api/utils/taxesUtils.js b/cypress/support/api/utils/taxesUtils.js new file mode 100644 index 000000000..9ba0bf740 --- /dev/null +++ b/cypress/support/api/utils/taxesUtils.js @@ -0,0 +1,31 @@ +import { + getTaxClassList, + getTaxConfigurationList, + updateTaxes, +} from "../requests/Taxes"; + +export function updateTaxConfigurationForChannel({ + channelSlug, + chargeTaxes = true, + taxCalculationStrategy = "FLAT_RATES", +}) { + getTaxConfigurationList().then(taxConfigurationList => { + const taxConfigurationForChannel = taxConfigurationList.find( + taxConfiguration => taxConfiguration.node.channel.slug === channelSlug, + ); + updateTaxes({ + id: taxConfigurationForChannel.node.id, + chargeTaxes, + taxCalculationStrategy, + }); + }); +} + +export function getDefaultTaxClass() { + getTaxClassList().then(taxClassArray => { + const taxClass = taxClassArray.find( + taxClassItem => taxClassItem.node.name === "No Taxes", + ); + return taxClass.node; + }); +}