Skip to content

Commit

Permalink
Add vendor coupon tests (getdokan#2470)
Browse files Browse the repository at this point in the history
* Add vendor coupon tests

* Update test tags
  • Loading branch information
shashwatahalder01 authored Dec 7, 2024
1 parent e0ce1a0 commit 3af31a0
Showing 1 changed file with 73 additions and 7 deletions.
80 changes: 73 additions & 7 deletions tests/pw/tests/api/calculation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ test.describe.serial('fee recipient calculation test', () => {
});
});

// todo: vendor coupon tests [skipped wc order api doesn't support vendor coupon]
test.describe.serial('marketplace coupon calculation test', () => {
let apiUtils: ApiUtils;

Expand All @@ -387,10 +386,10 @@ test.describe.serial('marketplace coupon calculation test', () => {
});

test('marketplace coupon: single coupon', { tag: ['@lite'] }, async () => {
const [, , code1] = await apiUtils.createMarketPlaceCoupon({ ...payloads.createMarketPlaceCoupon(), discount_type: 'percent' }, payloads.adminAuth);
const [, , couponCode] = await apiUtils.createMarketPlaceCoupon({ ...payloads.createMarketPlaceCoupon(), discount_type: 'percent' }, payloads.adminAuth);

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: code1 }] }, payloads.vendorAuth);
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: couponCode }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

Expand Down Expand Up @@ -425,18 +424,85 @@ test.describe.serial('marketplace coupon calculation test', () => {
});

test('marketplace coupon: percent coupon', { tag: ['@lite'] }, async () => {
const [, , code1] = await apiUtils.createMarketPlaceCoupon({ ...payloads.createMarketPlaceCoupon(), discount_type: 'percent' }, payloads.adminAuth);
const [, , couponCode] = await apiUtils.createMarketPlaceCoupon({ ...payloads.createMarketPlaceCoupon(), discount_type: 'percent' }, payloads.adminAuth);

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: code1 }] }, payloads.vendorAuth);
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: couponCode }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

test('marketplace coupon: fixed_cart coupon', { tag: ['@lite'] }, async () => {
const [, , code1] = await apiUtils.createMarketPlaceCoupon({ ...payloads.createMarketPlaceCoupon(), discount_type: 'fixed_cart' }, payloads.adminAuth);
const [, , couponCode] = await apiUtils.createMarketPlaceCoupon({ ...payloads.createMarketPlaceCoupon(), discount_type: 'fixed_cart' }, payloads.adminAuth);

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: couponCode }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});
});

test.describe.serial('vendor coupon calculation test', () => {
let apiUtils: ApiUtils;

test.beforeAll(async () => {
apiUtils = new ApiUtils(await request.newContext());
await apiUtils.setUpTaxRate(payloads.enableTax, { ...payloads.createTaxRate, rate: '10' });
await dbUtils.setOptionValue(dbData.dokan.optionName.selling, dbData.dokan.sellingSettings);
const store = await apiUtils.getSingleStore(VENDOR_ID);
await apiUtils.updateStore(VENDOR_ID, { ...store, ...payloads.vendorwiseCommission, admin_commission: '', admin_additional_fee: '' });
await apiUtils.updateSingleWcSettingOptions('general', 'woocommerce_calc_discounts_sequentially', { value: 'no' });
});

test('vendor coupon: single coupon', { tag: ['@pro'] }, async () => {
const [, , couponCode] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: couponCode }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

test('vendor coupon: multiple coupon', { tag: ['@pro'] }, async () => {
const [, , code1] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);
const [, , code2] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);
await apiUtils.updateSingleWcSettingOptions('general', 'woocommerce_calc_discounts_sequentially', { value: 'no' });

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: code1 }, { code: code2 }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

test('vendor coupon: multiple coupon non-sequential', { tag: ['@pro'] }, async () => {
const [, , code1] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);
const [, , code2] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);
await apiUtils.updateSingleWcSettingOptions('general', 'woocommerce_calc_discounts_sequentially', { value: 'no' });

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: code1 }, { code: code2 }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

test('vendor coupon: multiple coupon sequential', { tag: ['@pro'] }, async () => {
const [, , code1] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);
const [, , code2] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);
await apiUtils.updateSingleWcSettingOptions('general', 'woocommerce_calc_discounts_sequentially', { value: 'yes' });

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: code1 }, { code: code2 }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

test('vendor coupon: percent coupon', { tag: ['@pro'] }, async () => {
const [, , couponCode] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'percent' }, payloads.vendorAuth);

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: couponCode }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});

test('vendor coupon: fixed_cart coupon', { tag: ['@pro'] }, async () => {
const [, , couponCode] = await apiUtils.createCoupon([], { ...payloads.createCoupon(), discount_type: 'fixed_cart' }, payloads.vendorAuth);

// place order and assert order calculation
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: code1 }] }, payloads.vendorAuth);
const order = await apiUtils.createOrder(payloads.createProduct(), { ...payloads.createOrder, coupon_lines: [{ code: couponCode }] }, payloads.vendorAuth);
await assertOrderCalculation(order);
});
});
Expand Down

0 comments on commit 3af31a0

Please sign in to comment.