git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/money/vat/moss_test.go (about) 1 package vat 2 3 import ( 4 "testing" 5 ) 6 7 func TestGetApplicableTax(t *testing.T) { 8 var tests = []struct { 9 VATnumber string 10 CountryCode string 11 TaxRate float64 12 ReverseCharge bool 13 Err error 14 }{ 15 // private customer within EU 16 {"", "DE", 19, false, nil}, 17 // {"", "UK", 20, false, nil}, 18 19 // business customer within EU 20 {"IE6388047V", "IE", 0, true, nil}, 21 22 // customer not in EU 23 {"", "CH", 0, false, nil}, 24 {"", "AR", 0, false, nil}, 25 } 26 27 for _, tt := range tests { 28 taxRate, reverseCharge, err := GetApplicableTax(tt.CountryCode, tt.VATnumber) 29 if err != tt.Err { 30 t.Fatalf("Expected err %v, got %v for %+v\n", tt.Err, err, tt) 31 } 32 if taxRate != tt.TaxRate { 33 t.Errorf("Expected tax rate %v, got %v for %+v\n", tt.TaxRate, taxRate, tt) 34 } 35 if reverseCharge != tt.ReverseCharge { 36 t.Errorf("Expected reverse charge %v, got %v for %+v\n", tt.ReverseCharge, reverseCharge, tt) 37 } 38 } 39 40 }