tests for warehouses in checkout (#1379)
* tests for warehouses in checkout * fix puchase product with type
This commit is contained in:
parent
547f5f7c3e
commit
f7b452cb12
6 changed files with 243 additions and 26 deletions
|
@ -1,3 +1,9 @@
|
||||||
export const WAREHOUSES_DETAILS = {
|
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"]'
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,11 @@ import {
|
||||||
deleteShippingStartsWith
|
deleteShippingStartsWith
|
||||||
} from "../../support/api/utils/shippingUtils";
|
} from "../../support/api/utils/shippingUtils";
|
||||||
import filterTests from "../../support/filterTests";
|
import filterTests from "../../support/filterTests";
|
||||||
|
import {
|
||||||
|
pickupOptions,
|
||||||
|
visitAndEnablePickup,
|
||||||
|
visitSetPublicStockAndEnablePickup
|
||||||
|
} from "../../support/pages/warehousePage";
|
||||||
|
|
||||||
filterTests({ definedTags: ["all"] }, () => {
|
filterTests({ definedTags: ["all"] }, () => {
|
||||||
describe("Warehouses in checkout", () => {
|
describe("Warehouses in checkout", () => {
|
||||||
|
@ -22,13 +27,14 @@ filterTests({ definedTags: ["all"] }, () => {
|
||||||
let defaultChannel;
|
let defaultChannel;
|
||||||
let usAddress;
|
let usAddress;
|
||||||
let plAddress;
|
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();
|
cy.clearSessionData().loginUserViaRequest();
|
||||||
deleteShippingStartsWith(startsWith);
|
deleteShippingStartsWith(startsWith);
|
||||||
deleteProductsStartsWith(startsWith);
|
deleteProductsStartsWith(startsWith);
|
||||||
const name = `${startsWith}${faker.datatype.number()}`;
|
|
||||||
cy.fixture("addresses")
|
cy.fixture("addresses")
|
||||||
.then(addresses => {
|
.then(addresses => {
|
||||||
usAddress = addresses.usAddress;
|
usAddress = addresses.usAddress;
|
||||||
|
@ -37,35 +43,164 @@ filterTests({ definedTags: ["all"] }, () => {
|
||||||
})
|
})
|
||||||
.then(channelResp => {
|
.then(channelResp => {
|
||||||
defaultChannel = channelResp;
|
defaultChannel = channelResp;
|
||||||
createShipping({
|
createTypeAttributeAndCategoryForProduct({ name: startsWith });
|
||||||
channelId: defaultChannel.id,
|
|
||||||
name,
|
|
||||||
address: usAddress
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(({ warehouse: warehouseResp }) => {
|
|
||||||
warehouse = warehouseResp;
|
|
||||||
createTypeAttributeAndCategoryForProduct({ name });
|
|
||||||
})
|
})
|
||||||
.then(({ attribute, productType, category }) => {
|
.then(({ attribute, productType, category }) => {
|
||||||
createProductInChannel({
|
productData = {
|
||||||
name,
|
|
||||||
attributeId: attribute.id,
|
attributeId: attribute.id,
|
||||||
categoryId: category.id,
|
categoryId: category.id,
|
||||||
channelId: defaultChannel.id,
|
channelId: defaultChannel.id,
|
||||||
productTypeId: productType.id,
|
productTypeId: productType.id,
|
||||||
warehouseId: warehouse.id,
|
|
||||||
quantityInWarehouse: 100
|
quantityInWarehouse: 100
|
||||||
});
|
};
|
||||||
})
|
checkoutData = {
|
||||||
.then(({ variantsList }) => {
|
returnAvailableCollectionPoints: true,
|
||||||
createCheckout({
|
|
||||||
channelSlug: defaultChannel.slug,
|
channelSlug: defaultChannel.slug,
|
||||||
email: "example@example.com",
|
email: "example@example.com",
|
||||||
variantsList,
|
address: plAddress
|
||||||
|
};
|
||||||
|
createShipping({
|
||||||
|
channelId: defaultChannel.id,
|
||||||
|
name: startsWith,
|
||||||
address: plAddress
|
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 }) => {
|
.then(({ errors }) => {
|
||||||
expect(errors[0]).to.have.property("field", "quantity");
|
expect(errors[0]).to.have.property("field", "quantity");
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
} from "../../fixtures/urlList";
|
} from "../../fixtures/urlList";
|
||||||
import { createShippingZone } from "../../support/api/requests/ShippingMethod";
|
import { createShippingZone } from "../../support/api/requests/ShippingMethod";
|
||||||
import {
|
import {
|
||||||
createWarehouse,
|
createWarehouse as createWarehouseViaApi,
|
||||||
getWarehouse
|
getWarehouse
|
||||||
} from "../../support/api/requests/Warehouse";
|
} from "../../support/api/requests/Warehouse";
|
||||||
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
import { getDefaultChannel } from "../../support/api/utils/channelsUtils";
|
||||||
|
@ -70,7 +70,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
||||||
getDefaultChannel()
|
getDefaultChannel()
|
||||||
.then(channelResp => {
|
.then(channelResp => {
|
||||||
defaultChannel = channelResp;
|
defaultChannel = channelResp;
|
||||||
createWarehouse({
|
createWarehouseViaApi({
|
||||||
name,
|
name,
|
||||||
address: usAddress
|
address: usAddress
|
||||||
});
|
});
|
||||||
|
@ -101,7 +101,7 @@ filterTests({ definedTags: ["all"] }, () => {
|
||||||
|
|
||||||
it("should delete warehouse", () => {
|
it("should delete warehouse", () => {
|
||||||
const name = `${startsWith}${faker.datatype.number()}`;
|
const name = `${startsWith}${faker.datatype.number()}`;
|
||||||
createWarehouse({
|
createWarehouseViaApi({
|
||||||
name,
|
name,
|
||||||
address: usAddress
|
address: usAddress
|
||||||
}).then(warehouse => {
|
}).then(warehouse => {
|
||||||
|
|
|
@ -12,7 +12,8 @@ export function createCheckout({
|
||||||
variantsList,
|
variantsList,
|
||||||
address,
|
address,
|
||||||
billingAddress,
|
billingAddress,
|
||||||
auth = "auth"
|
auth = "auth",
|
||||||
|
returnAvailableCollectionPoints = false
|
||||||
}) {
|
}) {
|
||||||
const lines = getVariantsLines(variantsList, productQuantity);
|
const lines = getVariantsLines(variantsList, productQuantity);
|
||||||
const shippingAddress = getDefaultAddress(address, "shippingAddress");
|
const shippingAddress = getDefaultAddress(address, "shippingAddress");
|
||||||
|
@ -21,6 +22,16 @@ export function createCheckout({
|
||||||
"billingAddress"
|
"billingAddress"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const availableCollectionPointsLines = getValueWithDefault(
|
||||||
|
returnAvailableCollectionPoints,
|
||||||
|
`availableCollectionPoints{
|
||||||
|
id
|
||||||
|
name
|
||||||
|
clickAndCollectOption
|
||||||
|
isPrivate
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
|
||||||
const mutation = `mutation{
|
const mutation = `mutation{
|
||||||
checkoutCreate(input:{
|
checkoutCreate(input:{
|
||||||
channel:"${channelSlug}"
|
channel:"${channelSlug}"
|
||||||
|
@ -33,13 +44,13 @@ export function createCheckout({
|
||||||
field
|
field
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
|
|
||||||
created
|
created
|
||||||
checkout{
|
checkout{
|
||||||
id
|
id
|
||||||
availableShippingMethods{
|
availableShippingMethods{
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
${availableCollectionPointsLines}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
|
@ -62,6 +62,7 @@ export function getWarehouse(warehouseId) {
|
||||||
warehouse(id:"${warehouseId}"){
|
warehouse(id:"${warehouseId}"){
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
|
clickAndCollectOption
|
||||||
address{
|
address{
|
||||||
companyName
|
companyName
|
||||||
streetAddress1
|
streetAddress1
|
||||||
|
|
64
cypress/support/pages/warehousePage.js
Normal file
64
cypress/support/pages/warehousePage.js
Normal 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
|
||||||
|
};
|
Loading…
Reference in a new issue