@@ -349,15 +349,6 @@ func TestMixedDiscounts(t *testing.T) {
349349func TestRealWorldTaxCalculations (t * testing.T ) {
350350 settings := & Settings {
351351 PricesIncludeTaxes : true ,
352- Taxes : []* Tax {& Tax {
353- Percentage : 7 ,
354- ProductTypes : []string {"Book" },
355- Countries : []string {"USA" },
356- }, & Tax {
357- Percentage : 19 ,
358- ProductTypes : []string {"E-Book" },
359- Countries : []string {"USA" },
360- }},
361352 }
362353
363354 item1 := & TestItem {
@@ -371,26 +362,63 @@ func TestRealWorldTaxCalculations(t *testing.T) {
371362 itemType : "E-Book" ,
372363 }},
373364 }
374- item2 := & TestItem {
375- price : 3490 ,
376- itemType : "Book" ,
377- items : []Item {& TestItem {
378- price : 2300 ,
379- itemType : "Book" ,
380- }, & TestItem {
381- price : 1190 ,
382- itemType : "E-Book" ,
383- }},
384- }
385- params := PriceParameters {"USA" , "USD" , nil , []Item {item1 , item2 }}
386- price := CalculatePrice (settings , nil , params , testLogger )
387365
388- validatePrice (t , price , Price {
389- Subtotal : 5766 ,
390- Discount : 0 ,
391- NetTotal : 5766 ,
392- Taxes : 625 ,
393- Total : 6391 ,
366+ t .Run ("Single items" , func (t * testing.T ) {
367+ settings .Taxes = []* Tax {& Tax {
368+ Percentage : 7 ,
369+ ProductTypes : []string {"Book" },
370+ Countries : []string {"USA" },
371+ }, & Tax {
372+ Percentage : 21 ,
373+ ProductTypes : []string {"E-Book" },
374+ Countries : []string {"USA" },
375+ }}
376+
377+ params := PriceParameters {"USA" , "USD" , nil , []Item {item1 }}
378+ price := CalculatePrice (settings , nil , params , testLogger )
379+
380+ validatePrice (t , price , Price {
381+ Subtotal : 2602 ,
382+ Discount : 0 ,
383+ NetTotal : 2602 ,
384+ Taxes : 298 ,
385+ Total : 2900 ,
386+ })
387+ })
388+
389+ t .Run ("Two items" , func (t * testing.T ) {
390+ settings .Taxes = []* Tax {& Tax {
391+ Percentage : 7 ,
392+ ProductTypes : []string {"Book" },
393+ Countries : []string {"USA" },
394+ }, & Tax {
395+ Percentage : 19 ,
396+ ProductTypes : []string {"E-Book" },
397+ Countries : []string {"USA" },
398+ }}
399+
400+ item2 := & TestItem {
401+ price : 3490 ,
402+ itemType : "Book" ,
403+ items : []Item {& TestItem {
404+ price : 2300 ,
405+ itemType : "Book" ,
406+ }, & TestItem {
407+ price : 1190 ,
408+ itemType : "E-Book" ,
409+ }},
410+ }
411+
412+ params := PriceParameters {"USA" , "USD" , nil , []Item {item1 , item2 }}
413+ price := CalculatePrice (settings , nil , params , testLogger )
414+
415+ validatePrice (t , price , Price {
416+ Subtotal : 5766 ,
417+ Discount : 0 ,
418+ NetTotal : 5766 ,
419+ Taxes : 624 ,
420+ Total : 6390 ,
421+ })
394422 })
395423}
396424
0 commit comments