projects/storefrontapp-e2e-cypress/cypress/helpers/payment-methods.ts
Properties |
accountHolderName |
accountHolderName:
|
Type : string
|
billingAddress |
billingAddress:
|
Type : literal type
|
cardNumber |
cardNumber:
|
Type : number
|
cardType |
cardType:
|
Type : literal type
|
defaultPayment |
defaultPayment:
|
Type : boolean
|
expiryMonth |
expiryMonth:
|
Type : string
|
expiryYear |
expiryYear:
|
Type : string
|
saved |
saved:
|
Type : boolean
|
import { waitForPage } from './checkout-flow';
interface PaymentDetail {
accountHolderName: string;
cardNumber: number;
cardType: { code: string };
expiryMonth: string;
expiryYear: string;
defaultPayment: boolean;
saved: boolean;
billingAddress: {
firstName: string;
lastName: string;
titleCode: string;
line1: string;
line2?: string;
town: string;
postalCode: string;
country: { isocode: string };
};
}
export const testPaymentDetail: PaymentDetail[] = [
{
accountHolderName: 'test user',
cardNumber: 4111111111111111,
cardType: { code: 'visa' },
expiryMonth: '12',
expiryYear: '2027',
defaultPayment: true,
saved: true,
billingAddress: {
firstName: 'test',
lastName: 'user',
titleCode: 'mr',
line1: '999 de Maisonneuve',
line2: '',
town: 'Montreal',
postalCode: 'H4B3L4',
country: { isocode: 'US' },
},
},
{
accountHolderName: 'named user',
cardNumber: 1234123412341234,
cardType: { code: 'visa' },
expiryMonth: '03',
expiryYear: '2126',
defaultPayment: false,
saved: true,
billingAddress: {
firstName: 'named',
lastName: 'user',
titleCode: 'mr',
line1: '999 de Maisonneuve',
line2: '',
town: 'Montreal',
postalCode: 'H4B3L4',
country: { isocode: 'US' },
},
},
];
export function verifyPaymentCard(cardLength: number) {
cy.get('.cx-payment .cx-body').then(() => {
cy.get('cx-card').should('exist');
cy.get('cx-card').should('have.length', cardLength);
});
}
export function visitPaymentDetailsPage() {
const paymentDetailPage = waitForPage(
'/my-account/payment-details',
'getPaymentDetail'
);
cy.selectUserMenuOption({ option: 'Payment Details' });
cy.wait(`@${paymentDetailPage}`).its('response.statusCode').should('eq', 200);
}
export function addPaymentMethod(paymentDetail: PaymentDetail) {
cy.get('.cx-total')
.first()
.then(($cart) => {
const cartid = $cart.text().match(/[0-9]+/)[0];
cy.request({
method: 'POST',
url: `${Cypress.env('API_URL')}/${Cypress.env(
'OCC_PREFIX'
)}/${Cypress.env(
'BASE_SITE'
)}/users/current/carts/${cartid}/paymentdetails`,
headers: {
Authorization: `bearer ${
JSON.parse(localStorage.getItem('spartacus⚿⚿auth')).token
.access_token
}`,
},
body: paymentDetail,
}).then((response) => {
expect(response.status).to.eq(201);
});
});
}