Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC-34958: Added missing Order Management tests. #64

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions cypress/e2e/backoffice/order-management/order-creation-dms.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { container } from '@utils';
import { OrderCreationDmsDynamicFixtures, OrderManagementDmsStaticFixtures } from '@interfaces/backoffice';
import { CatalogPage, ProductPage } from '@pages/yves';
import { CheckoutScenario, CustomerLoginScenario, SelectStoreScenario } from '@scenarios/yves';
import {
CreateStoreScenario,
UserLoginScenario,
AssignStoreToProductScenario,
EnableCmsBlockForAllStoresScenario,
SetupDefaultStoreRelationsScenario,
} from '@scenarios/backoffice';
import { SalesDetailPage, SalesIndexPage } from '@pages/backoffice';
import { retryableBefore } from '../../../support/e2e';

describeIfDynamicStoreEnabled(
'order creation dms',
{ tags: ['@backoffice', '@order-management', '@dms'] },
(): void => {
const catalogPage = container.get(CatalogPage);
const productPage = container.get(ProductPage);
const salesIndexPage = container.get(SalesIndexPage);
const salesDetailPage = container.get(SalesDetailPage);

const checkoutScenario = container.get(CheckoutScenario);
const userLoginScenario = container.get(UserLoginScenario);
const customerLoginScenario = container.get(CustomerLoginScenario);
const selectStoreScenario = container.get(SelectStoreScenario);
const createStoreScenario = container.get(CreateStoreScenario);
const assignStoreToProductScenario = container.get(AssignStoreToProductScenario);
const enableCmsBlockForAllStoresScenario = container.get(EnableCmsBlockForAllStoresScenario);
const setupDefaultStoreRelationsScenario = container.get(SetupDefaultStoreRelationsScenario);

let staticFixtures: OrderManagementDmsStaticFixtures;
let dynamicFixtures: OrderCreationDmsDynamicFixtures;

retryableBefore((): void => {
({ staticFixtures, dynamicFixtures } = Cypress.env());

userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

createStoreScenario.execute({ store: staticFixtures.store, shouldTriggerPublishAndSync: true });

assignStoreToProductScenario.execute({
abstractProductSku: dynamicFixtures.product.abstract_sku,
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});

setupDefaultStoreRelations();
setupDefaultCmsBlockForStore();
});

beforeEach((): void => {
selectStoreScenario.execute(staticFixtures.store.name);
});

skipB2BIt('backoffice user should be able close an order from guest', (): void => {
addOneProductToCart();
checkoutScenario.execute({ isGuest: true, shouldTriggerOmsInCli: true });

userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

assertOmsTransitions();
});

it('backoffice user should be able close an order from customer', (): void => {
customerLoginScenario.execute({
email: dynamicFixtures.customer.email,
password: staticFixtures.defaultPassword,
});

selectStoreScenario.execute(staticFixtures.store.name);

addOneProductToCart();
checkoutScenario.execute({
idCustomerAddress: dynamicFixtures.address.id_customer_address,
shouldTriggerOmsInCli: true,
});

userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

assertOmsTransitions();
});

function assertOmsTransitions(): void {
salesIndexPage.visit();
salesIndexPage.view();

salesDetailPage.triggerOms({ state: 'Pay', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Skip timeout', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'skip picking' });
salesDetailPage.triggerOms({ state: 'Ship' });
salesDetailPage.triggerOms({ state: 'Stock update' });
salesDetailPage.triggerOms({ state: 'Close' });
}

function addOneProductToCart(): void {
catalogPage.visit();
catalogPage.searchProductFromSuggestions({ query: dynamicFixtures.product.sku });
productPage.addToCart();
}

function setupDefaultStoreRelations(): void {
setupDefaultStoreRelationsScenario.execute({
storeName: staticFixtures.store.name,
paymentMethods: staticFixtures.paymentMethods,
rootUser: {
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
},
});
}

function setupDefaultCmsBlockForStore(): void {
enableCmsBlockForAllStoresScenario.execute({
cmsBlockName: 'order-confirmation--text',
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});
enableCmsBlockForAllStoresScenario.execute({
cmsBlockName: 'order-confirmation--html',
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});
enableCmsBlockForAllStoresScenario.execute({
cmsBlockName: 'order-shipped--text',
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});
enableCmsBlockForAllStoresScenario.execute({
cmsBlockName: 'order-shipped--html',
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});
}

function skipB2BIt(description: string, testFn: () => void): void {
(['b2b'].includes(Cypress.env('repositoryId')) ? it.skip : it)(description, testFn);
}
}
);

function describeIfDynamicStoreEnabled(title: string, options: { tags: string[] }, fn: () => void): void {
(Cypress.env('isDynamicStoreEnabled') && ['suite', 'b2c', 'b2b'].includes(Cypress.env('repositoryId'))
? describe
: describe.skip)(title, fn);
}
172 changes: 172 additions & 0 deletions cypress/e2e/mp/marketplace-order-management/order-creation-dms.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { container } from '@utils';
import { OrderCreationDmsDynamicFixtures, OrderCreationDmsStaticFixtures } from '@interfaces/mp';
import { SalesDetailPage, SalesIndexPage } from '@pages/backoffice';
import { CatalogPage, ProductPage } from '@pages/yves';
import {
AssignStoreToMerchantScenario,
AssignStoreToProductScenario,
CreateStoreScenario,
SetupDefaultStoreRelationsScenario,
UserLoginScenario,
} from '@scenarios/backoffice';
import { CheckoutMpScenario, CustomerLoginScenario, SelectStoreScenario } from '@scenarios/yves';
import { ActionEnum, SalesOrdersPage } from '@pages/mp';
import { MerchantUserLoginScenario } from '@scenarios/mp';

describeDmsSuiteAndMp('order creation dms', { tags: ['@mp', '@marketplace-order-management', '@dms'] }, (): void => {
const catalogPage = container.get(CatalogPage);
const productPage = container.get(ProductPage);
const salesIndexPage = container.get(SalesIndexPage);
const salesDetailPage = container.get(SalesDetailPage);
const salesOrdersPage = container.get(SalesOrdersPage);
const userLoginScenario = container.get(UserLoginScenario);
const customerLoginScenario = container.get(CustomerLoginScenario);
const checkoutMpScenario = container.get(CheckoutMpScenario);
const merchantUserLoginScenario = container.get(MerchantUserLoginScenario);
const createStoreScenario = container.get(CreateStoreScenario);
const assignStoreToProductScenario = container.get(AssignStoreToProductScenario);
const setupDefaultStoreRelationsScenario = container.get(SetupDefaultStoreRelationsScenario);
const assignStoreToMerchantScenario = container.get(AssignStoreToMerchantScenario);
const selectStoreScenario = container.get(SelectStoreScenario);

let staticFixtures: OrderCreationDmsStaticFixtures;
let dynamicFixtures: OrderCreationDmsDynamicFixtures;

before((): void => {
({ staticFixtures, dynamicFixtures } = Cypress.env());

userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

createStoreScenario.execute({ store: staticFixtures.store, shouldTriggerPublishAndSync: true });

assignStoreToMerchant(dynamicFixtures.merchant.name);
assignStoreToProduct(dynamicFixtures.merchantProduct.abstract_sku);
setupDefaultStoreRelations();
});

beforeEach((): void => {
selectStoreScenario.execute(staticFixtures.store.name);
});

skipB2BIt('merchant user should be able close an order from guest', (): void => {
addOneProductToCart();
checkoutMpScenario.execute({ isGuest: true, shouldTriggerOmsInCli: true });

userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

assertMarketplacePaymentOmsTransitions();
});

it('merchant user should be able close an order from customer', (): void => {
customerLoginScenario.execute({
email: dynamicFixtures.customer.email,
password: staticFixtures.defaultPassword,
});

selectStoreScenario.execute(staticFixtures.store.name);

addOneProductToCart();
checkoutMpScenario.execute({
idCustomerAddress: dynamicFixtures.address.id_customer_address,
shouldTriggerOmsInCli: true,
});

userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

assertMarketplacePaymentOmsTransitions();
});

function addOneProductToCart(): void {
catalogPage.visit();
catalogPage.searchProductFromSuggestions({ query: dynamicFixtures.merchantProduct.sku });
productPage.addToCart();
}

function assertMarketplacePaymentOmsTransitions(): void {
salesIndexPage.visit();
salesIndexPage.view();

salesIndexPage.getOrderReference().then((orderReference) => {
salesDetailPage.triggerOms({ state: 'Pay', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'skip picking', shouldTriggerOmsInCli: true });

merchantUserLoginScenario.execute({
username: dynamicFixtures.merchantUser.username,
password: staticFixtures.defaultPassword,
});

if (['b2b-mp'].includes(Cypress.env('repositoryId'))) {
cy.runCliCommands(['console oms:check-condition', 'console oms:check-timeout']);
}

closeOrderFromMerchantPortal(orderReference);
closeOrderFromBackoffice();
});
}

function closeOrderFromMerchantPortal(orderReference: string): void {
salesOrdersPage.visit();
salesOrdersPage.update({ query: orderReference, action: ActionEnum.ship });

salesOrdersPage.visit();
salesOrdersPage.update({ query: orderReference, action: ActionEnum.deliver });
}

function closeOrderFromBackoffice(): void {
userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
});

salesIndexPage.visit();
salesIndexPage.view();

salesDetailPage.triggerOms({ state: 'Close' });
}

function assignStoreToMerchant(merchantName: string): void {
assignStoreToMerchantScenario.execute({
merchantName: merchantName,
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});
}

function assignStoreToProduct(abstractSku: string): void {
assignStoreToProductScenario.execute({
abstractProductSku: abstractSku,
storeName: staticFixtures.store.name,
shouldTriggerPublishAndSync: true,
});
}

function setupDefaultStoreRelations(): void {
setupDefaultStoreRelationsScenario.execute({
storeName: staticFixtures.store.name,
paymentMethods: staticFixtures.paymentMethods,
rootUser: {
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
},
});
}

function skipB2BIt(description: string, testFn: () => void): void {
(['b2b-mp'].includes(Cypress.env('repositoryId')) ? it.skip : it)(description, testFn);
}
});

function describeDmsSuiteAndMp(title: string, options: { tags: string[] }, fn: () => void): void {
(Cypress.env('isDynamicStoreEnabled') && ['suite', 'b2c-mp', 'b2b-mp'].includes(Cypress.env('repositoryId'))
? describe
: describe.skip)(title, fn);
}
Loading
Loading