diff --git a/modules/test/playwright/helpers/HeadlessCommerceDeliveryCartApiHelper.ts b/modules/test/playwright/helpers/HeadlessCommerceDeliveryCartApiHelper.ts index 2942d0bcea3fcb..46e46bd810a2d9 100644 --- a/modules/test/playwright/helpers/HeadlessCommerceDeliveryCartApiHelper.ts +++ b/modules/test/playwright/helpers/HeadlessCommerceDeliveryCartApiHelper.ts @@ -19,10 +19,13 @@ type TCartItemUOM = { type TCart = { accountId: number; + billingAddressId?: number; cartItems?: TCartItem[]; currencyCode?: string; id?: number; paymentMethod?: string; + shippingAddressId?: number; + shippingMethod?: string; }; export class HeadlessCommerceDeliveryCartApiHelper { @@ -34,6 +37,12 @@ export class HeadlessCommerceDeliveryCartApiHelper { this.basePath = 'headless-commerce-delivery-cart/v1.0/'; } + async checkoutCart(cartId: number) { + return this.apiHelpers.post( + `${this.apiHelpers.baseUrl}${this.basePath}/carts/${cartId}/checkout` + ); + } + async deleteCart(cartId: number) { return this.apiHelpers.delete( `${this.apiHelpers.baseUrl}${this.basePath}/carts/${cartId}` diff --git a/modules/test/playwright/pages/commerce/commerce-order-content-web/pendingOrdersPage.ts b/modules/test/playwright/pages/commerce/commerce-order-content-web/pendingOrdersPage.ts index 6b5a9786ce92c8..3d5908b4f7a652 100644 --- a/modules/test/playwright/pages/commerce/commerce-order-content-web/pendingOrdersPage.ts +++ b/modules/test/playwright/pages/commerce/commerce-order-content-web/pendingOrdersPage.ts @@ -9,6 +9,9 @@ import {searchTableRowByValue} from '../commerceDNDTablePage'; import {CommerceLayoutsPage} from '../commerceLayoutsPage'; export class PendingOrdersPage { + readonly approveButton: Locator; + readonly checkoutButton: Locator; + readonly doneButton: Locator; readonly editMenuItem: Locator; readonly errorMessageCloseButton: Locator; readonly layoutsPage: CommerceLayoutsPage; @@ -29,6 +32,12 @@ export class PendingOrdersPage { readonly viewButton: Locator; constructor(page: Page) { + this.approveButton = page.getByText('Approve'); + this.checkoutButton = page.getByText('Checkout'); + this.doneButton = page.getByRole('button', { + exact: true, + name: 'Done', + }); this.editMenuItem = page.getByRole('menuitem', { exact: true, name: 'Edit', diff --git a/modules/test/playwright/tests/commerce/commerce-order-content-web/pendingOrder.spec.ts b/modules/test/playwright/tests/commerce/commerce-order-content-web/pendingOrder.spec.ts index 7f7f072286f5b5..f46ff63bf26b2e 100644 --- a/modules/test/playwright/tests/commerce/commerce-order-content-web/pendingOrder.spec.ts +++ b/modules/test/playwright/tests/commerce/commerce-order-content-web/pendingOrder.spec.ts @@ -851,3 +851,126 @@ test('LPD-3259 As a buyer with approval workflow, when I click review order in m await expect(pendingOrdersPage.orderItemsTable).toBeVisible(); }); + +test('LPD-3440 As a order manager with buyer approval workflow, I can approve orders on pending orders page', async ({ + apiHelpers, + commerceAdminChannelDetailsPage, + commerceAdminChannelsPage, + commerceLayoutsPage, + commerceMiniCartPage, + page, + pendingOrdersPage, +}) => { + const {channel, site} = await miniumSetUp(apiHelpers); + + const account = await apiHelpers.headlessAdminUser.postAccount({ + name: getRandomString(), + type: 'business', + }); + + apiHelpers.data.push({id: account.id, type: 'account'}); + + const user = + await apiHelpers.headlessAdminUser.getUserAccountByEmailAddress( + 'demo.unprivileged@liferay.com' + ); + const rolesResponse = await apiHelpers.headlessAdminUser.getAccountRoles( + account.id + ); + + const accountRoleOrderManager = rolesResponse?.items?.filter((role) => { + return role.name === 'Order Manager'; + }); + + await apiHelpers.headlessAdminUser.assignAccountRoles( + account.externalReferenceCode, + accountRoleOrderManager[0].id, + user.emailAddress + ); + await apiHelpers.headlessAdminUser.assignUserToAccountByEmailAddress( + account.id, + ['demo.unprivileged@liferay.com'] + ); + const siteRole = + await apiHelpers.headlessAdminUser.getRoleByName('Site Member'); + await apiHelpers.headlessAdminUser.assignUserToSite( + siteRole.id, + site.id, + user.id + ); + + await commerceAdminChannelsPage.changeCommerceChannelBuyerOrderApprovalWorkflow( + 'Single Approver (Version 1)', + channel.name + ); + + await ( + await commerceAdminChannelDetailsPage.commerceChannelHealthChecksTableRowAction( + 'Fix Issue', + 'Commerce Cart' + ) + ).click(); + + const product = await apiHelpers.headlessCommerceAdminCatalog.getProducts( + new URLSearchParams({ + filter: `name eq 'Abs Sensor'`, + }) + ); + + const productId = product.items[0].productId; + + const productSkus = await apiHelpers.headlessCommerceAdminCatalog + .getProduct(productId) + .then((product) => { + return product.skus; + }); + + const sku = productSkus[0]; + + const phoneNumber = '12345'; + + const address = await apiHelpers.headlessCommerceAdminAccount.postAddress( + account.id, + {phoneNumber, regionISOCode: 'AL'} + ); + + await apiHelpers.headlessCommerceDeliveryCart.postCart( + { + accountId: account.id, + billingAddressId: address.id, + cartItems: [ + { + options: '[]', + quantity: 1, + replacedSkuId: 0, + skuId: sku.id, + }, + ], + shippingAddressId: address.id, + shippingMethod: 'fixed', + }, + channel.id + ); + + await page.goto(`/web/${site.name}`); + + await commerceMiniCartPage.miniCartButton.click(); + await commerceMiniCartPage.reviewOrderButton.click(); + await commerceMiniCartPage.submitButton.click(); + + await expect(commerceMiniCartPage.submitButton).toBeHidden(); + + await performLogout(page); + + await performLogin(page, 'demo.unprivileged'); + + await page.goto(`/web/${site.name}`); + + await commerceLayoutsPage.pendingOrdersLink.click(); + + await pendingOrdersPage.viewButton.click(); + await pendingOrdersPage.approveButton.click(); + await pendingOrdersPage.doneButton.click(); + + await expect(pendingOrdersPage.checkoutButton).toBeVisible(); +});