E-Commerce

Promo code validation

Coupon engine accepts QA20, rejects EXPIRED, and ignores invalid casing differences.

User story

As a shopper, I want to apply a coupon code at checkout and see immediate feedback if it is invalid or expired.

Acceptance criteria

  • QA20 reduces total by 20%
  • Codes are case-insensitive
  • EXPIRED produces a recoverable error
  • Applied code shows a removable chip

Manual test steps

  1. 1.Open /checkout
  2. 2.Enter QA20, click Apply
  3. 3.Enter EXPIRED, click Apply
  4. 4.Remove the active code and re-enter

Expected result

QA20 chip is visible and total drops by 20%; EXPIRED keeps the original total and shows an error.

Possible bug risks

  • Stacking two codes silently
  • Discount applied to shipping when it shouldn't be
  • Removing a chip leaves the discount applied

Reference Playwright spec

promo-code.spec.ts
ts
1
2
3
4
5
6
7
8
9
10
11
12
import { test, expect } from '@playwright/test';

test('promo code accepts QA20 and rejects EXPIRED', async ({ page }) => {
  await page.goto('https://lab.hakdogan.com/checkout');
  await page.getByLabel(/promo code/i).fill('QA20');
  await page.getByRole('button', { name: /apply/i }).click();
  await expect(page.getByTestId('promo-chip')).toContainText('QA20');

  await page.getByLabel(/promo code/i).fill('EXPIRED');
  await page.getByRole('button', { name: /apply/i }).click();
  await expect(page.getByRole('alert')).toContainText(/expired/i);
});