Skip to content

Commit

Permalink
e2e: improve coupon fraud tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JuroUhlar committed Jan 29, 2024
1 parent 6aefd62 commit 16f1800
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion e2e/coupon-fraud.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page, test } from '@playwright/test';
import { Page, test, expect } from '@playwright/test';
import { resetScenarios } from './resetHelper';
import { TEST_IDS } from '../src/client/testIDs';
import { COUPON_FRAUD_COPY } from '../src/pages/api/coupon-fraud/claim';
Expand All @@ -21,12 +21,14 @@ test.describe('Coupon fraud', () => {
await insertCoupon(page, 'Does not exist');
await submitCoupon(page);
await page.getByText(COUPON_FRAUD_COPY.doesNotExist).waitFor();
await expect(page.getByTestId(TEST_IDS.common.cart.discount)).toBeAttached({ attached: false });
});

test('should apply correct coupon only once', async ({ page }) => {
await insertCoupon(page, 'Promo3000');
await submitCoupon(page);
await page.getByText(COUPON_FRAUD_COPY.success).waitFor();
await page.getByTestId(TEST_IDS.common.cart.discount);

await submitCoupon(page);
await page.getByText(COUPON_FRAUD_COPY.usedBefore).waitFor();
Expand All @@ -35,6 +37,7 @@ test.describe('Coupon fraud', () => {
test('should prevent spamming multiple coupons', async ({ page }) => {
await insertCoupon(page, 'Promo3000');
await submitCoupon(page);
await page.getByTestId(TEST_IDS.common.cart.discount);
await page.getByText(COUPON_FRAUD_COPY.success).waitFor();

await insertCoupon(page, 'BlackFriday');
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/common/Cart/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const Cart: FunctionComponent<CartProps> = ({ items, discount, taxPerItem
<span>{format$(taxesApplied)}</span>
</div>
{discount > 0 && (
<div className={classNames(styles.item, styles.discount)}>
<div className={classNames(styles.item, styles.discount)} data-testid={TEST_IDS.common.cart.discount}>
<span>Coupon Discount {discount}%</span>
<span>-{format$(discountApplied)}</span>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/client/testIDs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const TEST_IDS = {
cartItemCount: 'cartItemCount',
cartItemPrice: 'cartItemPrice',
cartSubTotal: 'cartSubTotal',
discount: 'discount',
},
alert: 'alert',
},
Expand Down

0 comments on commit 16f1800

Please sign in to comment.