2021-09-27 10:04:21 +00:00
|
|
|
/// <reference types="cypress"/>
|
|
|
|
/// <reference types="../../../support"/>
|
|
|
|
|
2021-07-23 09:46:44 +00:00
|
|
|
import faker from "faker";
|
|
|
|
|
2021-09-27 10:04:21 +00:00
|
|
|
import { shippingZoneDetailsUrl } from "../../../fixtures/urlList";
|
|
|
|
import { ONE_PERMISSION_USERS } from "../../../fixtures/users";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
updateChannelWarehouses,
|
|
|
|
} from "../../../support/api/requests/Channels";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { createCheckout } from "../../../support/api/requests/Checkout";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
createShippingZone,
|
|
|
|
} from "../../../support/api/requests/ShippingMethod";
|
2021-09-27 10:04:21 +00:00
|
|
|
import { createWarehouse } from "../../../support/api/requests/Warehouse";
|
|
|
|
import { getDefaultChannel } from "../../../support/api/utils/channelsUtils";
|
2021-07-23 09:46:44 +00:00
|
|
|
import {
|
|
|
|
createProductInChannel,
|
|
|
|
createTypeAttributeAndCategoryForProduct,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../../support/api/utils/products/productsUtils";
|
2023-07-28 07:48:41 +00:00
|
|
|
import {
|
|
|
|
isShippingAvailableInCheckout,
|
|
|
|
} from "../../../support/api/utils/storeFront/checkoutUtils";
|
2021-09-27 10:04:21 +00:00
|
|
|
import {
|
|
|
|
createRateWithPostalCode,
|
2022-06-27 16:49:35 +00:00
|
|
|
postalCodesOptions,
|
2021-09-27 10:04:21 +00:00
|
|
|
} from "../../../support/pages/shippingMethodPage";
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
describe("As a user I want to create shipping method with postal codes", () => {
|
2022-08-16 10:49:22 +00:00
|
|
|
const startsWith = "postalCodes-";
|
2022-06-27 09:30:51 +00:00
|
|
|
const name = `${startsWith}${faker.datatype.number()}`;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
const price = 10;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
let defaultChannel;
|
|
|
|
let usAddress;
|
|
|
|
let secondUsAddress;
|
|
|
|
let shippingZone;
|
|
|
|
let warehouse;
|
|
|
|
let variantsList;
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
before(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest();
|
2022-06-27 09:30:51 +00:00
|
|
|
getDefaultChannel()
|
|
|
|
.then(channel => {
|
|
|
|
defaultChannel = channel;
|
2022-07-29 06:35:55 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
cy.fixture("addresses");
|
|
|
|
})
|
|
|
|
.then(
|
|
|
|
({
|
|
|
|
usAddress: usAddressResp,
|
2022-06-27 16:49:35 +00:00
|
|
|
secondUsAddress: secondUsAddressResp,
|
2022-06-27 09:30:51 +00:00
|
|
|
}) => {
|
|
|
|
usAddress = usAddressResp;
|
|
|
|
secondUsAddress = secondUsAddressResp;
|
2022-07-29 06:35:55 +00:00
|
|
|
|
|
|
|
createWarehouse({ name, address: usAddress }).then(warehouseResp => {
|
|
|
|
warehouse = warehouseResp;
|
|
|
|
|
|
|
|
updateChannelWarehouses(defaultChannel.id, warehouse.id);
|
|
|
|
createShippingZone(
|
|
|
|
name,
|
|
|
|
"US",
|
|
|
|
defaultChannel.id,
|
|
|
|
warehouse.id,
|
|
|
|
).then(shippingZoneResp => {
|
|
|
|
shippingZone = shippingZoneResp;
|
|
|
|
|
|
|
|
createTypeAttributeAndCategoryForProduct({ name });
|
|
|
|
});
|
|
|
|
});
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
)
|
|
|
|
.then(({ attribute, productType, category }) => {
|
|
|
|
createProductInChannel({
|
|
|
|
name,
|
|
|
|
channelId: defaultChannel.id,
|
|
|
|
warehouseId: warehouse.id,
|
|
|
|
attributeId: attribute.id,
|
|
|
|
categoryId: category.id,
|
2022-06-27 16:49:35 +00:00
|
|
|
productTypeId: productType.id,
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(({ variantsList: variantsListResp }) => {
|
|
|
|
variantsList = variantsListResp;
|
2023-01-16 13:55:38 +00:00
|
|
|
cy.checkIfDataAreNotNull({
|
|
|
|
defaultChannel,
|
|
|
|
usAddress,
|
|
|
|
secondUsAddress,
|
|
|
|
shippingZone,
|
|
|
|
warehouse,
|
|
|
|
variantsList,
|
|
|
|
});
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
beforeEach(() => {
|
2023-07-28 07:48:41 +00:00
|
|
|
cy.loginUserViaRequest("auth", ONE_PERMISSION_USERS.shipping).visit(
|
|
|
|
shippingZoneDetailsUrl(shippingZone.id),
|
|
|
|
);
|
2022-06-27 09:30:51 +00:00
|
|
|
});
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to create shipping method with included postal codes. TC: SALEOR_0801",
|
|
|
|
{ tags: ["@shipping", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const rateName = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
|
|
|
createRateWithPostalCode({
|
|
|
|
rateName,
|
|
|
|
price,
|
|
|
|
postalCodeOption: postalCodesOptions.INCLUDE_OPTION,
|
|
|
|
maxPostalCode: usAddress.postalCode,
|
2022-06-27 16:49:35 +00:00
|
|
|
minPostalCode: usAddress.postalCode,
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
|
|
|
isShippingAvailableForAddress(usAddress, rateName).then(
|
2022-06-27 16:49:35 +00:00
|
|
|
isAvailable => expect(isAvailable).to.be.true,
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
|
|
|
isShippingAvailableForAddress(secondUsAddress, rateName).then(
|
2022-06-27 16:49:35 +00:00
|
|
|
isAvailable => expect(isAvailable).to.be.false,
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
2021-07-23 09:46:44 +00:00
|
|
|
|
2022-06-27 09:30:51 +00:00
|
|
|
it(
|
|
|
|
"should be able to create shipping method with excluded postal codes. TC: SALEOR_0802",
|
|
|
|
{ tags: ["@shipping", "@allEnv", "@stable"] },
|
|
|
|
() => {
|
2021-07-23 09:46:44 +00:00
|
|
|
const rateName = `${startsWith}${faker.datatype.number()}`;
|
|
|
|
|
|
|
|
createRateWithPostalCode({
|
|
|
|
rateName,
|
|
|
|
price,
|
|
|
|
postalCodeOption: postalCodesOptions.EXCLUDE_OPTION,
|
|
|
|
maxPostalCode: usAddress.postalCode,
|
2022-06-27 16:49:35 +00:00
|
|
|
minPostalCode: usAddress.postalCode,
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|
|
|
|
isShippingAvailableForAddress(usAddress, rateName).then(
|
2022-06-27 16:49:35 +00:00
|
|
|
isAvailable => expect(isAvailable).to.be.false,
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
|
|
|
isShippingAvailableForAddress(secondUsAddress, rateName).then(
|
2022-06-27 16:49:35 +00:00
|
|
|
isAvailable => expect(isAvailable).to.be.true,
|
2021-07-23 09:46:44 +00:00
|
|
|
);
|
2022-06-27 16:49:35 +00:00
|
|
|
},
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
function isShippingAvailableForAddress(address, rateName) {
|
|
|
|
return createCheckout({
|
|
|
|
address,
|
|
|
|
channelSlug: defaultChannel.slug,
|
|
|
|
email: "example@example.com",
|
2022-06-27 16:49:35 +00:00
|
|
|
variantsList,
|
2022-06-27 09:30:51 +00:00
|
|
|
}).then(({ checkout }) =>
|
2022-06-27 16:49:35 +00:00
|
|
|
isShippingAvailableInCheckout(checkout, rateName),
|
2022-06-27 09:30:51 +00:00
|
|
|
);
|
|
|
|
}
|
2021-07-23 09:46:44 +00:00
|
|
|
});
|