Browse Source

fix(core): Consistently apply coupon code checks on MySQL DBs

Closes #1604
Michael Bromley 3 years ago
parent
commit
bfaee82c10

+ 15 - 1
packages/core/e2e/order-promotion.e2e-spec.ts

@@ -95,7 +95,7 @@ import { addPaymentToOrder, proceedToArrangingPayment } from './utils/test-order
 describe('Promotions applied to Orders', () => {
 describe('Promotions applied to Orders', () => {
     const { server, adminClient, shopClient } = createTestEnvironment({
     const { server, adminClient, shopClient } = createTestEnvironment({
         ...testConfig(),
         ...testConfig(),
-        logger: new DefaultLogger({ level: LogLevel.Info }),
+        // logger: new DefaultLogger({ level: LogLevel.Info }),
         paymentOptions: {
         paymentOptions: {
             paymentMethodHandlers: [testSuccessfulPaymentMethod],
             paymentMethodHandlers: [testSuccessfulPaymentMethod],
         },
         },
@@ -203,6 +203,20 @@ describe('Promotions applied to Orders', () => {
             expect(applyCouponCode.errorCode).toBe(ErrorCode.COUPON_CODE_EXPIRED_ERROR);
             expect(applyCouponCode.errorCode).toBe(ErrorCode.COUPON_CODE_EXPIRED_ERROR);
         });
         });
 
 
+        it('coupon code application is case-sensitive', async () => {
+            const { applyCouponCode } = await shopClient.query<
+                ApplyCouponCode.Mutation,
+                ApplyCouponCode.Variables
+            >(APPLY_COUPON_CODE, {
+                couponCode: TEST_COUPON_CODE.toLowerCase(),
+            });
+            orderResultGuard.assertErrorResult(applyCouponCode);
+            expect(applyCouponCode.message).toBe(
+                `Coupon code "${TEST_COUPON_CODE.toLowerCase()}" is not valid`,
+            );
+            expect(applyCouponCode.errorCode).toBe(ErrorCode.COUPON_CODE_INVALID_ERROR);
+        });
+
         it('applies a valid coupon code', async () => {
         it('applies a valid coupon code', async () => {
             const { applyCouponCode } = await shopClient.query<
             const { applyCouponCode } = await shopClient.query<
                 ApplyCouponCode.Mutation,
                 ApplyCouponCode.Mutation,

+ 1 - 1
packages/core/src/service/services/promotion.service.ts

@@ -230,7 +230,7 @@ export class PromotionService {
                 deletedAt: null,
                 deletedAt: null,
             },
             },
         });
         });
-        if (!promotion) {
+        if (!promotion || promotion.couponCode !== couponCode) {
             return new CouponCodeInvalidError(couponCode);
             return new CouponCodeInvalidError(couponCode);
         }
         }
         if (promotion.endsAt && +promotion.endsAt < +new Date()) {
         if (promotion.endsAt && +promotion.endsAt < +new Date()) {