diff --git a/src/basic/__tests__/basic.test.tsx b/src/basic/__tests__/basic.test.tsx index 5d2200ce..f096ad9f 100644 --- a/src/basic/__tests__/basic.test.tsx +++ b/src/basic/__tests__/basic.test.tsx @@ -6,6 +6,7 @@ import { AdminPage } from '../../refactoring/pages/AdminPage'; import { CartItem, Coupon, Product } from '../../types'; import { useCart, useCoupons, useProducts } from '../../refactoring/hooks'; import * as cartUtils from '../../refactoring/models/cart'; +import * as discountUtils from '../../refactoring/models/discount'; const mockProducts: Product[] = [ { @@ -335,24 +336,24 @@ describe('basic > ', () => { describe('calculateItemTotal', () => { test('할인 없이 총액을 계산해야 합니다.', () => { const item: CartItem = { product: testProduct, quantity: 1 }; - expect(cartUtils.calculateItemTotal(item)).toBe(100); + expect(discountUtils.calculateItemTotal(item)).toBe(100); }); test('수량에 따라 올바른 할인을 적용해야 합니다.', () => { const item: CartItem = { product: testProduct, quantity: 5 }; - expect(cartUtils.calculateItemTotal(item)).toBe(400); // 500 * 0.8 + expect(discountUtils.calculateItemTotal(item)).toBe(400); // 500 * 0.8 }); }); describe('getMaxApplicableDiscount', () => { test('할인이 적용되지 않으면 0을 반환해야 합니다.', () => { const item: CartItem = { product: testProduct, quantity: 1 }; - expect(cartUtils.getMaxApplicableDiscount(item)).toBe(0); + expect(discountUtils.calculateItemMaxDiscount(item)).toBe(0); }); test('적용 가능한 가장 높은 할인율을 반환해야 합니다.', () => { const item: CartItem = { product: testProduct, quantity: 5 }; - expect(cartUtils.getMaxApplicableDiscount(item)).toBe(0.2); + expect(discountUtils.calculateItemMaxDiscount(item)).toBe(0.2); }); }); diff --git a/src/refactoring/models/discount.ts b/src/refactoring/models/discount.ts index 18bde7f9..373e9256 100644 --- a/src/refactoring/models/discount.ts +++ b/src/refactoring/models/discount.ts @@ -1,7 +1,7 @@ import { CartItem } from 'src/types'; // 개별 항목에서 적용 가능한 최대 할인율 계산 -export const getMaxApplicableDiscount = (item: CartItem) => { +export const calculateItemMaxDiscount = (item: CartItem) => { const discount = item.product.discounts.reduce((maxDiscount, d) => { return item.quantity >= d.quantity && d.rate > maxDiscount ? d.rate : maxDiscount; }, 0); @@ -11,7 +11,7 @@ export const getMaxApplicableDiscount = (item: CartItem) => { // 개별 항목의 할인율 적용한 총 금액 계산 export const calculateItemTotal = (item: CartItem) => { const { product, quantity } = item; - const discount = getMaxApplicableDiscount(item); + const discount = calculateItemMaxDiscount(item); return product.price * quantity * (1 - discount); };