Skip to content

Commit

Permalink
automation test 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Quanmuito committed Jan 24, 2024
1 parent c576c63 commit 3683f28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)(
Expand Down Expand Up @@ -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)(
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 3683f28

Please sign in to comment.