|
| 1 | +/* |
| 2 | + * Copyright Magmodules.eu. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +import { test, expect } from '@playwright/test'; |
| 7 | +import CheckoutPaymentPage from "Pages/frontend/CheckoutPaymentPage"; |
| 8 | +import VisitCheckoutPaymentCompositeAction from "CompositeActions/VisitCheckoutPaymentCompositeAction"; |
| 9 | +import MollieHostedPaymentPage from "Pages/mollie/MollieHostedPaymentPage"; |
| 10 | +import CheckoutSuccessPage from "Pages/frontend/CheckoutSuccessPage"; |
| 11 | +import OrdersPage from "Pages/backend/OrdersPage"; |
| 12 | +import CartPage from "Pages/frontend/CartPage"; |
| 13 | + |
| 14 | +const checkoutPaymentPage = new CheckoutPaymentPage(); |
| 15 | +const visitCheckoutPayment = new VisitCheckoutPaymentCompositeAction(); |
| 16 | +const mollieHostedPaymentPage = new MollieHostedPaymentPage(expect); |
| 17 | +const checkoutSuccessPage = new CheckoutSuccessPage(expect); |
| 18 | +const ordersPage = new OrdersPage(); |
| 19 | +const cartPage = new CartPage(); |
| 20 | + |
| 21 | +const testCases = [ |
| 22 | + {status: 'paid', orderStatus: 'Processing', title: '[C4251742] Validate the submission of an order with KBC/CBC as payment method and payment mark as "Paid"'}, |
| 23 | + {status: 'failed', orderStatus: 'Canceled', title: '[C4251743] Validate the submission of an order with KBC/CBC as payment method and payment mark as "Failed"'}, |
| 24 | + {status: 'expired', orderStatus: 'Canceled', title: '[C4251744] Validate the submission of an order with KBC/CBC as payment method and payment mark as "Expired"'}, |
| 25 | + {status: 'canceled', orderStatus: 'Canceled', title: '[C4251745] Validate the submission of an order with KBC/CBC as payment method and payment mark as "Cancelled"'}, |
| 26 | +]; |
| 27 | + |
| 28 | +for (const testCase of testCases) { |
| 29 | + test(testCase.title, async ({ page }) => { |
| 30 | + test.skip(!process.env.mollie_available_methods.includes('kbc'), 'Skipping test as KBC is not available'); |
| 31 | + |
| 32 | + await visitCheckoutPayment.visit(page); |
| 33 | + |
| 34 | + await checkoutPaymentPage.selectPaymentMethod(page, 'KBC'); |
| 35 | + await checkoutPaymentPage.placeOrder(page); |
| 36 | + |
| 37 | + const values = ['CBC', 'KBC']; |
| 38 | + const randomIndex = Math.floor(Math.random() * values.length); |
| 39 | + |
| 40 | + mollieHostedPaymentPage.selectPaymentMethod(page, values[randomIndex]); |
| 41 | + await mollieHostedPaymentPage.selectStatus(page, testCase.status); |
| 42 | + |
| 43 | + if (testCase.status === 'paid') { |
| 44 | + await checkoutSuccessPage.assertThatOrderSuccessPageIsShown(page); |
| 45 | + } |
| 46 | + |
| 47 | + if (testCase.status === 'canceled') { |
| 48 | + await cartPage.assertCartPageIsShown(page); |
| 49 | + } |
| 50 | + |
| 51 | + if (checkoutPaymentPage.orderId) { |
| 52 | + await ordersPage.openOrderById(page, checkoutPaymentPage.orderId); |
| 53 | + } else if (mollieHostedPaymentPage.incrementId) { |
| 54 | + await ordersPage.openByIncrementId(page, mollieHostedPaymentPage.incrementId); |
| 55 | + } else { |
| 56 | + await ordersPage.openLatestOrder(page); |
| 57 | + } |
| 58 | + |
| 59 | + if (testCase.status === 'expired') { |
| 60 | + await ordersPage.callFetchStatus(page); |
| 61 | + } |
| 62 | + |
| 63 | + await ordersPage.assertOrderStatusIs(page, testCase.orderStatus); |
| 64 | + }); |
| 65 | +} |
0 commit comments