Fix should make a refund 2107 (#2950)

* get/update taxes for tests

* update creating shipping and product of tax class
This commit is contained in:
Anna Szczęch 2023-01-09 10:55:12 +01:00 committed by GitHub
parent 91478a8b6d
commit d695bb9aa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 122 additions and 1 deletions

View file

@ -28,6 +28,10 @@ import {
createShipping, createShipping,
deleteShippingStartsWith, deleteShippingStartsWith,
} from "../../support/api/utils/shippingUtils"; } from "../../support/api/utils/shippingUtils";
import {
getDefaultTaxClass,
updateTaxConfigurationForChannel,
} from "../../support/api/utils/taxesUtils";
import { selectChannelInPicker } from "../../support/pages/channelsPage"; import { selectChannelInPicker } from "../../support/pages/channelsPage";
import { finalizeDraftOrder } from "../../support/pages/draftOrderPage"; import { finalizeDraftOrder } from "../../support/pages/draftOrderPage";
@ -41,6 +45,7 @@ describe("Orders", () => {
let shippingMethod; let shippingMethod;
let variantsList; let variantsList;
let address; let address;
let taxClass;
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
@ -52,8 +57,11 @@ describe("Orders", () => {
getDefaultChannel() getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
updateTaxConfigurationForChannel({ channelSlug: defaultChannel.slug });
getDefaultTaxClass();
}) })
.then(() => { .then(resp => {
taxClass = resp;
cy.fixture("addresses"); cy.fixture("addresses");
}) })
.then(addresses => { .then(addresses => {
@ -66,6 +74,7 @@ describe("Orders", () => {
channelId: defaultChannel.id, channelId: defaultChannel.id,
name: randomName, name: randomName,
address, address,
taxClassId: taxClass.id,
}); });
}) })
.then( .then(
@ -90,6 +99,7 @@ describe("Orders", () => {
productTypeId: productTypeResp.id, productTypeId: productTypeResp.id,
attributeId: attributeResp.id, attributeId: attributeResp.id,
categoryId: categoryResp.id, categoryId: categoryResp.id,
taxClassId: taxClass.id,
}); });
}, },
) )

View file

@ -102,6 +102,7 @@ export function createProduct({
categoryId, categoryId,
collectionId, collectionId,
description, description,
taxClassId,
}) { }) {
const collection = getValueWithDefault( const collection = getValueWithDefault(
collectionId, collectionId,
@ -120,6 +121,11 @@ export function createProduct({
${attributeValuesLine} ${attributeValuesLine}
}]`, }]`,
); );
const selectedTaxClass = getValueWithDefault(
taxClassId,
`taxClass: "${taxClassId}"`,
`taxClass: ""`,
);
const mutation = `mutation createProduct${descriptionData.mutationVariables}{ const mutation = `mutation createProduct${descriptionData.mutationVariables}{
productCreate(input:{ productCreate(input:{
${attributes} ${attributes}
@ -130,6 +136,7 @@ export function createProduct({
${category} ${category}
${collection} ${collection}
${descriptionData.descriptionLine} ${descriptionData.descriptionLine}
${selectedTaxClass}
}){ }){
product{ product{
id id

View file

@ -6,6 +6,7 @@ export function createShippingRate({
type = "PRICE", type = "PRICE",
maxWeight, maxWeight,
minWeight, minWeight,
taxClassId,
}) { }) {
const maxOrderWeight = getValueWithDefault( const maxOrderWeight = getValueWithDefault(
maxWeight, maxWeight,
@ -16,6 +17,12 @@ export function createShippingRate({
`minimumOrderWeight: ${minWeight}`, `minimumOrderWeight: ${minWeight}`,
); );
const selectedTaxClass = getValueWithDefault(
taxClassId,
`taxClass: "${taxClassId}"`,
`taxClass: ""`,
);
const mutation = `mutation{ const mutation = `mutation{
shippingPriceCreate(input:{ shippingPriceCreate(input:{
name: "${name}" name: "${name}"
@ -23,6 +30,7 @@ export function createShippingRate({
type: ${type} type: ${type}
${minOrderWeight} ${minOrderWeight}
${maxOrderWeight} ${maxOrderWeight}
${selectedTaxClass}
}){ }){
shippingMethod{ shippingMethod{
id id

View file

@ -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);
}

View file

@ -35,6 +35,7 @@ export function createProductInChannel({
trackInventory = true, trackInventory = true,
weight = 1, weight = 1,
sku = name, sku = name,
taxClassId,
}) { }) {
let product; let product;
let variantsList; let variantsList;
@ -49,6 +50,7 @@ export function createProductInChannel({
visibleInListings, visibleInListings,
collectionId, collectionId,
description, description,
taxClassId,
}) })
.then(productResp => { .then(productResp => {
product = productResp; product = productResp;
@ -263,6 +265,7 @@ export function createProductInChannelWithoutVariants({
visibleInListings = true, visibleInListings = true,
collectionId = null, collectionId = null,
description = null, description = null,
taxClassId,
}) { }) {
let product; let product;
return productRequest return productRequest
@ -273,6 +276,7 @@ export function createProductInChannelWithoutVariants({
categoryId, categoryId,
collectionId, collectionId,
description, description,
taxClassId,
}) })
.then(productResp => { .then(productResp => {
product = productResp; product = productResp;

View file

@ -9,6 +9,7 @@ export function createShipping({
address, address,
price = 1, price = 1,
minProductPrice = 0, minProductPrice = 0,
taxClassId,
}) { }) {
let shippingMethod; let shippingMethod;
let shippingZone; let shippingZone;
@ -31,6 +32,7 @@ export function createShipping({
shippingMethodRequest.createShippingRate({ shippingMethodRequest.createShippingRate({
name, name,
shippingZone: shippingZone.id, shippingZone: shippingZone.id,
taxClassId,
}); });
}); });
}) })

View file

@ -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;
});
}