From 3683f284143de29c4aae47b37ae01e3bc92c8cdb Mon Sep 17 00:00:00 2001 From: quanmuito Date: Wed, 24 Jan 2024 13:27:41 +0200 Subject: [PATCH] automation test 2 --- src/__tests__/utils.test.ts | 10 ++++++---- src/utils.ts | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts index 0714b84..4661ce6 100644 --- a/src/__tests__/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -6,11 +6,12 @@ import { } from 'utils'; const cartValueCases = [ - [8.9, 1.1], [5.0, 5.0], - [10.0, 0], - [10.1, 0.1], - [11.0, 0], + [8.9, 1.1], + [9.9, 0.1], + [10.0, 0.0], + [10.1, 0.0], + [11.0, 0.0], ]; describe('Test get cart value surcharge', () => { test.each(cartValueCases)( @@ -66,6 +67,7 @@ const rushHourCases: [string, boolean][] = [ ['2024-01-26T17:30', true], ['2024-01-26T18:30', true], ['2024-01-26T19:30', false], // Fri, after rush hour + ['2024-01-26T20:30', false], // Fri, after rush hour ]; describe('Test check rush hour', () => { test.each(rushHourCases)( diff --git a/src/utils.ts b/src/utils.ts index 25ea717..dd12ecb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -40,7 +40,7 @@ export const getDeliveryDistanceSurcharge = (deliveryDistance: number): number = return DELIVERY_DISTANCE_SURCHARGE_MINIMUM + multiplier * DELIVERY_DISTANCE_SURCHARGE_INTERVAL; }; -export const getItemNumberSurcharge = (numberOfItems: number): number => { +export const getNumberOfItemsSurcharge = (numberOfItems: number): number => { if (numberOfItems <= ITEM_NUMBER_FREE) { return ITEM_NUMBER_SURCHARGE_MINIMUM; } @@ -64,7 +64,7 @@ export const isRushHour = (orderTime: string): boolean => { } // Before 3PM or after 7PM - if (hour < RUSH_HOURS_START || hour > RUSH_HOURS_END) { + if (hour < RUSH_HOURS_START || hour >= RUSH_HOURS_END) { return false; } @@ -83,7 +83,7 @@ export const getDeliveryFee = ( let cartValueSurcharge = getCartValueSurcharge(cartValue); let deliveryDistanceSurcharge = getDeliveryDistanceSurcharge(deliveryDistance); - let itemNumberSurcharge = getItemNumberSurcharge(numberOfItems); + let itemNumberSurcharge = getNumberOfItemsSurcharge(numberOfItems); let deliveryFee = cartValueSurcharge + deliveryDistanceSurcharge + itemNumberSurcharge; if (isRushHour(orderTime)) { deliveryFee *= RUSH_HOUR_MULTIPLIER;