Saleor 2960 checkout products without shipment (#1075)

* add tests for puchase by type

* add expect for isShippingRequired
This commit is contained in:
Karolina Rakoczy 2021-04-28 15:10:47 +02:00 committed by GitHub
parent d220914085
commit 074c0f7a6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 537 additions and 235 deletions

View file

@ -18,7 +18,9 @@ export function createAttribute(name, attributeValues = ["value"]) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.attributeCreate.attribute");
} }
export function getAttributes(first, search) { export function getAttributes(first, search) {

View file

@ -11,7 +11,9 @@ export function createCategory(name, slug = name) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.categoryCreate.category");
} }
export function getCategories(first, search) { export function getCategories(first, search) {
const mutation = `query{ const mutation = `query{

View file

@ -1,4 +1,9 @@
export function createChannel(isActive, name, slug, currencyCode) { export function createChannel({
isActive = true,
name,
slug = name,
currencyCode = "PLN"
}) {
const createChannelMutation = `mutation{ const createChannelMutation = `mutation{
channelCreate(input: { channelCreate(input: {
isActive: ${isActive} isActive: ${isActive}
@ -17,7 +22,9 @@ export function createChannel(isActive, name, slug, currencyCode) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(createChannelMutation); return cy
.sendRequestWithQuery(createChannelMutation)
.its("body.data.channelCreate.channel");
} }
export function getChannels() { export function getChannels() {
const getChannelsInfoQuery = `query{ const getChannelsInfoQuery = `query{

View file

@ -1,17 +1,20 @@
import { getDefaultAddress } from "./utils/Utils"; import { getDefaultAddress, getVariantsLines } from "./utils/Utils";
export function createCheckout({ export function createCheckout({
channelSlug, channelSlug,
email, email,
productQuantity = 1, productQuantity = 1,
variantsList, variantsList,
address, address,
billingAddress,
auth = "auth" auth = "auth"
}) { }) {
const lines = variantsList.map( const lines = getVariantsLines(variantsList, productQuantity);
variant => `{quantity:${productQuantity}
variantId:"${variant.id}"}`
);
const shippingAddress = getDefaultAddress(address, "shippingAddress"); const shippingAddress = getDefaultAddress(address, "shippingAddress");
const billingAddressLines = getDefaultAddress(
billingAddress,
"billingAddress"
);
const mutation = `mutation{ const mutation = `mutation{
checkoutCreate(input:{ checkoutCreate(input:{
@ -19,6 +22,7 @@ export function createCheckout({
email:"${email}" email:"${email}"
lines: [${lines.join()}] lines: [${lines.join()}]
${shippingAddress} ${shippingAddress}
${billingAddressLines}
}){ }){
checkoutErrors{ checkoutErrors{
field field
@ -33,7 +37,9 @@ export function createCheckout({
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation, auth); return cy
.sendRequestWithQuery(mutation, auth)
.its("body.data.checkoutCreate.checkout");
} }
export function addShippingMethod(checkoutId, shippingMethodId) { export function addShippingMethod(checkoutId, shippingMethodId) {
const mutation = `mutation{ const mutation = `mutation{
@ -47,6 +53,7 @@ export function addShippingMethod(checkoutId, shippingMethodId) {
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
export function addPayment(checkoutId, gateway, token) { export function addPayment(checkoutId, gateway, token) {
const mutation = `mutation{ const mutation = `mutation{
checkoutPaymentCreate(checkoutId:"${checkoutId}", checkoutPaymentCreate(checkoutId:"${checkoutId}",
@ -60,8 +67,11 @@ export function addPayment(checkoutId, gateway, token) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.checkoutPaymentCreate");
} }
export function completeCheckout(checkoutId) { export function completeCheckout(checkoutId) {
const mutation = `mutation{ const mutation = `mutation{
checkoutComplete(checkoutId:"${checkoutId}"){ checkoutComplete(checkoutId:"${checkoutId}"){
@ -76,7 +86,9 @@ export function completeCheckout(checkoutId) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.checkoutComplete.order");
} }
export function addVoucher(checkoutId, voucherCode) { export function addVoucher(checkoutId, voucherCode) {
@ -99,3 +111,46 @@ export function addVoucher(checkoutId, voucherCode) {
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
export function checkoutVariantsUpdate(checkoutId, variantsList) {
const lines = getVariantsLines(variantsList, 1);
const mutation = `mutation{
checkoutLinesUpdate(checkoutId:"${checkoutId}",
lines: [${lines.join()}]){
checkoutErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}
export function checkoutShippingMethodUpdate(checkoutId, shippingMethodId) {
const mutation = `mutation{
checkoutShippingMethodUpdate(checkoutId:"${checkoutId}" shippingMethodId:"${shippingMethodId}"){
checkoutErrors{
field
message
}
}
}`;
return cy
.sendRequestWithQuery(mutation)
.its("body.data.checkoutShippingMethodUpdate");
}
export function checkoutShippingAddressUpdate(checkoutId, address) {
const shippingAddress = getDefaultAddress(address, "shippingAddress");
const mutation = `mutation{
checkoutShippingAddressUpdate(checkoutId:"${checkoutId}",
${shippingAddress}
){
checkoutErrors{
field
message
}
}
}`;
return cy.sendRequestWithQuery(mutation);
}

View file

@ -39,7 +39,9 @@ export function createDraftOrder(customerId, shippingMethodId, channelId) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.draftOrderCreate.order");
} }
export function completeOrder(orderId) { export function completeOrder(orderId) {
const mutation = `mutation{ const mutation = `mutation{
@ -54,3 +56,15 @@ export function completeOrder(orderId) {
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
export function getOrder(orderId) {
const query = `query getOrder{
order(id:"${orderId}"){
status
isShippingRequired
shippingMethod{
id
}
}
}`;
cy.sendRequestWithQuery(query).its("body.data.order");
}

View file

@ -36,7 +36,9 @@ export function updateProduct(productId, input) {
} }
} }
`; `;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.productUpdate.product");
} }
export function updateChannelInProduct({ export function updateChannelInProduct({
@ -83,14 +85,14 @@ export function updateChannelPriceInVariant(variantId, channelId) {
} `; } `;
return cy.sendRequestWithQuery(mutation); return cy.sendRequestWithQuery(mutation);
} }
export function createProduct( export function createProduct({
attributeId, attributeId,
name, name,
productType, productTypeId,
category, categoryId,
collectionId, collectionId,
description description
) { }) {
const collection = getValueWithDefault( const collection = getValueWithDefault(
collectionId, collectionId,
`collections:["${collectionId}"]` `collections:["${collectionId}"]`
@ -107,8 +109,8 @@ export function createProduct(
name:"${name}" name:"${name}"
slug:"${name}" slug:"${name}"
seo:{title:"${name}" description:""} seo:{title:"${name}" description:""}
productType:"${productType}" productType:"${productTypeId}"
category:"${category}" category:"${categoryId}"
${collection} ${collection}
${descriptionLine} ${descriptionLine}
}){ }){
@ -122,14 +124,16 @@ export function createProduct(
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.productCreate.product");
} }
export function createVariant({ export function createVariant({
productId, productId,
sku, sku,
warehouseId, warehouseId,
quantity, quantityInWarehouse,
channelId, channelId,
attributeId, attributeId,
price = 1, price = 1,
@ -148,7 +152,7 @@ export function createVariant({
warehouseId, warehouseId,
`stocks:{ `stocks:{
warehouse:"${warehouseId}" warehouse:"${warehouseId}"
quantity:${quantity} quantity:${quantityInWarehouse}
}` }`
); );
@ -172,23 +176,26 @@ export function createVariant({
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.productVariantBulkCreate.productVariants");
} }
export function createTypeProduct( export function createTypeProduct({
name, name,
attributeId, attributeId,
hasVariants = true, hasVariants = true,
slug = name slug = name,
) { shippable = true
}) {
const mutation = `mutation{ const mutation = `mutation{
productTypeCreate(input: { productTypeCreate(input: {
name: "${name}" name: "${name}"
slug: "${slug}" slug: "${slug}"
isShippingRequired: true
productAttributes: "${attributeId}" productAttributes: "${attributeId}"
variantAttributes: "${attributeId}" variantAttributes: "${attributeId}"
hasVariants: ${hasVariants} hasVariants: ${hasVariants}
isShippingRequired:${shippable}
}){ }){
productErrors{ productErrors{
field field
@ -200,7 +207,9 @@ export function createTypeProduct(
} }
} }
} `; } `;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.productTypeCreate.productType");
} }
export function deleteProduct(productId) { export function deleteProduct(productId) {

View file

@ -26,7 +26,9 @@ export function createShippingZone(name, country, channelId) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.shippingZoneCreate.shippingZone");
} }
export function addChannelToShippingZone(shippingZoneId, channelId) { export function addChannelToShippingZone(shippingZoneId, channelId) {
const mutation = `mutation addCh{ const mutation = `mutation addCh{

View file

@ -22,7 +22,9 @@ export function createWarehouse({ name, shippingZone, address, slug = name }) {
} }
} }
}`; }`;
return cy.sendRequestWithQuery(mutation); return cy
.sendRequestWithQuery(mutation)
.its("body.data.createWarehouse.warehouse");
} }
export function getWarehouses(first, search) { export function getWarehouses(first, search) {
const query = `query{ const query = `query{

View file

@ -19,3 +19,9 @@ export function getDefaultAddress(address, addressType, withName = true) {
} }
return `${addressType}:{${defaultAddress}}`; return `${addressType}:{${defaultAddress}}`;
} }
export function getVariantsLines(variantsList, quantity) {
return variantsList.map(
variant => `{quantity:${quantity}
variantId:"${variant.id}"}`
);
}

View file

@ -13,6 +13,8 @@ export const PRODUCT_DETAILS = {
descriptionInput: "[data-test-id='description']", descriptionInput: "[data-test-id='description']",
ratingInput: "[name='rating']", ratingInput: "[name='rating']",
skuInput: "[name='sku']", skuInput: "[name='sku']",
variantRow: "[data-test-id='product-variant-row']",
variantPrice: '[data-test="price"]',
collectionRemoveButtons: '[data-test-id="collectionRemove"]', collectionRemoveButtons: '[data-test-id="collectionRemove"]',
variantRow: "[data-test-id='product-variant-row']" variantRow: "[data-test-id='product-variant-row']"
}; };

View file

@ -4,6 +4,7 @@ export const BUTTON_SELECTORS = {
confirm: '[data-test="button-bar-confirm"]', confirm: '[data-test="button-bar-confirm"]',
goBackButton: "[data-test-id='app-header-back-button']", goBackButton: "[data-test-id='app-header-back-button']",
checkbox: "[type='checkbox']", checkbox: "[type='checkbox']",
checked: "[class*='checked']",
selectOption: "[data-test*='select-option']", selectOption: "[data-test*='select-option']",
notSelectedOption: ":not([aria-selected])", notSelectedOption: ":not([aria-selected])",
deleteButton: '[data-test="button-bar-delete"]', deleteButton: '[data-test="button-bar-delete"]',

View file

@ -10,5 +10,17 @@
"phone": "123456787", "phone": "123456787",
"currency": "PLN", "currency": "PLN",
"countryFullName": "Poland" "countryFullName": "Poland"
},
"usAddress": {
"companyName": "Test3",
"streetAddress1": "Amber Prairie",
"streetAddress2": "483",
"city": "KIRKSHIRE",
"postalCode": "52216",
"country": "US",
"countryArea": "IA",
"currency": "USD",
"phone": "+12025550180",
"countryFullName": "United States of America"
} }
} }

View file

@ -1,6 +1,7 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import { createChannel } from "../apiRequests/Channels";
import { updateChannelInProduct } from "../apiRequests/Product"; import { updateChannelInProduct } from "../apiRequests/Product";
import { getCollection } from "../apiRequests/storeFront/Collections"; import { getCollection } from "../apiRequests/storeFront/Collections";
import { searchInShop } from "../apiRequests/storeFront/Search"; import { searchInShop } from "../apiRequests/storeFront/Search";
@ -108,8 +109,7 @@ describe("Collections", () => {
let collection; let collection;
let channel; let channel;
channelsUtils createChannel({ name: collectionName })
.createChannel({ name: collectionName })
.then(channelResp => { .then(channelResp => {
channel = channelResp; channel = channelResp;
updateChannelInProduct(product.id, channel.id); updateChannelInProduct(product.id, channel.id);

View file

@ -83,7 +83,12 @@ describe("Channels", () => {
it("should validate slug name", () => { it("should validate slug name", () => {
const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`; const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`;
createChannel(false, randomChannel, randomChannel, currency); createChannel({
isActive: false,
name: randomChannel,
slug: randomChannel,
currencyCode: currency
});
cy.visit(urlList.channels); cy.visit(urlList.channels);
createChannelByView(randomChannel, currency); createChannelByView(randomChannel, currency);
cy.get(ADD_CHANNEL_FORM_SELECTORS.slugValidationMessage).should( cy.get(ADD_CHANNEL_FORM_SELECTORS.slugValidationMessage).should(
@ -102,12 +107,12 @@ describe("Channels", () => {
it("should delete channel", () => { it("should delete channel", () => {
const randomChannelToDelete = `${channelStartsWith} ${faker.datatype.number()}`; const randomChannelToDelete = `${channelStartsWith} ${faker.datatype.number()}`;
createChannel( createChannel({
false, isActive: false,
randomChannelToDelete, name: randomChannelToDelete,
randomChannelToDelete, slug: randomChannelToDelete,
currency currencyCode: currency
); });
cy.addAliasToGraphRequest("Channels"); cy.addAliasToGraphRequest("Channels");
cy.visit(urlList.channels); cy.visit(urlList.channels);
cy.wait("@Channels"); cy.wait("@Channels");
@ -126,7 +131,12 @@ describe("Channels", () => {
it("should not be possible to add products to order with inactive channel", () => { it("should not be possible to add products to order with inactive channel", () => {
const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`; const randomChannel = `${channelStartsWith} ${faker.datatype.number()}`;
createChannel(false, randomChannel, randomChannel, currency); createChannel({
isActive: false,
name: randomChannel,
slug: randomChannel,
currencyCode: currency
});
cy.visit(urlList.orders) cy.visit(urlList.orders)
.get(ORDERS_SELECTORS.createOrder) .get(ORDERS_SELECTORS.createOrder)
.click() .click()

View file

@ -0,0 +1,233 @@
import faker from "faker";
import { createAttribute } from "../../../apiRequests/Attribute";
import { createCategory } from "../../../apiRequests/Category";
import {
checkoutShippingAddressUpdate,
checkoutShippingMethodUpdate,
checkoutVariantsUpdate,
completeCheckout,
createCheckout
} from "../../../apiRequests/Checkout";
import { getOrder } from "../../../apiRequests/Order";
import { createTypeProduct } from "../../../apiRequests/Product";
import { getDefaultChannel } from "../../../utils/channelsUtils";
import {
addPayment,
createAndCompleteCheckoutWithoutShipping,
createWaitingForCaptureOrder
} from "../../../utils/ordersUtils";
import {
createProductInChannel,
deleteProductsStartsWith
} from "../../../utils/products/productsUtils";
import {
createShipping,
deleteShippingStartsWith
} from "../../../utils/shippingUtils";
describe("Purchase products with all products types", () => {
const startsWith = `CyPurchaseByType`;
const name = `${startsWith}${faker.datatype.number()}`;
const email = `${startsWith}@example.com`;
const testsMessage = "Check order status";
const { softExpect } = chai;
let defaultChannel;
let address;
let warehouse;
let attribute;
let category;
let shippingMethod;
let createProductData;
before(() => {
cy.clearSessionData().loginUserViaRequest();
deleteProductsStartsWith(startsWith);
deleteShippingStartsWith(startsWith);
getDefaultChannel().then(channelResp => (defaultChannel = channelResp));
cy.fixture("addresses")
.then(addresses => {
address = addresses.usAddress;
createShipping({
channelId: defaultChannel.id,
name,
address,
price: 10
});
})
.then(
({ warehouse: warehouseResp, shippingMethod: shippingMethodResp }) => {
warehouse = warehouseResp;
shippingMethod = shippingMethodResp;
}
);
createAttribute(name)
.then(attributeResp => {
attribute = attributeResp;
createCategory(name);
})
.then(categoryResp => {
category = categoryResp;
});
});
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
createProductData = {
channelId: defaultChannel.id,
warehouseId: warehouse.id,
quantityInWarehouse: 10,
attributeId: attribute.id,
categoryId: category.id,
price: 10
};
});
it("should purchase digital product", () => {
const digitalName = `${startsWith}${faker.datatype.number()}`;
createTypeProduct({
name: digitalName,
attributeId: attribute.id,
shippable: false
})
.then(productType => {
createProductData.name = digitalName;
createProductData.productTypeId = productType.id;
createProductInChannel(createProductData);
})
.then(({ variantsList }) => {
createAndCompleteCheckoutWithoutShipping({
channelSlug: defaultChannel.slug,
email,
billingAddress: address,
variantsList,
auth: "token"
});
})
.then(({ order }) => {
getOrder(order.id);
})
.then(order => {
softExpect(
order.isShippingRequired,
"Check if is shipping required in order"
).to.eq(false);
expect(order.status, testsMessage).to.be.eq("UNFULFILLED");
});
});
it("should purchase physical product", () => {
const physicalName = `${startsWith}${faker.datatype.number()}`;
createTypeProduct({
name: physicalName,
attributeId: attribute.id,
shippable: true
})
.then(productType => {
createProductData.name = physicalName;
createProductData.productTypeId = productType.id;
createProductInChannel(createProductData);
})
.then(({ variantsList }) => {
createWaitingForCaptureOrder(
defaultChannel.slug,
email,
variantsList,
shippingMethod.id,
address
);
})
.then(({ order }) => {
getOrder(order.id);
})
.then(order => {
softExpect(
order.isShippingRequired,
"Check if is shipping required in order"
).to.eq(true);
expect(order.status, testsMessage).to.be.eq("UNFULFILLED");
});
});
it("should purchase multiple products with all product types", () => {
const physicalName = `${startsWith}${faker.datatype.number()}`;
const digitalName = `${startsWith}${faker.datatype.number()}`;
let digitalProductVariantsList;
let checkout;
createTypeProduct({
name: digitalName,
attributeId: attribute.id,
shippable: false
})
.then(productType => {
createProductData.name = digitalName;
createProductData.productTypeId = productType.id;
createProductInChannel(createProductData);
})
.then(({ variantsList }) => {
digitalProductVariantsList = variantsList;
createCheckout({
channelSlug: defaultChannel.slug,
email,
variantsList: digitalProductVariantsList,
billingAddress: address,
auth: "token"
});
})
.then(checkoutResp => {
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => {
createTypeProduct({
name: physicalName,
attributeId: attribute.id,
shippable: true
});
})
.then(productType => {
createProductData.name = physicalName;
createProductData.productTypeId = productType.id;
createProductInChannel(createProductData);
})
.then(({ variantsList }) => {
checkoutVariantsUpdate(checkout.id, variantsList);
})
.then(() => {
checkoutShippingMethodUpdate(checkout.id, shippingMethod.id);
})
.then(({ checkoutErrors }) => {
expect(
checkoutErrors,
"Should be not possible to add shipping method without shipping address"
).to.have.lengthOf(1);
checkoutShippingAddressUpdate(checkout.id, address);
})
.then(() => {
addPayment(checkout.id);
})
.then(({ paymentErrors }) => {
expect(
paymentErrors,
"Should be not possible to add payment without shipping"
).to.have.lengthOf(1);
checkoutShippingMethodUpdate(checkout.id, shippingMethod.id);
})
.then(() => {
addPayment(checkout.id);
})
.then(() => {
completeCheckout(checkout.id);
})
.then(order => {
getOrder(order.id);
})
.then(order => {
softExpect(
order.isShippingRequired,
"Check if is shipping required in order"
).to.eq(true);
expect(order.status, testsMessage).to.be.eq("UNFULFILLED");
});
});
});

View file

@ -1,10 +1,13 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import { createChannel } from "../../apiRequests/Channels";
import { createCheckout } from "../../apiRequests/Checkout";
import { import {
addChannelToShippingMethod, addChannelToShippingMethod,
addChannelToShippingZone addChannelToShippingZone
} from "../../apiRequests/ShippingMethod"; } from "../../apiRequests/ShippingMethod";
import { createWarehouse } from "../../apiRequests/Warehouse";
import { SHIPPING_ZONE_DETAILS } from "../../elements/shipping/shipping-zone-details"; import { SHIPPING_ZONE_DETAILS } from "../../elements/shipping/shipping-zone-details";
import { selectChannelInHeader } from "../../steps/channelsSteps"; import { selectChannelInHeader } from "../../steps/channelsSteps";
import { import {
@ -15,7 +18,6 @@ import {
import { getFormattedCurrencyAmount } from "../../support/format/formatCurrencyAmount"; import { getFormattedCurrencyAmount } from "../../support/format/formatCurrencyAmount";
import { urlList } from "../../url/urlList"; import { urlList } from "../../url/urlList";
import * as channelsUtils from "../../utils/channelsUtils"; import * as channelsUtils from "../../utils/channelsUtils";
import { createCheckout } from "../../utils/ordersUtils";
import * as productsUtils from "../../utils/products/productsUtils"; import * as productsUtils from "../../utils/products/productsUtils";
import * as shippingUtils from "../../utils/shippingUtils"; import * as shippingUtils from "../../utils/shippingUtils";
import { isShippingAvailableInCheckout } from "../../utils/storeFront/checkoutUtils"; import { isShippingAvailableInCheckout } from "../../utils/storeFront/checkoutUtils";
@ -43,7 +45,7 @@ describe("Shipping methods", () => {
}) })
.then(addresses => { .then(addresses => {
plAddress = addresses.plAddress; plAddress = addresses.plAddress;
shippingUtils.createWarehouse({ name, address: plAddress }); createWarehouse({ name, address: plAddress });
}) })
.then(warehouseResp => { .then(warehouseResp => {
warehouse = warehouseResp; warehouse = warehouseResp;
@ -66,7 +68,7 @@ describe("Shipping methods", () => {
}); });
} }
) )
.then(({ variants: variantsListResp }) => { .then(({ variantsList: variantsListResp }) => {
variantsList = variantsListResp; variantsList = variantsListResp;
}); });
}); });
@ -86,8 +88,7 @@ describe("Shipping methods", () => {
let shippingZone; let shippingZone;
let createdChannel; let createdChannel;
channelsUtils createChannel({
.createChannel({
name: shippingName, name: shippingName,
currencyCode: createdChannelCurrency currencyCode: createdChannelCurrency
}) })

View file

@ -2,6 +2,7 @@
import faker from "faker"; import faker from "faker";
import { createChannel } from "../../apiRequests/Channels";
import { updateChannelInProduct } from "../../apiRequests/Product"; import { updateChannelInProduct } from "../../apiRequests/Product";
import { import {
assignProducts, assignProducts,
@ -144,9 +145,9 @@ describe("Sales discounts", () => {
const discountValue = 50; const discountValue = 50;
const productPrice = 100; const productPrice = 100;
channelsUtils createChannel({ name: saleName }).then(
.createChannel({ name: saleName }) channelResp => (channel = channelResp)
.then(channelResp => (channel = channelResp)); );
productsUtils productsUtils
.createProductInChannel({ .createProductInChannel({
name: saleName, name: saleName,

View file

@ -1,6 +1,7 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import { createChannel } from "../../apiRequests/Channels";
import { import {
createVoucher, createVoucher,
discountOptions discountOptions
@ -77,7 +78,7 @@ describe("Vouchers discounts", () => {
price: productPrice price: productPrice
}); });
}) })
.then(({ variants: variantsResp }) => (variants = variantsResp)); .then(({ variantsList: variantsResp }) => (variants = variantsResp));
}); });
beforeEach(() => { beforeEach(() => {
@ -142,8 +143,7 @@ describe("Vouchers discounts", () => {
const randomName = `${startsWith}${faker.datatype.number()}`; const randomName = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50; const voucherValue = 50;
channelsUtils createChannel({ name: randomName })
.createChannel({ name: randomName })
.then(channel => { .then(channel => {
createVoucher({ createVoucher({
voucherCode: randomName, voucherCode: randomName,

View file

@ -85,7 +85,7 @@ describe("Homepage analytics", () => {
}); });
} }
) )
.then(({ variants: variantsResp }) => { .then(({ variantsList: variantsResp }) => {
createdVariants = variantsResp; createdVariants = variantsResp;
}); });
}); });

View file

@ -1,6 +1,7 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import { createChannel } from "../../apiRequests/Channels";
import { CHANNEL_FORM_SELECTORS } from "../../elements/channels/channel-form-selectors"; import { CHANNEL_FORM_SELECTORS } from "../../elements/channels/channel-form-selectors";
import { HEADER_SELECTORS } from "../../elements/header/header-selectors"; import { HEADER_SELECTORS } from "../../elements/header/header-selectors";
import { DRAFT_ORDER_SELECTORS } from "../../elements/orders/draft-order-selectors"; import { DRAFT_ORDER_SELECTORS } from "../../elements/orders/draft-order-selectors";
@ -26,7 +27,7 @@ describe("Channels in draft orders", () => {
.getDefaultChannel() .getDefaultChannel()
.then(channel => { .then(channel => {
defaultChannel = channel; defaultChannel = channel;
channelsUtils.createChannel({ name: randomName }); createChannel({ name: randomName });
}) })
.then(channelResp => { .then(channelResp => {
otherChannel = channelResp; otherChannel = channelResp;

View file

@ -77,7 +77,7 @@ describe("Orders", () => {
}); });
} }
) )
.then(({ variants: variantsResp }) => { .then(({ variantsList: variantsResp }) => {
variantsList = variantsResp; variantsList = variantsResp;
}); });
}); });

View file

@ -1,6 +1,8 @@
// <reference types="cypress" /> // <reference types="cypress" />
import faker from "faker"; import faker from "faker";
import { createAttribute } from "../../apiRequests/Attribute";
import { createTypeProduct } from "../../apiRequests/Product";
import { PRODUCT_DETAILS } from "../../elements/catalog/products/product-details"; import { PRODUCT_DETAILS } from "../../elements/catalog/products/product-details";
import { PRODUCTS_LIST } from "../../elements/catalog/products/products-list"; import { PRODUCTS_LIST } from "../../elements/catalog/products/products-list";
import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../elements/shared/button-selectors";
@ -47,7 +49,7 @@ describe("Create product", () => {
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
productUtils.deleteProductsStartsWith(startsWith); productUtils.deleteProductsStartsWith(startsWith);
productUtils.createAttribute(name).then(attributeResp => { createAttribute(name).then(attributeResp => {
attribute = attributeResp; attribute = attributeResp;
}); });
}); });
@ -60,7 +62,7 @@ describe("Create product", () => {
it("should create product with variants", () => { it("should create product with variants", () => {
const randomName = `${startsWith}${faker.datatype.number()}`; const randomName = `${startsWith}${faker.datatype.number()}`;
productUtils.createTypeProduct(randomName, attribute.id); createTypeProduct({ name: randomName, attributeId: attribute.id });
seo.slug = randomName; seo.slug = randomName;
const productData = { const productData = {
generalInfo, generalInfo,
@ -88,7 +90,11 @@ describe("Create product", () => {
const prices = { sellingPrice: 6, costPrice: 3 }; const prices = { sellingPrice: 6, costPrice: 3 };
const randomName = `${startsWith}${faker.datatype.number()}`; const randomName = `${startsWith}${faker.datatype.number()}`;
seo.slug = randomName; seo.slug = randomName;
productUtils.createTypeProduct(randomName, attribute.id, false); createTypeProduct({
name: randomName,
attributeId: attribute.id,
hasVariants: false
});
const productData = { const productData = {
generalInfo, generalInfo,
seo, seo,

View file

@ -1,6 +1,7 @@
import faker from "faker"; import faker from "faker";
import { createCollection } from "../../../apiRequests/Collections"; import { createCollection } from "../../../apiRequests/Collections";
import { updateProduct } from "../../../apiRequests/Product";
import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list"; import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list";
import { import {
selectFilterOption, selectFilterOption,
@ -12,8 +13,7 @@ import { getDefaultChannel } from "../../../utils/channelsUtils";
import { import {
createProductInChannel, createProductInChannel,
createTypeAttributeAndCategoryForProduct, createTypeAttributeAndCategoryForProduct,
deleteProductsStartsWith, deleteProductsStartsWith
updateProduct
} from "../../../utils/products/productsUtils"; } from "../../../utils/products/productsUtils";
import { import {
createShipping, createShipping,

View file

@ -76,9 +76,14 @@ describe("Creating variants", () => {
const price = 10; const price = 10;
let createdProduct; let createdProduct;
createProduct(attribute.id, name, productType.id, category.id) createProduct({
attributeId: attribute.id,
name,
productTypeId: productType.id,
categoryId: category.id
})
.then(resp => { .then(resp => {
createdProduct = resp.body.data.productCreate.product; createdProduct = resp;
updateChannelInProduct({ updateChannelInProduct({
productId: createdProduct.id, productId: createdProduct.id,
channelId: defaultChannel.id channelId: defaultChannel.id
@ -145,15 +150,15 @@ describe("Creating variants", () => {
const variantsPrice = 10; const variantsPrice = 10;
let newChannel; let newChannel;
let createdProduct; let createdProduct;
createChannel(true, name, name, "PLN") createChannel({ isActive: true, name, currencyCode: "PLN" })
.then(resp => { .then(resp => {
newChannel = resp.body.data.channelCreate.channel; newChannel = resp;
productUtils.createProduct( createProduct({
attribute.id, attributeId: attribute.id,
name, name,
productType.id, productTypeId: productType.id,
category.id categoryId: category.id
); });
}) })
.then(productResp => { .then(productResp => {
createdProduct = productResp; createdProduct = productResp;

View file

@ -1,5 +1,6 @@
import faker from "faker"; import faker from "faker";
import { createCategory } from "../../apiRequests/Category";
import { createCollection } from "../../apiRequests/Collections"; import { createCollection } from "../../apiRequests/Collections";
import { getProductDetails } from "../../apiRequests/storeFront/ProductDetails"; import { getProductDetails } from "../../apiRequests/storeFront/ProductDetails";
import { PRODUCT_DETAILS } from "../../elements/catalog/products/product-details"; import { PRODUCT_DETAILS } from "../../elements/catalog/products/product-details";
@ -11,7 +12,6 @@ import { getDefaultChannel } from "../../utils/channelsUtils";
import { deleteCollectionsStartsWith } from "../../utils/collectionsUtils"; import { deleteCollectionsStartsWith } from "../../utils/collectionsUtils";
import { expectCorrectProductInformation } from "../../utils/products/checkProductInfo"; import { expectCorrectProductInformation } from "../../utils/products/checkProductInfo";
import { import {
createCategory,
createProductInChannel, createProductInChannel,
createTypeAttributeAndCategoryForProduct, createTypeAttributeAndCategoryForProduct,
deleteProductsStartsWith deleteProductsStartsWith

View file

@ -8,8 +8,11 @@ import { selectChannelVariantInDetailsPage } from "../../channelsSteps";
import { fillUpPriceList } from "./priceList"; import { fillUpPriceList } from "./priceList";
export function variantsShouldBeVisible({ name, price }) { export function variantsShouldBeVisible({ name, price }) {
cy.contains(PRODUCT_DETAILS.variantRow, name).should("be.visible"); cy.contains(PRODUCT_DETAILS.variantRow, name)
cy.contains(PRODUCT_DETAILS.variantRow, price).should("be.visible"); .should("be.visible")
.find(PRODUCT_DETAILS.variantPrice)
.invoke("text")
.then(text => expect(text).to.includes(price));
} }
export function createFirstVariant({ sku, warehouseId, price, attribute }) { export function createFirstVariant({ sku, warehouseId, price, attribute }) {
cy.get(PRODUCT_DETAILS.addVariantsButton).click(); cy.get(PRODUCT_DETAILS.addVariantsButton).click();
@ -17,6 +20,9 @@ export function createFirstVariant({ sku, warehouseId, price, attribute }) {
.contains(attribute) .contains(attribute)
.find(VARIANTS_SELECTORS.attributeCheckbox) .find(VARIANTS_SELECTORS.attributeCheckbox)
.click() .click()
.get(VARIANTS_SELECTORS.valueContainer)
.find(BUTTON_SELECTORS.checked)
.should("exist")
.get(VARIANTS_SELECTORS.nextButton) .get(VARIANTS_SELECTORS.nextButton)
.click(); .click();
fillUpPriceList(price); fillUpPriceList(price);

View file

@ -3,10 +3,12 @@ import { DRAFT_ORDER_SELECTORS } from "../elements/orders/draft-order-selectors"
import { SELECT_SHIPPING_METHOD_FORM } from "../elements/shipping/select-shipping-method-form"; import { SELECT_SHIPPING_METHOD_FORM } from "../elements/shipping/select-shipping-method-form";
export function finalizeDraftOrder(name) { export function finalizeDraftOrder(name) {
cy.get(DRAFT_ORDER_SELECTORS.addProducts) return cy
.get(DRAFT_ORDER_SELECTORS.addProducts)
.click() .click()
.get(ASSIGN_PRODUCTS_SELECTORS.searchInput) .get(ASSIGN_PRODUCTS_SELECTORS.searchInput)
.type(name); .type(name)
.then(() => {
cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, name) cy.contains(ASSIGN_PRODUCTS_SELECTORS.tableRow, name)
.find(ASSIGN_PRODUCTS_SELECTORS.checkbox) .find(ASSIGN_PRODUCTS_SELECTORS.checkbox)
.click() .click()
@ -36,4 +38,5 @@ export function finalizeDraftOrder(name) {
cy.get(DRAFT_ORDER_SELECTORS.finalizeButton).click(); cy.get(DRAFT_ORDER_SELECTORS.finalizeButton).click();
cy.wait("@OrderDraftFinalize"); cy.wait("@OrderDraftFinalize");
return cy.get("@draftOrderNumber"); return cy.get("@draftOrderNumber");
});
} }

View file

@ -32,13 +32,3 @@ export function getDefaultChannel() {
}); });
}); });
} }
export function createChannel({
isActive = true,
name,
slug = name,
currencyCode = "PLN"
}) {
return channels
.createChannel(isActive, name, slug, currencyCode)
.its("body.data.channelCreate.channel");
}

View file

@ -11,14 +11,15 @@ export function createWaitingForCaptureOrder(
let checkout; let checkout;
const auth = "token"; const auth = "token";
cy.loginInShop(); cy.loginInShop();
return createCheckout({ channelSlug, email, variantsList, address, auth }) return checkoutRequest
.createCheckout({ channelSlug, email, variantsList, address, auth })
.then(checkoutResp => { .then(checkoutResp => {
checkout = checkoutResp; checkout = checkoutResp;
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId); checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
}) })
.then(() => addPayment(checkout.id)) .then(() => addPayment(checkout.id))
.then(() => checkoutRequest.completeCheckout(checkout.id)) .then(() => checkoutRequest.completeCheckout(checkout.id))
.then(() => checkout); .then(order => ({ checkout, order }));
} }
export function createCheckoutWithVoucher({ export function createCheckoutWithVoucher({
channelSlug, channelSlug,
@ -30,7 +31,8 @@ export function createCheckoutWithVoucher({
auth auth
}) { }) {
let checkout; let checkout;
return createCheckout({ channelSlug, email, variantsList, address, auth }) return checkoutRequest
.createCheckout({ channelSlug, email, variantsList, address, auth })
.then(checkoutResp => { .then(checkoutResp => {
checkout = checkoutResp; checkout = checkoutResp;
checkoutRequest.addShippingMethod(checkout.id, shippingMethodId); checkoutRequest.addShippingMethod(checkout.id, shippingMethodId);
@ -48,7 +50,8 @@ export function createReadyToFulfillOrder(
variantsList variantsList
) { ) {
let order; let order;
return createDraftOrder(customerId, shippingMethodId, channelId) return orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId)
.then(orderResp => { .then(orderResp => {
order = orderResp; order = orderResp;
assignVariantsToOrder(order, variantsList); assignVariantsToOrder(order, variantsList);
@ -64,7 +67,8 @@ export function createOrder({
variantsList variantsList
}) { }) {
let order; let order;
return createDraftOrder(customerId, shippingMethodId, channelId) return orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId)
.then(orderResp => { .then(orderResp => {
order = orderResp; order = orderResp;
assignVariantsToOrder(order, variantsList); assignVariantsToOrder(order, variantsList);
@ -78,30 +82,6 @@ function assignVariantsToOrder(order, variantsList) {
orderRequest.addProductToOrder(order.id, variantElement.id); orderRequest.addProductToOrder(order.id, variantElement.id);
}); });
} }
export function createDraftOrder(customerId, shippingMethodId, channelId) {
return orderRequest
.createDraftOrder(customerId, shippingMethodId, channelId)
.its("body.data.draftOrderCreate.order");
}
export function createCheckout({
channelSlug,
email,
variantsList,
address,
auth
}) {
return checkoutRequest
.createCheckout({
channelSlug,
email,
productQuantity: 1,
variantsList,
address,
auth
})
.its("body.data.checkoutCreate.checkout");
}
export function addPayment(checkoutId) { export function addPayment(checkoutId) {
return checkoutRequest.addPayment( return checkoutRequest.addPayment(
checkoutId, checkoutId,
@ -109,3 +89,20 @@ export function addPayment(checkoutId) {
"not-charged" "not-charged"
); );
} }
export function createAndCompleteCheckoutWithoutShipping({
channelSlug,
email,
variantsList,
billingAddress,
auth
}) {
let checkout;
return checkoutRequest
.createCheckout({ channelSlug, email, variantsList, billingAddress, auth })
.then(checkoutResp => {
checkout = checkoutResp;
addPayment(checkout.id);
})
.then(() => checkoutRequest.completeCheckout(checkout.id))
.then(order => ({ checkout, order }));
}

View file

@ -18,15 +18,16 @@ export function createProductInChannel({
description = null description = null
}) { }) {
let product; let product;
let variants; let variantsList;
return createProduct( return productRequest
.createProduct({
attributeId, attributeId,
name, name,
productTypeId, productTypeId,
categoryId, categoryId,
collectionId, collectionId,
description description
) })
.then(productResp => { .then(productResp => {
product = productResp; product = productResp;
productRequest.updateChannelInProduct({ productRequest.updateChannelInProduct({
@ -38,7 +39,7 @@ export function createProductInChannel({
}); });
}) })
.then(() => { .then(() => {
createVariant({ productRequest.createVariant({
productId: product.id, productId: product.id,
sku: name, sku: name,
attributeId, attributeId,
@ -49,8 +50,8 @@ export function createProductInChannel({
}); });
}) })
.then(variantsResp => { .then(variantsResp => {
variants = variantsResp; variantsList = variantsResp;
return { product, variants }; return { product, variantsList };
}); });
} }
@ -61,81 +62,21 @@ export function createTypeAttributeAndCategoryForProduct(
let attribute; let attribute;
let productType; let productType;
let category; let category;
return createAttribute(name, attributeValues) return attributeRequest
.createAttribute(name, attributeValues)
.then(attributeResp => { .then(attributeResp => {
attribute = attributeResp; attribute = attributeResp;
createTypeProduct(name, attributeResp.id); productRequest.createTypeProduct({ name, attributeId: attributeResp.id });
}) })
.then(productTypeResp => { .then(productTypeResp => {
productType = productTypeResp; productType = productTypeResp;
createCategory(name); categoryRequest.createCategory(name);
}) })
.then(categoryResp => { .then(categoryResp => {
category = categoryResp; category = categoryResp;
return { attribute, category, productType }; return { attribute, category, productType };
}); });
} }
export function createAttribute(name, attributeValues) {
return attributeRequest
.createAttribute(name, attributeValues)
.its("body.data.attributeCreate.attribute");
}
export function createTypeProduct(name, attributeId, hasVariants) {
return productRequest
.createTypeProduct(name, attributeId, hasVariants)
.its("body.data.productTypeCreate.productType");
}
export function createCategory(name) {
return categoryRequest
.createCategory(name)
.its("body.data.categoryCreate.category");
}
export function createProduct(
attributeId,
name,
productTypeId,
categoryId,
collectionId,
description
) {
return productRequest
.createProduct(
attributeId,
name,
productTypeId,
categoryId,
collectionId,
description
)
.its("body.data.productCreate.product");
}
export function updateProduct(productId, input) {
return productRequest
.updateProduct(productId, input)
.its("body.data.productUpdate.product");
}
export function createVariant({
productId,
sku,
attributeId,
warehouseId,
quantityInWarehouse,
channelId,
price
}) {
return productRequest
.createVariant({
productId,
sku,
attributeId,
warehouseId,
quantity: quantityInWarehouse,
channelId,
price
})
.its("body.data.productVariantBulkCreate.productVariants");
}
export function deleteProductsStartsWith(startsWith) { export function deleteProductsStartsWith(startsWith) {
cy.deleteElementsStartsWith( cy.deleteElementsStartsWith(
productRequest.deleteProductType, productRequest.deleteProductType,

View file

@ -6,10 +6,15 @@ export function createShipping({ channelId, name, address, price = 1 }) {
let shippingZone; let shippingZone;
let warehouse; let warehouse;
return createShippingZone(name, address.country, channelId) return shippingMethodRequest
.createShippingZone(name, address.country, channelId)
.then(shippingZoneResp => { .then(shippingZoneResp => {
shippingZone = shippingZoneResp; shippingZone = shippingZoneResp;
createWarehouse({ name, shippingZoneId: shippingZone.id, address }); warehouseRequest.createWarehouse({
name,
shippingZone: shippingZone.id,
address
});
}) })
.then(warehouseResp => { .then(warehouseResp => {
warehouse = warehouseResp; warehouse = warehouseResp;
@ -25,17 +30,6 @@ export function createShipping({ channelId, name, address, price = 1 }) {
}) })
.then(() => ({ shippingMethod, shippingZone, warehouse })); .then(() => ({ shippingMethod, shippingZone, warehouse }));
} }
export function createShippingZone(name, country, channelId) {
return shippingMethodRequest
.createShippingZone(name, country, channelId)
.its("body.data.shippingZoneCreate.shippingZone");
}
export function createWarehouse({ name, shippingZoneId, address }) {
return warehouseRequest
.createWarehouse({ name, shippingZone: shippingZoneId, address })
.its("body.data.createWarehouse.warehouse");
}
export function createShippingRate(name, shippingZoneId) { export function createShippingRate(name, shippingZoneId) {
return shippingMethodRequest return shippingMethodRequest
.createShippingRate(name, shippingZoneId) .createShippingRate(name, shippingZoneId)