tests for click & collect (#1488)

This commit is contained in:
Karolina Rakoczy 2021-10-21 12:45:38 +02:00 committed by GitHub
parent e879a0c1d5
commit 39c1e8e208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 121 additions and 23 deletions

View file

@ -37,7 +37,7 @@
"postalCode": "70958", "postalCode": "70958",
"country": "US", "country": "US",
"countryArea": "LA", "countryArea": "LA",
"phone": "2025550189", "phone": "+12025550169",
"currency": "USD", "currency": "USD",
"countryFullName": "United States of America" "countryFullName": "United States of America"
} }

View file

@ -3,8 +3,16 @@
import faker from "faker"; import faker from "faker";
import { createCheckout } from "../../support/api/requests/Checkout"; 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 { getDefaultChannel } from "../../support/api/utils/channelsUtils";
import { addPayment } from "../../support/api/utils/ordersUtils";
import { import {
createProductInChannel, createProductInChannel,
createTypeAttributeAndCategoryForProduct, createTypeAttributeAndCategoryForProduct,
@ -16,6 +24,7 @@ import {
} from "../../support/api/utils/shippingUtils"; } from "../../support/api/utils/shippingUtils";
import filterTests from "../../support/filterTests"; import filterTests from "../../support/filterTests";
import { import {
createWarehouse,
pickupOptions, pickupOptions,
visitAndEnablePickup, visitAndEnablePickup,
visitSetPublicStockAndEnablePickup visitSetPublicStockAndEnablePickup
@ -26,6 +35,7 @@ filterTests({ definedTags: ["all"] }, () => {
const startsWith = `CyWarehouseCheckout`; const startsWith = `CyWarehouseCheckout`;
let defaultChannel; let defaultChannel;
let usAddress; let usAddress;
let secondUsAddress;
let plAddress; let plAddress;
let productData; let productData;
let checkoutData; let checkoutData;
@ -38,6 +48,7 @@ filterTests({ definedTags: ["all"] }, () => {
cy.fixture("addresses") cy.fixture("addresses")
.then(addresses => { .then(addresses => {
usAddress = addresses.usAddress; usAddress = addresses.usAddress;
secondUsAddress = addresses.secondUsAddress;
plAddress = addresses.plAddress; plAddress = addresses.plAddress;
getDefaultChannel(); getDefaultChannel();
}) })
@ -57,17 +68,18 @@ filterTests({ definedTags: ["all"] }, () => {
returnAvailableCollectionPoints: true, returnAvailableCollectionPoints: true,
channelSlug: defaultChannel.slug, channelSlug: defaultChannel.slug,
email: "example@example.com", email: "example@example.com",
address: plAddress address: secondUsAddress
}; };
createShipping({ createShipping({
channelId: defaultChannel.id, channelId: defaultChannel.id,
name: startsWith, name: startsWith,
address: plAddress address: secondUsAddress
}); });
}) })
.then(({ warehouse: warehouseResp }) => { .then(({ warehouse: warehouseResp }) => {
productData.name = startsWith; productData.name = startsWith;
productData.warehouseId = warehouseResp.id; productData.warehouseId = warehouseResp.id;
updateWarehouse({ id: productData.warehouseId, isPrivate: false });
createProductInChannel(productData); createProductInChannel(productData);
}) })
.then(({ variantsList }) => { .then(({ variantsList }) => {
@ -86,7 +98,7 @@ filterTests({ definedTags: ["all"] }, () => {
createShipping({ createShipping({
channelId: defaultChannel.id, channelId: defaultChannel.id,
name, name,
address: plAddress address: secondUsAddress
}) })
.then(({ warehouse: warehouseResp }) => { .then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp; warehouse = warehouseResp;
@ -102,7 +114,9 @@ filterTests({ definedTags: ["all"] }, () => {
createCheckout(checkoutData); createCheckout(checkoutData);
}) })
.then(({ checkout }) => { .then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints[0]; const clickAndCollectOption = checkout.availableCollectionPoints.find(
element => element.id === warehouse.id
);
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL"); expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
expect(clickAndCollectOption.id).to.eq(warehouse.id); expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(true); expect(clickAndCollectOption.isPrivate).to.eq(true);
@ -117,7 +131,7 @@ filterTests({ definedTags: ["all"] }, () => {
createShipping({ createShipping({
channelId: defaultChannel.id, channelId: defaultChannel.id,
name, name,
address: plAddress address: secondUsAddress
}) })
.then(({ warehouse: warehouseResp }) => { .then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp; warehouse = warehouseResp;
@ -133,7 +147,9 @@ filterTests({ definedTags: ["all"] }, () => {
createCheckout(checkoutData); createCheckout(checkoutData);
}) })
.then(({ checkout }) => { .then(({ checkout }) => {
const clickAndCollectOption = checkout.availableCollectionPoints[0]; const clickAndCollectOption = checkout.availableCollectionPoints.find(
element => element.id === warehouse.id
);
expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL"); expect(clickAndCollectOption.clickAndCollectOption).to.eq("ALL");
expect(clickAndCollectOption.id).to.eq(warehouse.id); expect(clickAndCollectOption.id).to.eq(warehouse.id);
expect(clickAndCollectOption.isPrivate).to.eq(false); expect(clickAndCollectOption.isPrivate).to.eq(false);
@ -149,7 +165,7 @@ filterTests({ definedTags: ["all"] }, () => {
createShipping({ createShipping({
channelId: defaultChannel.id, channelId: defaultChannel.id,
name, name,
address: plAddress address: secondUsAddress
}) })
.then(({ warehouse: warehouseResp }) => { .then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp; warehouse = warehouseResp;
@ -167,8 +183,8 @@ filterTests({ definedTags: ["all"] }, () => {
}) })
.then(({ checkout }) => { .then(({ checkout }) => {
expect(checkout.availableCollectionPoints).to.have.length( expect(checkout.availableCollectionPoints).to.have.length(
0, 1,
"there should be no available collection point" "there should be no available collection point for local stock"
); );
checkoutData.variantsList = variantsInLocalStock; checkoutData.variantsList = variantsInLocalStock;
createCheckout(checkoutData); createCheckout(checkoutData);
@ -182,6 +198,39 @@ filterTests({ definedTags: ["all"] }, () => {
}); });
}); });
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", () => { it("should not be possible to buy product for country not listed in warehouse", () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
let warehouse; let warehouse;
@ -189,7 +238,7 @@ filterTests({ definedTags: ["all"] }, () => {
createShipping({ createShipping({
channelId: defaultChannel.id, channelId: defaultChannel.id,
name, name,
address: usAddress address: plAddress
}) })
.then(({ warehouse: warehouseResp }) => { .then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp; warehouse = warehouseResp;

View file

@ -1,25 +1,25 @@
/// <reference types="cypress"/> /// <reference types="cypress"/>
/// <reference types="../../support"/> /// <reference types="../../../support"/>
import faker from "faker"; import faker from "faker";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { SHIPPING_ZONE_DETAILS } from "../../elements/shipping/shipping-zone-details"; import { SHIPPING_ZONE_DETAILS } from "../../../elements/shipping/shipping-zone-details";
import { WAREHOUSES_DETAILS } from "../../elements/warehouses/warehouse-details"; import { WAREHOUSES_DETAILS } from "../../../elements/warehouses/warehouse-details";
import { WAREHOUSES_LIST } from "../../elements/warehouses/warehouses-list"; import { WAREHOUSES_LIST } from "../../../elements/warehouses/warehouses-list";
import { import {
shippingZoneDetailsUrl, shippingZoneDetailsUrl,
urlList, urlList,
warehouseDetailsUrl warehouseDetailsUrl
} from "../../fixtures/urlList"; } from "../../../fixtures/urlList";
import { createShippingZone } from "../../support/api/requests/ShippingMethod"; import { createShippingZone } from "../../../support/api/requests/ShippingMethod";
import { import {
createWarehouse as createWarehouseViaApi, 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";
import { deleteShippingStartsWith } from "../../support/api/utils/shippingUtils"; import { deleteShippingStartsWith } from "../../../support/api/utils/shippingUtils";
import filterTests from "../../support/filterTests"; import filterTests from "../../../support/filterTests";
filterTests({ definedTags: ["all"] }, () => { filterTests({ definedTags: ["all"] }, () => {
describe("Warehouse settings", () => { describe("Warehouse settings", () => {

View file

@ -46,6 +46,7 @@ export function createCheckout({
} }
created created
checkout{ checkout{
token
id id
availableShippingMethods{ availableShippingMethods{
name name
@ -85,6 +86,18 @@ export function addShippingMethod(checkoutId, shippingMethodId) {
.its("body.data.checkoutShippingMethodUpdate"); .its("body.data.checkoutShippingMethodUpdate");
} }
export function deliveryMethodUpdate(deliveryMethodId, checkoutToken) {
const mutation = `mutation{
checkoutDeliveryMethodUpdate(deliveryMethodId:"${deliveryMethodId}", token:"${checkoutToken}"){
errors{
field
message
}
}
}`;
cy.sendRequestWithQuery(mutation);
}
export function addPayment({ checkoutId, gateway, token, amount }) { export function addPayment({ checkoutId, gateway, token, amount }) {
const tokenLine = getValueWithDefault(token, `token:"${token}"`); const tokenLine = getValueWithDefault(token, `token:"${token}"`);
const amountLine = getValueWithDefault(amount, `amount: ${amount}`); const amountLine = getValueWithDefault(amount, `amount: ${amount}`);

View file

@ -108,6 +108,24 @@ export function getOrder(orderId) {
key key
value value
} }
shippingAddress{
companyName
streetAddress1
streetAddress2
city
postalCode
countryArea
phone
}
billingAddress{
companyName
streetAddress1
streetAddress2
city
postalCode
countryArea
phone
}
} }
}`; }`;
cy.sendRequestWithQuery(query).its("body.data.order"); cy.sendRequestWithQuery(query).its("body.data.order");

View file

@ -83,3 +83,21 @@ export function getWarehouse(warehouseId) {
}`; }`;
return cy.sendRequestWithQuery(query).its("body.data.warehouse"); return cy.sendRequestWithQuery(query).its("body.data.warehouse");
} }
export function updateWarehouse({
id,
isPrivate,
clickAndCollectOption = "ALL"
}) {
const mutation = `mutation{
updateWarehouse(id:"${id}" input:{
isPrivate:${isPrivate}
clickAndCollectOption:${clickAndCollectOption}
}){
errors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation).its("body.data");
}