tests for warehouses in checkout (#1379)

* tests for warehouses in checkout

* fix puchase product with type
This commit is contained in:
Karolina Rakoczy 2021-10-05 13:46:58 +02:00 committed by GitHub
parent 547f5f7c3e
commit f7b452cb12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 243 additions and 26 deletions

View file

@ -1,3 +1,9 @@
export const WAREHOUSES_DETAILS = {
nameInput: '[name="name"]'
nameInput: '[name="name"]',
privateRadioButton: '[name="isPrivate"][value=true]',
publicRadioButton: '[name="isPrivate"][value=false]',
clickAndCollectAllWarehousesRadioButton:
'[name="clickAndCollectOption"][value="ALL"]',
clickAndCollectLocalStockRadioButton:
'[name="clickAndCollectOption"][value="LOCAL"]'
};

View file

@ -15,6 +15,11 @@ import {
deleteShippingStartsWith
} from "../../support/api/utils/shippingUtils";
import filterTests from "../../support/filterTests";
import {
pickupOptions,
visitAndEnablePickup,
visitSetPublicStockAndEnablePickup
} from "../../support/pages/warehousePage";
filterTests({ definedTags: ["all"] }, () => {
describe("Warehouses in checkout", () => {
@ -22,13 +27,14 @@ filterTests({ definedTags: ["all"] }, () => {
let defaultChannel;
let usAddress;
let plAddress;
let warehouse;
let productData;
let checkoutData;
let variantsInOtherWarehouse;
it("should not be possible to buy product for country not listed in warehouse", () => {
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteShippingStartsWith(startsWith);
deleteProductsStartsWith(startsWith);
const name = `${startsWith}${faker.datatype.number()}`;
cy.fixture("addresses")
.then(addresses => {
usAddress = addresses.usAddress;
@ -37,35 +43,164 @@ filterTests({ definedTags: ["all"] }, () => {
})
.then(channelResp => {
defaultChannel = channelResp;
createShipping({
channelId: defaultChannel.id,
name,
address: usAddress
});
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
createTypeAttributeAndCategoryForProduct({ name });
createTypeAttributeAndCategoryForProduct({ name: startsWith });
})
.then(({ attribute, productType, category }) => {
createProductInChannel({
name,
productData = {
attributeId: attribute.id,
categoryId: category.id,
channelId: defaultChannel.id,
productTypeId: productType.id,
warehouseId: warehouse.id,
quantityInWarehouse: 100
});
})
.then(({ variantsList }) => {
createCheckout({
};
checkoutData = {
returnAvailableCollectionPoints: true,
channelSlug: defaultChannel.slug,
email: "example@example.com",
variantsList,
address: plAddress
};
createShipping({
channelId: defaultChannel.id,
name: startsWith,
address: plAddress
});
})
.then(({ warehouse: warehouseResp }) => {
productData.name = startsWith;
productData.warehouseId = warehouseResp.id;
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: plAddress
})
.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[0];
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: plAddress
})
.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[0];
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: plAddress
})
.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(
0,
"there should be no available collection point"
);
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 buy product for country not listed in warehouse", () => {
const name = `${startsWith}${faker.datatype.number()}`;
let warehouse;
createShipping({
channelId: defaultChannel.id,
name,
address: usAddress
})
.then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
productData.name = name;
productData.warehouseId = warehouse.id;
createProductInChannel(productData);
})
.then(({ variantsList }) => {
checkoutData.variantsList = variantsList;
createCheckout(checkoutData);
})
.then(({ errors }) => {
expect(errors[0]).to.have.property("field", "quantity");
});

View file

@ -14,7 +14,7 @@ import {
} from "../../fixtures/urlList";
import { createShippingZone } from "../../support/api/requests/ShippingMethod";
import {
createWarehouse,
createWarehouse as createWarehouseViaApi,
getWarehouse
} from "../../support/api/requests/Warehouse";
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
@ -70,7 +70,7 @@ filterTests({ definedTags: ["all"] }, () => {
getDefaultChannel()
.then(channelResp => {
defaultChannel = channelResp;
createWarehouse({
createWarehouseViaApi({
name,
address: usAddress
});
@ -101,7 +101,7 @@ filterTests({ definedTags: ["all"] }, () => {
it("should delete warehouse", () => {
const name = `${startsWith}${faker.datatype.number()}`;
createWarehouse({
createWarehouseViaApi({
name,
address: usAddress
}).then(warehouse => {

View file

@ -12,7 +12,8 @@ export function createCheckout({
variantsList,
address,
billingAddress,
auth = "auth"
auth = "auth",
returnAvailableCollectionPoints = false
}) {
const lines = getVariantsLines(variantsList, productQuantity);
const shippingAddress = getDefaultAddress(address, "shippingAddress");
@ -21,6 +22,16 @@ export function createCheckout({
"billingAddress"
);
const availableCollectionPointsLines = getValueWithDefault(
returnAvailableCollectionPoints,
`availableCollectionPoints{
id
name
clickAndCollectOption
isPrivate
}`
);
const mutation = `mutation{
checkoutCreate(input:{
channel:"${channelSlug}"
@ -33,13 +44,13 @@ export function createCheckout({
field
message
}
created
checkout{
id
availableShippingMethods{
name
}
${availableCollectionPointsLines}
}
}
}`;

View file

@ -62,6 +62,7 @@ export function getWarehouse(warehouseId) {
warehouse(id:"${warehouseId}"){
id
name
clickAndCollectOption
address{
companyName
streetAddress1

View file

@ -0,0 +1,64 @@
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details";
import { WAREHOUSES_LIST } from "../../elements/warehouses/warehouses-list";
import { urlList, warehouseDetailsUrl } from "../../fixtures/urlList";
export function createWarehouse({ name, address }) {
return cy
.visit(urlList.warehouses)
.get(WAREHOUSES_LIST.createNewButton)
.click()
.get(WAREHOUSES_DETAILS.nameInput)
.type(name)
.fillUpBasicAddress(address)
.addAliasToGraphRequest("WarehouseCreate")
.get(BUTTON_SELECTORS.confirm)
.click()
.wait("@WarehouseCreate")
.its("response.body.data.createWarehouse.warehouse");
}
export function visitAndEnablePickup(
warehouseId,
pickup = enableAllWarehousesPickup
) {
cy.visit(warehouseDetailsUrl(warehouseId));
pickup();
return saveWarehouseAfterUpdate();
}
export function visitSetPublicStockAndEnablePickup(
warehouseId,
pickup = enableAllWarehousesPickup
) {
cy.visit(warehouseDetailsUrl(warehouseId))
.get(WAREHOUSES_DETAILS.publicRadioButton)
.click();
pickup();
return saveWarehouseAfterUpdate();
}
export function enableAllWarehousesPickup() {
return cy
.get(WAREHOUSES_DETAILS.clickAndCollectAllWarehousesRadioButton)
.click();
}
export function enableLocalStockOnlyPickup() {
return cy
.get(WAREHOUSES_DETAILS.clickAndCollectLocalStockRadioButton)
.click();
}
function saveWarehouseAfterUpdate() {
return cy
.addAliasToGraphRequest("WarehouseUpdate")
.get(BUTTON_SELECTORS.confirm)
.click()
.wait("@WarehouseUpdate");
}
export const pickupOptions = {
allWarehouses: enableAllWarehousesPickup,
local: enableLocalStockOnlyPickup
};