diff --git a/tests/pw/feature-map/feature-map.yml b/tests/pw/feature-map/feature-map.yml index fc0572af2b..e7758eee31 100644 --- a/tests/pw/feature-map/feature-map.yml +++ b/tests/pw/feature-map/feature-map.yml @@ -184,13 +184,17 @@ vendor: vendor can view payment settings menu page [lite]: true vendor can add paypal payment method [lite]: true + vendor can update paypal payment method [lite]: true + vendor can remove paypal payment method [lite]: true vendor can add bank payment method [lite]: true - vendor can add Skrill payment method: true + vendor can update bank payment method [lite]: true + vendor can remove bank payment method [lite]: true + vendor can add skrill payment method: true + vendor can update skrill payment method: true + vendor can remove skrill payment method: true vendor can add custom payment method: true - vendor can disconnect paypal payment method: true - vendor can disconnect bank payment method: true - vendor can disconnect Skrill payment method: true - vendor can disconnect custom payment method: true + vendor can update custom payment method: true + vendor can remove custom payment method: true - page: 'Shop' features: diff --git a/tests/pw/pages/paymentsPage.ts b/tests/pw/pages/paymentsPage.ts index 3c13eaffb7..c8e92ecb03 100644 --- a/tests/pw/pages/paymentsPage.ts +++ b/tests/pw/pages/paymentsPage.ts @@ -16,13 +16,13 @@ export class PaymentsPage extends AdminPage { // payment methods - async goToPaymentSettings() { + async goToWcPaymentSettings() { await this.goIfNotThere(data.subUrls.backend.wc.paymentSettings); } // admin setup basic payment methods async setupBasicPaymentMethods(payment: payment) { - await this.goToPaymentSettings(); + await this.goToWcPaymentSettings(); // bank transfer await this.enablePaymentMethod(paymentSettingsAdmin.enableDirectBankTransfer); @@ -38,7 +38,7 @@ export class PaymentsPage extends AdminPage { // admin setup stripe sonnect async setupStripeConnect(payment: payment) { - await this.goToPaymentSettings(); + await this.goToWcPaymentSettings(); await this.click(paymentSettingsAdmin.setupDokanStripeConnect); // setup strip connect @@ -63,7 +63,7 @@ export class PaymentsPage extends AdminPage { // admin setup dokan paypal marketplace async setupPaypalMarketPlace(payment: payment) { - await this.goToPaymentSettings(); + await this.goToWcPaymentSettings(); await this.click(paymentSettingsAdmin.setupDokanPayPalMarketplace); // setup paypal marketplace @@ -91,7 +91,7 @@ export class PaymentsPage extends AdminPage { // admin setup mangopay async setupMangoPay(payment: payment) { - await this.goToPaymentSettings(); + await this.goToWcPaymentSettings(); await this.click(paymentSettingsAdmin.setupDokanMangoPay); // setup mangopay @@ -138,7 +138,7 @@ export class PaymentsPage extends AdminPage { // admin setup razorpay async setupRazorpay(payment: payment) { - await this.goToPaymentSettings(); + await this.goToWcPaymentSettings(); await this.click(paymentSettingsAdmin.setupDokanRazorpay); // setup razorpay @@ -162,7 +162,7 @@ export class PaymentsPage extends AdminPage { // admin setup stripe express async setupStripeExpress(payment: payment) { - await this.goToPaymentSettings(); + await this.goToWcPaymentSettings(); await this.click(paymentSettingsAdmin.setupDokanStripeExpress); @@ -217,46 +217,53 @@ export class PaymentsPage extends AdminPage { // paymentMethods dropdown is visible await this.toBeVisible(paymentSettingsVendor.paymentMethods.addPaymentMethodDropDown); - await this.notToHaveCount(paymentSettingsVendor.paymentMethods.noOfPaymentMethods, 0); + // await this.notToHaveCount(paymentSettingsVendor.paymentMethods.noOfPaymentMethods, 0); } - // vendor set basic payment settings - async setBasicPaymentSettings(payment: vendor['payment']): Promise { - await this.setBasicPayment({ ...data.vendor.payment, methodName: 'paypal' }); - await this.setBankTransfer(payment); - await this.setBasicPayment({ ...data.vendor.payment, methodName: 'skrill' }); - await this.setBasicPayment({ ...data.vendor.payment, methodName: 'custom' }); - } - - // set basic payment method [paypal, skrill, custom ] - async setBasicPayment(paymentMethod: vendor['payment']): Promise { - switch (paymentMethod.methodName) { + // goto payment settings + async goToPaymentSettings(methodName: string): Promise { + switch (methodName) { case 'paypal': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.paypal); + await this.goto(data.subUrls.frontend.vDashboard.paypal); + break; + + case 'bank': + await this.goto(data.subUrls.frontend.vDashboard.bankTransfer); break; case 'skrill': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.skrill); + await this.goto(data.subUrls.frontend.vDashboard.skrill); break; case 'custom': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.customPayment); + await this.goto(data.subUrls.frontend.vDashboard.customPayment); break; default: break; } + } + // set basic payment method [paypal, skrill, custom ] + async addBasicPayment(paymentMethod: vendor['payment']): Promise { + await this.goToPaymentSettings(paymentMethod.methodName); await this.clearAndType(paymentSettingsVendor.paymentEmail, paymentMethod.email()); await this.clickAndWaitForResponse(data.subUrls.ajax, paymentSettingsVendor.updateSettings); await this.toContainText(paymentSettingsVendor.updateSettingsSuccessMessage, paymentMethod.saveSuccessMessage); } + // disconnect basic payment method [paypal, skrill, custom ] + async removeBasicPayment(paymentMethod: vendor['payment']): Promise { + await this.goToPaymentSettings(paymentMethod.methodName); + await this.clickAndWaitForResponse(data.subUrls.ajax, paymentSettingsVendor.disconnectPayment); + await this.toContainText(paymentSettingsVendor.updateSettingsSuccessMessage, paymentMethod.saveSuccessMessage); + } + // bank transfer payment settings - async setBankTransfer(paymentMethod: vendor['payment']): Promise { + async addBankTransfer(paymentMethod: vendor['payment']): Promise { await this.goIfNotThere(data.subUrls.frontend.vDashboard.bankTransfer); - await this.clickIfVisible(paymentSettingsVendor.disconnectAccount); + // await this.clickIfVisible(paymentSettingsVendor.disconnectAccount); await this.clearAndType(paymentSettingsVendor.bankAccountName, paymentMethod.bankAccountName); await this.selectByValue(paymentSettingsVendor.bankAccountType, paymentMethod.bankAccountType); await this.clearAndType(paymentSettingsVendor.bankAccountNumber, paymentMethod.bankAccountNumber); @@ -270,31 +277,4 @@ export class PaymentsPage extends AdminPage { await this.clickAndWaitForResponse(data.subUrls.ajax, paymentSettingsVendor.addAccount); await this.toContainText(paymentSettingsVendor.updateSettingsSuccessMessage, paymentMethod.saveSuccessMessage); } - - // disconnect basic payment method [paypal, skrill, custom ] - async disconnectBasicPayment(paymentMethod: vendor['payment']): Promise { - switch (paymentMethod.methodName) { - case 'paypal': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.paypal); - break; - - case 'bank': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.bankTransfer); - break; - - case 'skrill': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.skrill); - break; - - case 'custom': - await this.goIfNotThere(data.subUrls.frontend.vDashboard.customPayment); - break; - - default: - break; - } - - await this.clickAndWaitForResponse(data.subUrls.ajax, paymentSettingsVendor.disconnectPayment); - await this.toContainText(paymentSettingsVendor.updateSettingsSuccessMessage, paymentMethod.saveSuccessMessage); - } } diff --git a/tests/pw/tests/e2e/payments.spec.ts b/tests/pw/tests/e2e/payments.spec.ts index 43bfa370f4..5d9b288816 100644 --- a/tests/pw/tests/e2e/payments.spec.ts +++ b/tests/pw/tests/e2e/payments.spec.ts @@ -3,6 +3,11 @@ import { PaymentsPage } from '@pages/paymentsPage'; import { ApiUtils } from '@utils/apiUtils'; import { data } from '@utils/testData'; import { payloads } from '@utils/payloads'; +import { dbUtils } from '@utils/dbUtils'; +import { dbData } from '@utils/dbData'; +import { helpers } from '@utils/helpers'; + +const { VENDOR_ID } = process.env; test.describe('Payments test', () => { let admin: PaymentsPage; @@ -20,10 +25,13 @@ test.describe('Payments test', () => { vendor = new PaymentsPage(vPage); apiUtils = new ApiUtils(await request.newContext()); + // await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: [] }); }); test.afterAll(async () => { await apiUtils.updateBatchWcSettingsOptions('general', payloads.currency, payloads.adminAuth); + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', dbData.testData.dokan.paymentSettings); + // await apiUtils.setStoreSettings(payloads.defaultStoreSettings, payloads.vendorAuth); await aPage.close(); await vPage.close(); await apiUtils.dispose(); @@ -71,40 +79,63 @@ test.describe('Payments test', () => { }); test('vendor can add paypal payment method', { tag: ['@lite', '@vendor'] }, async () => { - await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'paypal' }); + // await apiUtils.setStoreSettings({ payment: { paypal: { email: '' } } }, payloads.vendorAuth); + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: '' } } }); + await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'paypal' }); + }); + + test('vendor can update paypal payment method', { tag: ['@lite', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: 'paypal@g.c' } } }); + await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'paypal' }); + }); + + test('vendor can remove paypal payment method', { tag: ['@lite', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: 'paypal@g.c' } } }); + await vendor.removeBasicPayment({ ...data.vendor.payment, methodName: 'paypal' }); }); test('vendor can add bank payment method', { tag: ['@lite', '@vendor'] }, async () => { - await vendor.setBankTransfer(data.vendor.payment); + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', helpers.emptyObjectValues(dbData.testData.dokan.paymentSettings.bank)); + await vendor.addBankTransfer(data.vendor.payment); }); - test('vendor can add Skrill payment method', { tag: ['@pro', '@vendor'] }, async () => { - await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'skrill' }); + test('vendor can update bank payment method', { tag: ['@lite', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', dbData.testData.dokan.paymentSettings.bank); + await vendor.addBankTransfer(data.vendor.payment); }); - test('vendor can add custom payment method', { tag: ['@pro', '@vendor'] }, async () => { - await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'custom' }); + test('vendor can remove bank payment method', { tag: ['@lite', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', dbData.testData.dokan.paymentSettings.bank); + await vendor.removeBasicPayment({ ...data.vendor.payment, methodName: 'bank' }); }); - test('vendor can disconnect paypal payment method', { tag: ['@lite', '@vendor'] }, async () => { - await vendor.disconnectBasicPayment({ ...data.vendor.payment, methodName: 'paypal' }); - //reset - await apiUtils.setStoreSettings(payloads.defaultStoreSettings, payloads.vendorAuth); // todo: need to reset only payment method + test('vendor can add skrill payment method', { tag: ['@pro', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { skrill: { email: '' } } }); + await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'skrill' }); }); - test('vendor can disconnect bank payment method', { tag: ['@lite', '@vendor'] }, async () => { - await vendor.disconnectBasicPayment({ ...data.vendor.payment, methodName: 'bank' }); - // reset - await apiUtils.setStoreSettings(payloads.defaultStoreSettings, payloads.vendorAuth); // todo: need to reset only payment method + test('vendor can update skrill payment method', { tag: ['@pro', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { skrill: { email: 'skrill@g.c' } } }); + await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'skrill' }); + }); + + test('vendor can remove skrill payment method', { tag: ['@pro', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { skrill: { email: 'skrill@g.c' } } }); + await vendor.removeBasicPayment({ ...data.vendor.payment, methodName: 'skrill' }); + }); + + test('vendor can add custom payment method', { tag: ['@pro', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { dokan_custom: { value: '' } } }); + await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'custom' }); }); - test('vendor can disconnect Skrill payment method', { tag: ['@pro', '@vendor'] }, async () => { - // todo: need to add skrill connect via db - await vendor.disconnectBasicPayment({ ...data.vendor.payment, methodName: 'skrill' }); + test('vendor can update custom payment method', { tag: ['@pro', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { dokan_custom: { value: '0123456789' } } }); + await vendor.addBasicPayment({ ...data.vendor.payment, methodName: 'custom' }); }); - test('vendor can disconnect custom payment method', { tag: ['@pro', '@vendor'] }, async () => { - // todo: need to add skrill connect via db - await vendor.disconnectBasicPayment({ ...data.vendor.payment, methodName: 'custom' }); + test('vendor can remove custom payment method', { tag: ['@pro', '@vendor'] }, async () => { + await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { dokan_custom: { value: '0123456789' } } }); + await vendor.removeBasicPayment({ ...data.vendor.payment, methodName: 'custom' }); }); }); diff --git a/tests/pw/utils/dbData.ts b/tests/pw/utils/dbData.ts index 3dc413252e..f3cea8a3bd 100644 --- a/tests/pw/utils/dbData.ts +++ b/tests/pw/utils/dbData.ts @@ -1420,6 +1420,30 @@ export const dbData = { length_duration: '', addon_settings: [], }, + + // vendor payment settings + paymentSettings: { + paypal: { + email: 'paypal@g.com', + }, + bank: { + ac_name: 'accountName', + ac_number: '0123456789', + bank_name: 'bankName', + ac_type: 'personal', + bank_addr: 'bankAddress', + routing_number: '9876543210', + iban: 'QWERTY12345', + swift: 'AZERTY98765', + declaration: 'on', + }, + dokan_custom: { + value: '0123456789QWERTY', + }, + skrill: { + email: 'skrill@g.com', + }, + }, }, }, }; diff --git a/tests/pw/utils/helpers.ts b/tests/pw/utils/helpers.ts index ec37d44a95..58e4ef95ce 100644 --- a/tests/pw/utils/helpers.ts +++ b/tests/pw/utils/helpers.ts @@ -466,6 +466,12 @@ export const helpers = { return `rgb(${r}, ${g}, ${b})`; }, + // empty object values + emptyObjectValues: (obj: { [key: string]: any }) => (Object.keys(obj).forEach(key => (obj[key] = '')), obj), + + // is object + isPlainObject: (value: any) => value !== null && typeof value === 'object' && !Array.isArray(value), + // deep merge arrays deepMergeArrays(targetArray: any[], sourceArray: any[]) { if (targetArray.every((item: any) => item instanceof Object && !Array.isArray(item)) && sourceArray.every(item => item instanceof Object && !Array.isArray(item))) { @@ -488,7 +494,7 @@ export const helpers = { const result = { ...target }; for (const key of Object.keys(source)) { - if (source[key] instanceof Object && target[key] instanceof Object) { + if (this.isPlainObject(source[key]) && this.isPlainObject(target[key])) { result[key] = this.deepMergeObjects(target[key], source[key]); } else if (Array.isArray(source[key]) && Array.isArray(target[key])) { result[key] = this.deepMergeArrays(target[key], source[key]); diff --git a/tests/pw/utils/testData.ts b/tests/pw/utils/testData.ts index 7e27412899..446e762d2a 100644 --- a/tests/pw/utils/testData.ts +++ b/tests/pw/utils/testData.ts @@ -1410,7 +1410,6 @@ export const data = { payment: { methodName: '', - // email: () => faker.internet.email(), email: () => `${faker.person.firstName('male')}@email.com`, bankAccountName: 'accountName', bankAccountType: faker.helpers.arrayElement(['personal', 'business']),