Saleor 3496 tests for single permissions (#1147)

* permissions

* orders, channels and discounts

* tests for single permissions
This commit is contained in:
Karolina Rakoczy 2021-06-10 12:48:59 +02:00 committed by GitHub
parent 2c5b0feeb1
commit 6a2524a5c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 223 additions and 149 deletions

View file

@ -10,6 +10,10 @@ export const PERMISSIONS = {
app: { app: {
permissionSelectors: [menuSelectors.LEFT_MENU_SELECTORS.app] permissionSelectors: [menuSelectors.LEFT_MENU_SELECTORS.app]
}, },
channel: {
parent: configurationAsParent,
permissionSelectors: [CONFIGURATION_SELECTORS.channels]
},
customer: { customer: {
permissionSelectors: [menuSelectors.LEFT_MENU_SELECTORS.customers] permissionSelectors: [menuSelectors.LEFT_MENU_SELECTORS.customers]
}, },

View file

@ -10,6 +10,10 @@ export const PERMISSIONS_OPTIONS = {
user: ONE_PERMISSION_USERS.app, user: ONE_PERMISSION_USERS.app,
permissions: [PERMISSIONS.app] permissions: [PERMISSIONS.app]
}, },
channel: {
user: ONE_PERMISSION_USERS.channel,
permissions: [PERMISSIONS.channel]
},
customer: { customer: {
user: ONE_PERMISSION_USERS.user, user: ONE_PERMISSION_USERS.user,
permissions: [PERMISSIONS.customer] permissions: [PERMISSIONS.customer]

View file

@ -9,6 +9,7 @@ export const USER_WITHOUT_NAME = {
password: Cypress.env("USER_PASSWORD") password: Cypress.env("USER_PASSWORD")
}; };
export const ONE_PERMISSION_USERS = { export const ONE_PERMISSION_USERS = {
channel: getOnePermissionUser("channel.manager@example.com"),
shipping: getOnePermissionUser("shipping.manager@example.com"), shipping: getOnePermissionUser("shipping.manager@example.com"),
giftCard: getOnePermissionUser("gift.card.manager@example.com"), giftCard: getOnePermissionUser("gift.card.manager@example.com"),
app: getOnePermissionUser("app.manager@example.com"), app: getOnePermissionUser("app.manager@example.com"),

View file

@ -2,14 +2,13 @@
import faker from "faker"; import faker from "faker";
import { createChannel } from "../../../apiRequests/Channels"; import { createChannel } from "../../../apiRequests/Channels";
import { LEFT_MENU_SELECTORS } from "../../../elements/account/left-menu/left-menu-selectors"; import { ONE_PERMISSION_USERS } from "../../../Data/users";
import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list"; import { PRODUCTS_LIST } from "../../../elements/catalog/products/products-list";
import { ADD_CHANNEL_FORM_SELECTORS } from "../../../elements/channels/add-channel-form-selectors"; import { ADD_CHANNEL_FORM_SELECTORS } from "../../../elements/channels/add-channel-form-selectors";
import { AVAILABLE_CHANNELS_FORM } from "../../../elements/channels/available-channels-form"; import { AVAILABLE_CHANNELS_FORM } from "../../../elements/channels/available-channels-form";
import { CHANNEL_FORM_SELECTORS } from "../../../elements/channels/channel-form-selectors"; import { CHANNEL_FORM_SELECTORS } from "../../../elements/channels/channel-form-selectors";
import { CHANNELS_SELECTORS } from "../../../elements/channels/channels-selectors"; import { CHANNELS_SELECTORS } from "../../../elements/channels/channels-selectors";
import { SELECT_CHANNELS_TO_ASSIGN } from "../../../elements/channels/select-channels-to-assign"; import { SELECT_CHANNELS_TO_ASSIGN } from "../../../elements/channels/select-channels-to-assign";
import { CONFIGURATION_SELECTORS } from "../../../elements/configuration/configuration-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";
import { ORDERS_SELECTORS } from "../../../elements/orders/orders-selectors"; import { ORDERS_SELECTORS } from "../../../elements/orders/orders-selectors";
@ -29,17 +28,10 @@ describe("Channels", () => {
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest(
}); "auth",
ONE_PERMISSION_USERS.channel
it("should navigate to channels page", () => { );
cy.visit(urlList.homePage)
.get(LEFT_MENU_SELECTORS.configuration)
.click()
.get(CONFIGURATION_SELECTORS.channels)
.click()
.location("pathname")
.should("contain", "channels");
}); });
it("should create new channel", () => { it("should create new channel", () => {
@ -65,6 +57,7 @@ describe("Channels", () => {
.click(); .click();
// new channel should be visible at product availability form // new channel should be visible at product availability form
cy.clearSessionData().loginUserViaRequest();
cy.addAliasToGraphRequest("InitialProductFilterAttributes"); cy.addAliasToGraphRequest("InitialProductFilterAttributes");
cy.visit(urlList.products); cy.visit(urlList.products);
cy.wait("@InitialProductFilterAttributes"); cy.wait("@InitialProductFilterAttributes");
@ -135,6 +128,7 @@ describe("Channels", () => {
slug: randomChannel, slug: randomChannel,
currencyCode: currency currencyCode: currency
}); });
cy.clearSessionData().loginUserViaRequest();
cy.visit(urlList.orders) cy.visit(urlList.orders)
.get(ORDERS_SELECTORS.createOrder) .get(ORDERS_SELECTORS.createOrder)
.click() .click()

View file

@ -8,10 +8,10 @@ import {
addChannelToShippingZone addChannelToShippingZone
} from "../../../apiRequests/ShippingMethod"; } from "../../../apiRequests/ShippingMethod";
import { createWarehouse } from "../../../apiRequests/Warehouse"; import { createWarehouse } from "../../../apiRequests/Warehouse";
import { ONE_PERMISSION_USERS } from "../../../Data/users";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements"; import { SHARED_ELEMENTS } from "../../../elements/shared/sharedElements";
import { SHIPPING_ZONE_DETAILS } from "../../../elements/shipping/shipping-zone-details"; import { SHIPPING_ZONE_DETAILS } from "../../../elements/shipping/shipping-zone-details";
import { SHIPPING_ZONES_LIST } from "../../../elements/shipping/shipping-zones-list";
import { selectChannelInHeader } from "../../../steps/channelsSteps"; import { selectChannelInHeader } from "../../../steps/channelsSteps";
import { import {
createShippingRate, createShippingRate,
@ -78,7 +78,6 @@ describe("Shipping methods", () => {
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
cy.visit(urlList.shippingMethods);
}); });
it("should display different price for each channel", () => { it("should display different price for each channel", () => {
@ -123,6 +122,13 @@ describe("Shipping methods", () => {
} }
) )
.then(() => { .then(() => {
cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.shipping)
.visit(urlList.shippingMethods)
.get(SHARED_ELEMENTS.header)
.should("be.visible")
.get(SHARED_ELEMENTS.progressBar)
.should("not.exist");
cy.addAliasToGraphRequest("ShippingZone"); cy.addAliasToGraphRequest("ShippingZone");
cy.getTextFromElement(SHARED_ELEMENTS.table); cy.getTextFromElement(SHARED_ELEMENTS.table);
}) })
@ -159,7 +165,11 @@ describe("Shipping methods", () => {
}); });
it("should create price based shipping method", () => { it("should create price based shipping method", () => {
const shippingName = `${startsWith}${faker.datatype.number()}`; const shippingName = `${startsWith}${faker.datatype.number()}`;
cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.shipping
);
cy.visit(urlList.shippingMethods);
createShippingZone( createShippingZone(
shippingName, shippingName,
warehouse.name, warehouse.name,
@ -185,7 +195,11 @@ describe("Shipping methods", () => {
it("should create weight based shipping method", () => { it("should create weight based shipping method", () => {
const shippingName = `${startsWith}${faker.datatype.number()}`; const shippingName = `${startsWith}${faker.datatype.number()}`;
cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.shipping
);
cy.visit(urlList.shippingMethods);
createShippingZone( createShippingZone(
shippingName, shippingName,
warehouse.name, warehouse.name,

View file

@ -4,6 +4,7 @@ import faker from "faker";
import { createChannel } from "../../../apiRequests/Channels"; import { createChannel } from "../../../apiRequests/Channels";
import { updateChannelInProduct } from "../../../apiRequests/Product"; import { updateChannelInProduct } from "../../../apiRequests/Product";
import { ONE_PERMISSION_USERS } from "../../../Data/users";
import { import {
assignProducts, assignProducts,
createSale, createSale,
@ -88,7 +89,9 @@ describe("Sales discounts", () => {
price: productPrice price: productPrice
}) })
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
cy.visit(urlList.sales); cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
.visit(urlList.sales);
const product = productResp; const product = productResp;
createSale({ createSale({
saleName, saleName,
@ -121,7 +124,9 @@ describe("Sales discounts", () => {
price: productPrice price: productPrice
}) })
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
cy.visit(urlList.sales); cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
.visit(urlList.sales);
const product = productResp; const product = productResp;
createSale({ createSale({
saleName, saleName,
@ -166,7 +171,9 @@ describe("Sales discounts", () => {
}); });
}) })
.then(() => { .then(() => {
cy.visit(urlList.sales); cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
.visit(urlList.sales);
createSale({ createSale({
saleName, saleName,
channelName: channel.name, channelName: channel.name,

View file

@ -2,6 +2,7 @@
import faker from "faker"; import faker from "faker";
import { createChannel } from "../../../apiRequests/Channels"; import { createChannel } from "../../../apiRequests/Channels";
import { ONE_PERMISSION_USERS } from "../../../Data/users";
import { import {
createVoucher, createVoucher,
discountOptions discountOptions
@ -81,58 +82,36 @@ describe("Vouchers discounts", () => {
.then(({ variantsList: variantsResp }) => (variants = variantsResp)); .then(({ variantsList: variantsResp }) => (variants = variantsResp));
}); });
beforeEach(() => {
cy.clearSessionData().loginUserViaRequest();
cy.visit(urlList.vouchers);
});
it("should create percentage voucher", () => { it("should create percentage voucher", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50; const voucherValue = 50;
createVoucher({ loginAndCreateCheckoutForVoucherWithDiscount(
voucherCode, discountOptions.PERCENTAGE,
voucherValue, voucherValue
discountOption: discountOptions.PERCENTAGE, ).then(amount => {
channelName: defaultChannel.name
});
createCheckoutForCreatedVoucher(voucherCode)
.its("checkout.totalPrice.gross.amount")
.then(amount => {
const expectedAmount = const expectedAmount =
(productPrice * voucherValue) / 100 + shippingPrice; (productPrice * voucherValue) / 100 + shippingPrice;
expect(amount).to.be.eq(expectedAmount); expect(amount).to.be.eq(expectedAmount);
}); });
}); });
it("should create fixed price voucher", () => { it("should create fixed price voucher", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50; const voucherValue = 50;
createVoucher({ loginAndCreateCheckoutForVoucherWithDiscount(
voucherCode, discountOptions.FIXED,
voucherValue, voucherValue
discountOption: discountOptions.FIXED, ).then(amount => {
channelName: defaultChannel.name
});
createCheckoutForCreatedVoucher(voucherCode)
.its("checkout.totalPrice.gross.amount")
.then(amount => {
const expectedAmount = productPrice + shippingPrice - voucherValue; const expectedAmount = productPrice + shippingPrice - voucherValue;
expect(amount).to.be.eq(expectedAmount); expect(amount).to.be.eq(expectedAmount);
}); });
}); });
it("should create free shipping voucher", () => { it("should create free shipping voucher", () => {
const voucherCode = `${startsWith}${faker.datatype.number()}`; loginAndCreateCheckoutForVoucherWithDiscount(
discountOptions.SHIPPING,
createVoucher({ null
voucherCode, ).then(amount => {
discountOption: discountOptions.SHIPPING,
channelName: defaultChannel.name
});
createCheckoutForCreatedVoucher(voucherCode)
.its("checkout.totalPrice.gross.amount")
.then(amount => {
const expectedAmount = productPrice; const expectedAmount = productPrice;
expect(amount).to.be.eq(expectedAmount); expect(amount).to.be.eq(expectedAmount);
}); });
@ -142,6 +121,9 @@ describe("Vouchers discounts", () => {
const randomName = `${startsWith}${faker.datatype.number()}`; const randomName = `${startsWith}${faker.datatype.number()}`;
const voucherValue = 50; const voucherValue = 50;
cy.clearSessionData()
.loginUserViaRequest()
.visit(urlList.vouchers);
createChannel({ name: randomName }) createChannel({ name: randomName })
.then(channel => { .then(channel => {
createVoucher({ createVoucher({
@ -168,4 +150,24 @@ describe("Vouchers discounts", () => {
auth: "token" auth: "token"
}); });
} }
function loginAndCreateCheckoutForVoucherWithDiscount(
discount,
voucherValue
) {
const voucherCode = `${startsWith}${faker.datatype.number()}`;
cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.discount)
.visit(urlList.vouchers);
createVoucher({
voucherCode,
voucherValue,
discountOption: discount,
channelName: defaultChannel.name
});
return createCheckoutForCreatedVoucher(voucherCode).its(
"checkout.totalPrice.gross.amount"
);
}
}); });

View file

@ -6,6 +6,7 @@ import {
deleteCustomersStartsWith deleteCustomersStartsWith
} from "../../../apiRequests/Customer"; } from "../../../apiRequests/Customer";
import { getOrder } from "../../../apiRequests/Order"; import { getOrder } from "../../../apiRequests/Order";
import { ONE_PERMISSION_USERS } from "../../../Data/users";
import { ORDER_REFUND } from "../../../elements/orders/order-refund"; import { ORDER_REFUND } from "../../../elements/orders/order-refund";
import { ORDERS_SELECTORS } from "../../../elements/orders/orders-selectors"; import { ORDERS_SELECTORS } from "../../../elements/orders/orders-selectors";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
@ -91,7 +92,10 @@ describe("Orders", () => {
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.order
);
}); });
it("should create order with selected channel", () => { it("should create order with selected channel", () => {
@ -108,6 +112,7 @@ describe("Orders", () => {
}); });
}); });
// This test will pass after fixing SALEOR-3154
it("should not be possible to change channel in order", () => { it("should not be possible to change channel in order", () => {
createOrder({ createOrder({
customerId: customer.id, customerId: customer.id,

View file

@ -3,6 +3,7 @@ import faker from "faker";
import { createAttribute } from "../../../apiRequests/Attribute"; import { createAttribute } from "../../../apiRequests/Attribute";
import { createTypeProduct } from "../../../apiRequests/Product"; import { createTypeProduct } from "../../../apiRequests/Product";
import { ONE_PERMISSION_USERS } from "../../../Data/users";
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";
@ -55,14 +56,10 @@ describe("Create product", () => {
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
cy.visit(urlList.products)
.get(PRODUCTS_LIST.createProductBtn)
.click();
}); });
it("should create product with variants", () => { it("should create product with variants", () => {
const randomName = `${startsWith}${faker.datatype.number()}`; const randomName = `${startsWith}${faker.datatype.number()}`;
createTypeProduct({ name: randomName, attributeId: attribute.id });
seo.slug = randomName; seo.slug = randomName;
const productData = { const productData = {
generalInfo, generalInfo,
@ -71,7 +68,7 @@ describe("Create product", () => {
productOrganization: { productType: randomName }, productOrganization: { productType: randomName },
attribute attribute
}; };
fillUpCommonFieldsForAllProductTypes(productData).then( createTpeAndFillUpProductFields(randomName, true, productData).then(
productOrgResp => (productData.productOrganization = productOrgResp) productOrgResp => (productData.productOrganization = productOrgResp)
); );
cy.addAliasToGraphRequest("ProductDetails"); cy.addAliasToGraphRequest("ProductDetails");
@ -86,15 +83,11 @@ describe("Create product", () => {
expectCorrectProductInformation(productResp, productData); expectCorrectProductInformation(productResp, productData);
}); });
}); });
it("should create product without variants", () => { it("should create product without variants", () => {
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;
createTypeProduct({
name: randomName,
attributeId: attribute.id,
hasVariants: false
});
const productData = { const productData = {
generalInfo, generalInfo,
seo, seo,
@ -102,7 +95,7 @@ describe("Create product", () => {
productOrganization: { productType: randomName }, productOrganization: { productType: randomName },
attribute attribute
}; };
fillUpCommonFieldsForAllProductTypes(productData).then( createTpeAndFillUpProductFields(randomName, false, productData).then(
productOrgResp => (productData.productOrganization = productOrgResp) productOrgResp => (productData.productOrganization = productOrgResp)
); );
selectChannelInDetailsPages(); selectChannelInDetailsPages();
@ -126,4 +119,22 @@ describe("Create product", () => {
); );
}); });
}); });
function createTpeAndFillUpProductFields(
randomName,
hasVariants,
productData
) {
createTypeProduct({
name: randomName,
attributeId: attribute.id,
hasVariants
});
cy.clearSessionData()
.loginUserViaRequest("auth", ONE_PERMISSION_USERS.product)
.visit(urlList.products)
.get(PRODUCTS_LIST.createProductBtn)
.click();
return fillUpCommonFieldsForAllProductTypes(productData);
}
}); });

View file

@ -1,6 +1,7 @@
import faker from "faker"; import faker from "faker";
import { getProductDetails } from "../../../../apiRequests/storeFront/ProductDetails"; import { getProductDetails } from "../../../../apiRequests/storeFront/ProductDetails";
import { ONE_PERMISSION_USERS } from "../../../../Data/users";
import { updateProductIsAvailableForPurchase } from "../../../../steps/catalog/products/productSteps"; import { updateProductIsAvailableForPurchase } from "../../../../steps/catalog/products/productSteps";
import { productDetailsUrl } from "../../../../url/urlList"; import { productDetailsUrl } from "../../../../url/urlList";
import { getDefaultChannel } from "../../../../utils/channelsUtils"; import { getDefaultChannel } from "../../../../utils/channelsUtils";
@ -55,7 +56,10 @@ describe("Products available in listings", () => {
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.product
);
}); });
it("should update product to available for purchase", () => { it("should update product to available for purchase", () => {
@ -84,6 +88,7 @@ describe("Products available in listings", () => {
expect(isProductAvailableForPurchase(resp)).to.be.eq(true); expect(isProductAvailableForPurchase(resp)).to.be.eq(true);
}); });
}); });
it("should update product to not available for purchase", () => { it("should update product to not available for purchase", () => {
const productName = `${startsWith}${faker.datatype.number()}`; const productName = `${startsWith}${faker.datatype.number()}`;
let product; let product;

View file

@ -1,6 +1,7 @@
import faker from "faker"; import faker from "faker";
import { getProductDetails } from "../../../../apiRequests/storeFront/ProductDetails"; import { getProductDetails } from "../../../../apiRequests/storeFront/ProductDetails";
import { ONE_PERMISSION_USERS } from "../../../../Data/users";
import { updateProductPublish } from "../../../../steps/catalog/products/productSteps"; import { updateProductPublish } from "../../../../steps/catalog/products/productSteps";
import { productDetailsUrl } from "../../../../url/urlList"; import { productDetailsUrl } from "../../../../url/urlList";
import { getDefaultChannel } from "../../../../utils/channelsUtils"; import { getDefaultChannel } from "../../../../utils/channelsUtils";
@ -14,6 +15,7 @@ describe("Published products", () => {
let productType; let productType;
let attribute; let attribute;
let category; let category;
let defaultChannel;
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
@ -29,20 +31,26 @@ describe("Published products", () => {
productType = productTypeResp; productType = productTypeResp;
attribute = attributeResp; attribute = attributeResp;
category = categoryResp; category = categoryResp;
getDefaultChannel();
} }
); )
.then(channel => {
defaultChannel = channel;
});
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.product
);
}); });
it("should update product to published", () => { it("should update product to published", () => {
const productName = `${startsWith}${faker.datatype.number()}`; const productName = `${startsWith}${faker.datatype.number()}`;
let defaultChannel;
getDefaultChannel() productsUtils
.then(channel => { .createProductInChannel({
defaultChannel = channel;
productsUtils.createProductInChannel({
name: productName, name: productName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
productTypeId: productType.id, productTypeId: productType.id,
@ -50,7 +58,6 @@ describe("Published products", () => {
categoryId: category.id, categoryId: category.id,
isPublished: false, isPublished: false,
isAvailableForPurchase: false isAvailableForPurchase: false
});
}) })
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
const product = productResp; const product = productResp;
@ -63,21 +70,18 @@ describe("Published products", () => {
expect(isVisible).to.be.eq(true); expect(isVisible).to.be.eq(true);
}); });
}); });
it("should update product to not published", () => { it("should update product to not published", () => {
const productName = `${startsWith}${faker.datatype.number()}`; const productName = `${startsWith}${faker.datatype.number()}`;
let defaultChannel;
let product; let product;
getDefaultChannel() productsUtils
.then(channel => { .createProductInChannel({
defaultChannel = channel;
productsUtils.createProductInChannel({
name: productName, name: productName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
productTypeId: productType.id, productTypeId: productType.id,
attributeId: attribute.id, attributeId: attribute.id,
categoryId: category.id categoryId: category.id
});
}) })
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
product = productResp; product = productResp;

View file

@ -1,6 +1,7 @@
import faker from "faker"; import faker from "faker";
import { searchInShop } from "../../../../apiRequests/storeFront/Search"; import { searchInShop } from "../../../../apiRequests/storeFront/Search";
import { ONE_PERMISSION_USERS } from "../../../../Data/users";
import { updateProductVisibleInListings } from "../../../../steps/catalog/products/productSteps"; import { updateProductVisibleInListings } from "../../../../steps/catalog/products/productSteps";
import { productDetailsUrl } from "../../../../url/urlList"; import { productDetailsUrl } from "../../../../url/urlList";
import { getDefaultChannel } from "../../../../utils/channelsUtils"; import { getDefaultChannel } from "../../../../utils/channelsUtils";
@ -14,6 +15,7 @@ describe("Products displayed in listings", () => {
let productType; let productType;
let attribute; let attribute;
let category; let category;
let defaultChannel;
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
@ -29,20 +31,26 @@ describe("Products displayed in listings", () => {
productType = productTypeResp; productType = productTypeResp;
attribute = attributeResp; attribute = attributeResp;
category = categoryResp; category = categoryResp;
getDefaultChannel();
} }
); )
.then(channel => {
defaultChannel = channel;
});
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.product
);
}); });
it("should update product to visible in listings", () => { it("should update product to visible in listings", () => {
const productName = `${startsWith}${faker.datatype.number()}`; const productName = `${startsWith}${faker.datatype.number()}`;
let defaultChannel;
getDefaultChannel() productsUtils
.then(channel => { .createProductInChannel({
defaultChannel = channel;
productsUtils.createProductInChannel({
name: productName, name: productName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
productTypeId: productType.id, productTypeId: productType.id,
@ -50,7 +58,6 @@ describe("Products displayed in listings", () => {
categoryId: category.id, categoryId: category.id,
visibleInListings: false, visibleInListings: false,
isAvailableForPurchase: false isAvailableForPurchase: false
});
}) })
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
const product = productResp; const product = productResp;
@ -66,20 +73,18 @@ describe("Products displayed in listings", () => {
expect(isProductVisible).to.be.eq(true); expect(isProductVisible).to.be.eq(true);
}); });
}); });
it("should update product to not visible in listings", () => { it("should update product to not visible in listings", () => {
const productName = `${startsWith}${faker.datatype.number()}`; const productName = `${startsWith}${faker.datatype.number()}`;
let defaultChannel;
getDefaultChannel() productsUtils
.then(channel => { .createProductInChannel({
defaultChannel = channel;
productsUtils.createProductInChannel({
name: productName, name: productName,
channelId: defaultChannel.id, channelId: defaultChannel.id,
productTypeId: productType.id, productTypeId: productType.id,
attributeId: attribute.id, attributeId: attribute.id,
categoryId: category.id, categoryId: category.id,
visibleInListings: true visibleInListings: true
});
}) })
.then(({ product: productResp }) => { .then(({ product: productResp }) => {
const product = productResp; const product = productResp;

View file

@ -5,6 +5,7 @@ import {
createProduct, createProduct,
updateChannelInProduct updateChannelInProduct
} from "../../../apiRequests/Product"; } from "../../../apiRequests/Product";
import { ONE_PERMISSION_USERS } from "../../../Data/users";
import { import {
createFirstVariant, createFirstVariant,
createVariant, createVariant,
@ -30,6 +31,7 @@ describe("Creating variants", () => {
let attribute; let attribute;
let productType; let productType;
let category; let category;
let newChannel;
before(() => { before(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest();
@ -50,7 +52,11 @@ describe("Creating variants", () => {
address: fixtureAddresses.plAddress address: fixtureAddresses.plAddress
}) })
) )
.then(({ warehouse: warehouseResp }) => (warehouse = warehouseResp)); .then(({ warehouse: warehouseResp }) => {
warehouse = warehouseResp;
createChannel({ isActive: true, name, currencyCode: "PLN" });
})
.then(resp => (newChannel = resp));
productUtils productUtils
.createTypeAttributeAndCategoryForProduct(name, attributeValues) .createTypeAttributeAndCategoryForProduct(name, attributeValues)
@ -68,7 +74,10 @@ describe("Creating variants", () => {
}); });
beforeEach(() => { beforeEach(() => {
cy.clearSessionData().loginUserViaRequest(); cy.clearSessionData().loginUserViaRequest(
"auth",
ONE_PERMISSION_USERS.product
);
}); });
it("should create variant visible on frontend", () => { it("should create variant visible on frontend", () => {
@ -104,6 +113,7 @@ describe("Creating variants", () => {
expect(variant).to.have.property("price", price); expect(variant).to.have.property("price", price);
}); });
}); });
it("should create several variants", () => { it("should create several variants", () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const secondVariantSku = `${startsWith}${faker.datatype.number()}`; const secondVariantSku = `${startsWith}${faker.datatype.number()}`;
@ -145,21 +155,21 @@ describe("Creating variants", () => {
expect(secondVariant).to.have.property("price", variants[1].price); expect(secondVariant).to.have.property("price", variants[1].price);
}); });
}); });
it("should create variant for many channels", () => { it("should create variant for many channels", () => {
const name = `${startsWith}${faker.datatype.number()}`; const name = `${startsWith}${faker.datatype.number()}`;
const variantsPrice = 10; const variantsPrice = 10;
let newChannel;
let createdProduct; let createdProduct;
createChannel({ isActive: true, name, currencyCode: "PLN" }) // createChannel({ isActive: true, name, currencyCode: "PLN" })
.then(resp => { // .then(resp => {
newChannel = resp; // newChannel = resp;
createProduct({ createProduct({
attributeId: attribute.id, attributeId: attribute.id,
name, name,
productTypeId: productType.id, productTypeId: productType.id,
categoryId: category.id categoryId: category.id
});
}) })
// })
.then(productResp => { .then(productResp => {
createdProduct = productResp; createdProduct = productResp;
updateChannelInProduct({ updateChannelInProduct({

View file

@ -3,6 +3,7 @@ import faker from "faker";
import { createCategory } from "../../../apiRequests/Category"; 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 { ONE_PERMISSION_USERS } from "../../../Data/users";
import { PRODUCT_DETAILS } from "../../../elements/catalog/products/product-details"; import { PRODUCT_DETAILS } from "../../../elements/catalog/products/product-details";
import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors"; import { BUTTON_SELECTORS } from "../../../elements/shared/button-selectors";
import { metadataForms } from "../../../steps/catalog/metadataSteps"; import { metadataForms } from "../../../steps/catalog/metadataSteps";
@ -56,6 +57,7 @@ describe("Update products", () => {
product = productResp; product = productResp;
}); });
}); });
it("Should update product", () => { it("Should update product", () => {
const updatedName = `${startsWith}${faker.random.number()}`; const updatedName = `${startsWith}${faker.random.number()}`;
let updatedCategory; let updatedCategory;
@ -95,8 +97,11 @@ describe("Update products", () => {
collection: updatedCollection.name collection: updatedCollection.name
} }
}; };
cy.visit(productDetailsUrl(product.id)); cy.clearSessionData()
cy.get(PRODUCT_DETAILS.collectionRemoveButtons).click(); .loginUserViaRequest("auth", ONE_PERMISSION_USERS.product)
.visit(productDetailsUrl(product.id))
.get(PRODUCT_DETAILS.collectionRemoveButtons)
.click();
fillUpCommonFieldsForAllProductTypes(productData, false); fillUpCommonFieldsForAllProductTypes(productData, false);
cy.addAliasToGraphRequest("UpdatePrivateMetadata"); cy.addAliasToGraphRequest("UpdatePrivateMetadata");
cy.addAliasToGraphRequest("UpdateMetadata"); cy.addAliasToGraphRequest("UpdateMetadata");
@ -122,15 +127,18 @@ describe("Update products", () => {
}); });
}); });
}); });
it("should delete product", () => { it("should delete product", () => {
cy.visit(productDetailsUrl(product.id)); cy.clearSessionData()
cy.addAliasToGraphRequest("ProductDelete"); .loginUserViaRequest("auth", ONE_PERMISSION_USERS.product)
cy.get(BUTTON_SELECTORS.deleteButton) .visit(productDetailsUrl(product.id))
.addAliasToGraphRequest("ProductDelete")
.get(BUTTON_SELECTORS.deleteButton)
.click() .click()
.get(BUTTON_SELECTORS.submit) .get(BUTTON_SELECTORS.submit)
.click(); .click()
cy.wait("@ProductDelete"); .wait("@ProductDelete")
cy.loginUserViaRequest("token") .loginUserViaRequest("token")
.then(() => { .then(() => {
getProductDetails(product.id, defaultChannel.slug).its("body.data"); getProductDetails(product.id, defaultChannel.slug).its("body.data");
}) })