File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed
Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 11import { calculateCartTotal } from "../price-calculator" ;
2+ // import { getTax } from "../utils/tax";
23
34describe ( "calculateCartTotal()" , ( ) => {
45 it ( "calculates the total of a number of cart items" , ( ) => {
5- const total = calculateCartTotal ( [ ] , 0.07 ) ;
6+ const total = calculateCartTotal ( [ ] ) ;
67 expect ( total ) . toEqual ( { status : "success" , total : "0.00" } ) ;
78 } ) ;
8- } ) ;
9+ } ) ;
10+
Original file line number Diff line number Diff line change 1+ import { getTax } from "@/utils/tax" ;
12import type { CartItem } from "@/types/cart-item" ;
23
34/*
@@ -16,8 +17,7 @@ import type { CartItem } from "@/types/cart-item";
1617 name: "Product 4",
1718 },
1819 ];
19- const tax = 0.07;
20- const total = calculateCartTotal(items, tax);
20+ const total = calculateCartTotal(items);
2121 cosole.log(total); // { status: "success", total: "38.49" }
2222
2323
@@ -41,18 +41,19 @@ import type { CartItem } from "@/types/cart-item";
4141 name: "Product 4",
4242 },
4343 ];
44- const tax = 0.07;
45- const total = calculateCartTotal(items, tax);
44+ const total = calculateCartTotal(items);
4645 cosole.log(total); // { status: "error", message: "Cart has duplicate items" }
4746 */
4847
4948 type CartTotalResult =
5049 | { status : "success" ; total : string }
5150 | { status : "error" ; message : string } ;
5251
53- export function calculateCartTotal ( cartItems : CartItem [ ] , tax ?: number ) : CartTotalResult {
52+ export function calculateCartTotal ( cartItems : CartItem [ ] ) : CartTotalResult {
53+ const tax = getTax ( ) ;
5454 return {
5555 status : "success" ,
5656 total : "0.00" ,
5757 } ;
5858}
59+
Original file line number Diff line number Diff line change 1+ /**
2+ * Get the tax rate
3+ * In a real application, this would be fetched from an API
4+ * as it changes frequently
5+ * */
6+ export const getTax = ( ) => 0.07 ;
7+
You can’t perform that action at this time.
0 commit comments