Skip to content

Commit

Permalink
Add: add vendor payment tests (#53)
Browse files Browse the repository at this point in the history
* Add: add product form tests (getdokan#2385)

* Add: add vendor payment tests

* Update: update feature map

* Update: remove test.only
  • Loading branch information
shashwatahalder01 authored Oct 3, 2024
1 parent 1697f36 commit 2fb317a
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 78 deletions.
14 changes: 9 additions & 5 deletions tests/pw/feature-map/feature-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
82 changes: 31 additions & 51 deletions tests/pw/pages/paymentsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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<void> {
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<void> {
switch (paymentMethod.methodName) {
// goto payment settings
async goToPaymentSettings(methodName: string): Promise<void> {
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<void> {
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<void> {
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<void> {
async addBankTransfer(paymentMethod: vendor['payment']): Promise<void> {
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);
Expand All @@ -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<void> {
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);
}
}
71 changes: 51 additions & 20 deletions tests/pw/tests/e2e/payments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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: '[email protected]' } } });
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: '[email protected]' } } });
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: '[email protected]' } } });
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: '[email protected]' } } });
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' });
});
});
24 changes: 24 additions & 0 deletions tests/pw/utils/dbData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,30 @@ export const dbData = {
length_duration: '',
addon_settings: [],
},

// vendor payment settings
paymentSettings: {
paypal: {
email: '[email protected]',
},
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: '[email protected]',
},
},
},
},
};
8 changes: 7 additions & 1 deletion tests/pw/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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]);
Expand Down
1 change: 0 additions & 1 deletion tests/pw/utils/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down

0 comments on commit 2fb317a

Please sign in to comment.