Use switch-case to get coupons

This commit is contained in:
Rodel Calasagsag 2021-07-01 20:02:59 +08:00
parent cd463d0a92
commit 60b5b183da
2 changed files with 22 additions and 23 deletions

View File

@ -26,29 +26,29 @@ const couponsTable = [
['fixed product', { text: '$5.00' }, { text: '$4.99' }] ['fixed product', { text: '$5.00' }, { text: '$4.99' }]
]; ];
let coupons; let couponFixedCart;
let couponPercentage;
let couponFixedProduct;
const getCoupon = (couponType) => { const getCoupon = (couponType) => {
const coupon = coupons.find((pair) => pair.includes(couponType))[1]; switch (couponType) {
return coupon; case 'fixed cart':
return couponFixedCart;
case 'percentage':
return couponPercentage;
case 'fixed product':
return couponFixedProduct;
}
}; };
const runCartApplyCouponsTest = () => { const runCartApplyCouponsTest = () => {
describe('Cart applying coupons', () => { describe('Cart applying coupons', () => {
let couponFixedCart;
let couponPercentage;
let couponFixedProduct;
beforeAll(async () => { beforeAll(async () => {
await createSimpleProduct(); await createSimpleProduct();
couponFixedCart = await createCoupon(); couponFixedCart = await createCoupon();
couponPercentage = await createCoupon('50', 'Percentage discount'); couponPercentage = await createCoupon('50', 'Percentage discount');
couponFixedProduct = await createCoupon('5', 'Fixed product discount'); couponFixedProduct = await createCoupon('5', 'Fixed product discount');
coupons = [
['fixed cart', couponFixedCart],
['percentage', couponPercentage],
['fixed product', couponFixedProduct]
];
await shopper.emptyCart(); await shopper.emptyCart();
await shopper.goToShop(); await shopper.goToShop();
await shopper.addToCartFromShopPage('Simple product'); await shopper.addToCartFromShopPage('Simple product');

View File

@ -27,29 +27,28 @@ const couponsTable = [
['fixed product', { text: '$5.00' }, { text: '$4.99' }] ['fixed product', { text: '$5.00' }, { text: '$4.99' }]
]; ];
let coupons; let couponFixedCart;
let couponPercentage;
let couponFixedProduct;
const getCoupon = (couponType) => { const getCoupon = (couponType) => {
const coupon = coupons.find((pair) => pair.includes(couponType))[1]; switch (couponType) {
return coupon; case 'fixed cart':
return couponFixedCart;
case 'percentage':
return couponPercentage;
case 'fixed product':
return couponFixedProduct;
}
}; };
const runCheckoutApplyCouponsTest = () => { const runCheckoutApplyCouponsTest = () => {
describe('Checkout coupons', () => { describe('Checkout coupons', () => {
let couponFixedCart;
let couponPercentage;
let couponFixedProduct;
beforeAll(async () => { beforeAll(async () => {
await createSimpleProduct(); await createSimpleProduct();
couponFixedCart = await createCoupon(); couponFixedCart = await createCoupon();
couponPercentage = await createCoupon('50', 'Percentage discount'); couponPercentage = await createCoupon('50', 'Percentage discount');
couponFixedProduct = await createCoupon('5', 'Fixed product discount'); couponFixedProduct = await createCoupon('5', 'Fixed product discount');
coupons = [
['fixed cart', couponFixedCart],
['percentage', couponPercentage],
['fixed product', couponFixedProduct]
];
await shopper.emptyCart(); await shopper.emptyCart();
await shopper.goToShop(); await shopper.goToShop();
await waitForSelectorWithoutThrow( '.add_to_cart_button' ); await waitForSelectorWithoutThrow( '.add_to_cart_button' );