Fix cypress tests (#1541)

* fix tests

* fix base url

* fix varinats tests
This commit is contained in:
Karolina Rakoczy 2021-11-03 12:15:39 +01:00 committed by GitHub
parent b0369bf5ca
commit 80809a078a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 290 additions and 212 deletions

View file

@ -0,0 +1,233 @@
/// <reference types="cypress"/>
/// <reference types="../../support"/>
import faker from "faker";
import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details";
import {
completeCheckout,
createCheckout,
deliveryMethodUpdate
} from "../../support/api/requests/Checkout";
import { getOrder } from "../../support/api/requests/Order";
import { updateWarehouse } from "../../support/api/requests/Warehouse";
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
import { addPayment } from "../../support/api/utils/ordersUtils";
import {
createProductInChannel,
createTypeAttributeAndCategoryForProduct,
deleteProductsStartsWith
} from "../../support/api/utils/products/productsUtils";
import {
createShipping,
deleteShippingStartsWith
} from "../../support/api/utils/shippingUtils";
import filterTests from "../../support/filterTests";
import {
createWarehouse,
pickupOptions,
visitAndEnablePickup,
visitSetPublicStockAndEnablePickup
} from "../../support/pages/warehousePage";
filterTests({ definedTags: ["all"], version: "3.1.0" }, () => {
describe("Warehouses in checkout", () => {
const startsWith = `CyWarehouseCheckout`;
let defaultChannel;
let usAddress;
let secondUsAddress;
let plAddress;
let productData;
let checkoutData;
let variantsInOtherWarehouse;
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteShippingStartsWith(startsWith);
deleteProductsStartsWith(startsWith);
cy.fixture("addresses")
.then(addresses => {
usAddress = addresses.usAddress;
secondUsAddress = addresses.secondUsAddress;
plAddress = addresses.plAddress;
getDefaultChannel();
})
.then(channelResp => {
defaultChannel = channelResp;
createTypeAttributeAndCategoryForProduct({ name: startsWith });
})
.then(({ attribute, productType, category }) => {
productData = {
attributeId: attribute.id,
categoryId: category.id,
channelId: defaultChannel.id,
productTypeId: productType.id,
quantityInWarehouse: 100
};
checkoutData = {
returnAvailableCollectionPoints: true,
channelSlug: defaultChannel.slug,
email: "example@example.com",
address: secondUsAddress
};
createShipping({
channelId: defaultChannel.id,
name: startsWith,
address: secondUsAddress
});
})
.then(({ warehouse: warehouseResp }) => {
productData.name = startsWith;
productData.warehouseId = warehouseResp.id;
updateWarehouse({ id: productData.warehouseId, isPrivate: false });
createProductInChannel(productData);
})
.then(({ variantsList }) => {
variantsInOtherWarehouse = variantsList;
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should create warehouse with all warehouses pickup and private stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
createShipping({
channelId: defaultChannel.id,
name,
address: secondUsAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
visitAndEnablePickup(warehouse.id);
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
checkoutData.variantsList = variantsList.concat(
variantsInOtherWarehouse
);
createCheckout(checkoutData);
})
.then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints.find(
element => element.id === warehouse.id
);
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(true);
expect(clickAndCollectOption.name).to.eq(warehouse.name);
});
});
it("should create warehouse with all warehouses pickup and public stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
createShipping({
channelId: defaultChannel.id,
name,
address: secondUsAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
visitSetPublicStockAndEnablePickup(warehouse.id);
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
checkoutData.variantsList = variantsList.concat(
variantsInOtherWarehouse
);
createCheckout(checkoutData);
})
.then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints.find(
element => element.id === warehouse.id
);
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(false);
expect(clickAndCollectOption.name).to.eq(warehouse.name);
});
});
it("should create warehouse with local stock only pickup and public stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
let variantsInLocalStock;
createShipping({
channelId: defaultChannel.id,
name,
address: secondUsAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
visitSetPublicStockAndEnablePickup(warehouse.id, pickupOptions.local);
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
variantsInLocalStock = variantsList;
checkoutData.variantsList = variantsInLocalStock.concat(
variantsInOtherWarehouse
);
createCheckout(checkoutData);
})
.then(({ checkout }) => {
expect(checkout.availableCollectionPoints).to.have.length(
1,
"there should be no available collection point for local stock"
);
checkoutData.variantsList = variantsInLocalStock;
createCheckout(checkoutData);
})
.then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints[0];
expect(clickAndCollectOption.clickAndCollectOption).to.eq("LOCAL");
expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(false);
expect(clickAndCollectOption.name).to.eq(warehouse.name);
});
});
it("should not be possible to set local pickup when private stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
createWarehouse({ name, address: usAddress });
cy.get(WAREHOUSES_DETAILS.clickAndCollectLocalStockRadioButton).should(
"not.exist"
);
});
it("should create order with warehouse address", () => {
let checkout;
checkoutData.variantsList = variantsInOtherWarehouse;
createCheckout(checkoutData)
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
const clickAndCollectOption = checkout.availableCollectionPoints[0];
deliveryMethodUpdate(clickAndCollectOption.id, checkout.token);
})
.then(() => {
addPayment(checkout.id);
})
.then(() => {
completeCheckout(checkout.id);
})
.then(({ order }) => {
getOrder(order.id);
})
.then(order => {
cy.expectCorrectBasicAddress(order.shippingAddress, secondUsAddress);
cy.expectCorrectBasicAddress(order.billingAddress, usAddress);
});
});
});
});

View file

@ -3,16 +3,8 @@
import faker from "faker";
import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details";
import {
completeCheckout,
createCheckout,
deliveryMethodUpdate
} from "../../support/api/requests/Checkout";
import { getOrder } from "../../support/api/requests/Order";
import { updateWarehouse } from "../../support/api/requests/Warehouse";
import { createCheckout } from "../../support/api/requests/Checkout";
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
import { addPayment } from "../../support/api/utils/ordersUtils";
import {
createProductInChannel,
createTypeAttributeAndCategoryForProduct,
@ -23,232 +15,56 @@ import {
deleteShippingStartsWith
} from "../../support/api/utils/shippingUtils";
import filterTests from "../../support/filterTests";
import {
createWarehouse,
pickupOptions,
visitAndEnablePickup,
visitSetPublicStockAndEnablePickup
} from "../../support/pages/warehousePage";
filterTests({ definedTags: ["all"] }, () => {
describe("Warehouses in checkout", () => {
const startsWith = `CyWarehouseCheckout`;
let defaultChannel;
let usAddress;
let secondUsAddress;
let plAddress;
let productData;
let checkoutData;
let variantsInOtherWarehouse;
let warehouse;
before(() => {
it("should not be possible to buy product for country not listed in warehouse", () => {
cy.clearSessionData().loginUserViaRequest();
deleteShippingStartsWith(startsWith);
deleteProductsStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
cy.fixture("addresses")
.then(addresses => {
usAddress = addresses.usAddress;
secondUsAddress = addresses.secondUsAddress;
plAddress = addresses.plAddress;
getDefaultChannel();
})
.then(channelResp => {
defaultChannel = channelResp;
createTypeAttributeAndCategoryForProduct({ name: startsWith });
createShipping({
channelId: defaultChannel.id,
name,
address: usAddress
});
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
createTypeAttributeAndCategoryForProduct({ name });
})
.then(({ attribute, productType, category }) => {
productData = {
createProductInChannel({
name,
attributeId: attribute.id,
categoryId: category.id,
channelId: defaultChannel.id,
productTypeId: productType.id,
warehouseId: warehouse.id,
quantityInWarehouse: 100
};
checkoutData = {
returnAvailableCollectionPoints: true,
channelSlug: defaultChannel.slug,
email: "example@example.com",
address: secondUsAddress
};
createShipping({
channelId: defaultChannel.id,
name: startsWith,
address: secondUsAddress
});
})
.then(({ warehouse: warehouseResp }) => {
productData.name = startsWith;
productData.warehouseId = warehouseResp.id;
updateWarehouse({ id: productData.warehouseId, isPrivate: false });
createProductInChannel(productData);
})
.then(({ variantsList }) => {
variantsInOtherWarehouse = variantsList;
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
});
it("should create warehouse with all warehouses pickup and private stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
createShipping({
channelId: defaultChannel.id,
name,
address: secondUsAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
visitAndEnablePickup(warehouse.id);
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
checkoutData.variantsList = variantsList.concat(
variantsInOtherWarehouse
);
createCheckout(checkoutData);
})
.then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints.find(
element => element.id === warehouse.id
);
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(true);
expect(clickAndCollectOption.name).to.eq(warehouse.name);
});
});
it("should create warehouse with all warehouses pickup and public stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
createShipping({
channelId: defaultChannel.id,
name,
address: secondUsAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
visitSetPublicStockAndEnablePickup(warehouse.id);
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
checkoutData.variantsList = variantsList.concat(
variantsInOtherWarehouse
);
createCheckout(checkoutData);
})
.then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints.find(
element => element.id === warehouse.id
);
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(false);
expect(clickAndCollectOption.name).to.eq(warehouse.name);
});
});
it("should create warehouse with local stock only pickup and public stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
let variantsInLocalStock;
createShipping({
channelId: defaultChannel.id,
name,
address: secondUsAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
visitSetPublicStockAndEnablePickup(warehouse.id, pickupOptions.local);
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
variantsInLocalStock = variantsList;
checkoutData.variantsList = variantsInLocalStock.concat(
variantsInOtherWarehouse
);
createCheckout(checkoutData);
})
.then(({ checkout }) => {
expect(checkout.availableCollectionPoints).to.have.length(
1,
"there should be no available collection point for local stock"
);
checkoutData.variantsList = variantsInLocalStock;
createCheckout(checkoutData);
})
.then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints[0];
expect(clickAndCollectOption.clickAndCollectOption).to.eq("LOCAL");
expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(false);
expect(clickAndCollectOption.name).to.eq(warehouse.name);
});
});
it("should not be possible to set local pickup when private stock", () => {
const name = `${startsWith}${faker.datatype.number()}`;
createWarehouse({ name, address: usAddress });
cy.get(WAREHOUSES_DETAILS.clickAndCollectLocalStockRadioButton).should(
"not.exist"
);
});
it("should create order with warehouse address", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let checkout;
checkoutData.variantsList = variantsInOtherWarehouse;
createCheckout(checkoutData)
.then(({ checkout: checkoutResp }) => {
checkout = checkoutResp;
const clickAndCollectOption = checkout.availableCollectionPoints[0];
deliveryMethodUpdate(clickAndCollectOption.id, checkout.token);
})
.then(() => {
addPayment(checkout.id);
})
.then(() => {
completeCheckout(checkout.id);
})
.then(({ order }) => {
getOrder(order.id);
})
.then(order => {
cy.expectCorrectBasicAddress(order.shippingAddress, secondUsAddress);
cy.expectCorrectBasicAddress(order.billingAddress, usAddress);
});
});
it("should not be possible to buy product for country not listed in warehouse", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
createShipping({
channelId: defaultChannel.id,
name,
address: plAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
checkoutData.variantsList = variantsList;
createCheckout(checkoutData);
createCheckout({
channelSlug: defaultChannel.slug,
email: "example@example.com",
variantsList,
address: plAddress
});
})
.then(({ errors }) => {
expect(errors[0]).to.have.property("field", "quantity");

View file

@ -58,7 +58,7 @@ filterTests({ definedTags: ["all", "critical"] }, () => {
)
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
createChannel({ isActive: true, name, currencyCode: "PLN" });
createChannel({ isActive: true, name, currencyCode: "USD" });
})
.then(resp => (newChannel = resp));

View file

@ -81,7 +81,7 @@ filterTests({ definedTags: ["stagedOnly"] }, () => {
tokenCreate.errors[0].code,
"logging in should return error"
)
.to.be.eq("INVALID_CREDENTIALS");
.to.be.eq("INACTIVE");
expect(tokenCreate.token).to.be.not.ok;
});
});

View file

@ -43,6 +43,23 @@ export function createTypeProduct({
.its("body.data.productTypeCreate.productType");
}
export function productAttributeAssignmentUpdate({
productTypeId,
attributeId,
variantSelection = true
}) {
const mutation = `mutation {
productAttributeAssignmentUpdate(
operations: {id: "${attributeId}", variantSelection: ${variantSelection}} productTypeId:"${productTypeId}") {
errors {
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function getProductTypes(first, search) {
const query = `query{
productTypes(first:${first}, filter:{

View file

@ -1,3 +1,4 @@
import { returnValueDependsOnShopVersion } from "../../../formatData/dataDependingOnVersion";
import * as attributeRequest from "../../requests/Attribute";
import * as categoryRequest from "../../requests/Category";
import { createCollection } from "../../requests/Collections";
@ -5,7 +6,8 @@ import * as productRequest from "../../requests/Product";
import {
createTypeProduct,
deleteProductType,
getProductTypes
getProductTypes,
productAttributeAssignmentUpdate
} from "../../requests/ProductType";
import { deleteAttributesStartsWith } from "../attributes/attributeUtils";
import { deleteCollectionsStartsWith } from "../catalog/collectionsUtils";
@ -85,6 +87,13 @@ export function createTypeAttributeAndCategoryForProduct({
})
.then(productTypeResp => {
productType = productTypeResp;
const updateAssign = returnValueDependsOnShopVersion("3.1", true, false);
if (updateAssign) {
productAttributeAssignmentUpdate({
productTypeId: productType.id,
attributeId: attribute.id
});
}
categoryRequest.createCategory(name);
})
.then(categoryResp => {

View file

@ -62,9 +62,12 @@ export function createVariant({
cy.get(VARIANTS_SELECTORS.saveButton)
.click()
.get(BUTTON_SELECTORS.back)
.click();
.click()
.addAliasToGraphRequest("ProductChannelListingUpdate");
selectChannelVariantInDetailsPage(channelName, attributeName);
cy.get(BUTTON_SELECTORS.confirm).click();
cy.get(BUTTON_SELECTORS.confirm)
.click()
.waitForRequestAndCheckIfNoErrors("@ProductChannelListingUpdate");
cy.contains(PRODUCT_DETAILS.variantRow, attributeName)
.click()
.get(PRICE_LIST.priceInput)

View file

@ -99,7 +99,7 @@ export function selectChannelVariantInDetailsPage(channelName, attributeName) {
.click();
cy.get(SELECT_CHANNELS_TO_ASSIGN.selectChannelsForm)
.find(BUTTON_SELECTORS.submit)
.click();
.click({ force: true });
}
export function enterHomePageAndChangeChannel(channelName) {