Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: add vendor payment tests #53

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 30 additions & 50 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;
}
}
shashwatahalder01 marked this conversation as resolved.
Show resolved Hide resolved

// set basic payment method [paypal, skrill, custom ]
async setBasicPayment(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 disconnectBasicPayment(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> {
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);
}
}
59 changes: 46 additions & 13 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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for undefined VENDOR_ID

VENDOR_ID is retrieved from process.env, but there is no check to ensure it is defined. To prevent potential runtime errors during test execution, consider adding validation or a default value if VENDOR_ID is not set.


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);
shashwatahalder01 marked this conversation as resolved.
Show resolved Hide resolved
await aPage.close();
await vPage.close();
await apiUtils.dispose();
Expand Down Expand Up @@ -71,38 +79,63 @@ test.describe('Payments test', () => {
});

test('vendor can add paypal payment method', { tag: ['@lite', '@vendor'] }, async () => {
// await apiUtils.setStoreSettings({ payment: { paypal: { email: '' } } }, payloads.vendorAuth);
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: '' } } });
await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'paypal' });
});

test('vendor can add bank payment method', { tag: ['@lite', '@vendor'] }, async () => {
await vendor.setBankTransfer(data.vendor.payment);
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.setBasicPayment({ ...data.vendor.payment, methodName: 'paypal' });
});

test('vendor can add Skrill payment method', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'skrill' });
test('vendor can disconnect paypal payment method', { tag: ['@lite', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { paypal: { email: '[email protected]' } } });
await vendor.disconnectBasicPayment({ ...data.vendor.payment, methodName: 'paypal' });
});

test('vendor can add custom payment method', { tag: ['@pro', '@vendor'] }, async () => {
await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'custom' });
test('vendor can add bank payment method', { tag: ['@lite', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', helpers.emptyObjectValues(dbData.testData.dokan.paymentSettings.bank));
await vendor.setBankTransfer(data.vendor.payment);
});

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);
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.setBankTransfer(data.vendor.payment);
});

test('vendor can disconnect bank payment method', { tag: ['@lite', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', dbData.testData.dokan.paymentSettings.bank);
await vendor.disconnectBasicPayment({ ...data.vendor.payment, methodName: 'bank' });
// reset
await apiUtils.setStoreSettings(payloads.defaultStoreSettings, payloads.vendorAuth);
});

test('vendor can disconnect Skrill payment method', { tag: ['@pro', '@vendor'] }, async () => {
test('vendor can add skrill payment method', { tag: ['@pro', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { skrill: { email: '' } } });
await vendor.setBasicPayment({ ...data.vendor.payment, methodName: 'skrill' });
});

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.setBasicPayment({ ...data.vendor.payment, methodName: 'skrill' });
});

test('vendor can disconnect skrill payment method', { tag: ['@pro', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { skrill: { email: '[email protected]' } } });
await vendor.disconnectBasicPayment({ ...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.setBasicPayment({ ...data.vendor.payment, methodName: 'custom' });
});

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.setBasicPayment({ ...data.vendor.payment, methodName: 'custom' });
});

test('vendor can disconnect custom payment method', { tag: ['@pro', '@vendor'] }, async () => {
await dbUtils.updateUserMeta(VENDOR_ID, 'dokan_profile_settings', { payment: { dokan_custom: { value: '0123456789' } } });
await vendor.disconnectBasicPayment({ ...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),
shashwatahalder01 marked this conversation as resolved.
Show resolved Hide resolved

// 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