Skip to content

Commit

Permalink
LPD-3440 Add functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
dsitu authored and brianchandotcom committed Aug 27, 2024
1 parent 76bbf08 commit ad81eae
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'[email protected]'
);
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,
['[email protected]']
);
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();
});

0 comments on commit ad81eae

Please sign in to comment.