diff --git a/regimes/ch/invoices_test.go b/regimes/ch/invoices_test.go new file mode 100644 index 00000000..7a13aebb --- /dev/null +++ b/regimes/ch/invoices_test.go @@ -0,0 +1,60 @@ +package ch_test + +import ( + "testing" + + "github.com/invopop/gobl/bill" + "github.com/invopop/gobl/num" + "github.com/invopop/gobl/org" + "github.com/invopop/gobl/tax" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func validInvoice() *bill.Invoice { + return &bill.Invoice{ + Series: "TEST", + Code: "0002", + Supplier: &org.Party{ + Name: "Test Supplier", + TaxID: &tax.Identity{ + Country: "CH", + Code: "E100416306", + }, + }, + Customer: &org.Party{ + Name: "Test Customer", + TaxID: &tax.Identity{ + Country: "CH", + Code: "E432825998", + }, + }, + Lines: []*bill.Line{ + { + Quantity: num.MakeAmount(1, 0), + Item: &org.Item{ + Name: "bogus", + Price: num.MakeAmount(10000, 2), + Unit: org.UnitPackage, + }, + Taxes: tax.Set{ + { + Category: "VAT", + Rate: "standard", + }, + }, + }, + }, + } +} + +func TestInvoiceValidation(t *testing.T) { + inv := validInvoice() + require.NoError(t, inv.Calculate()) + assert.NoError(t, inv.Validate()) + + inv = validInvoice() + inv.Supplier.TaxID.Code = "" + require.NoError(t, inv.Calculate()) + assert.Error(t, inv.Validate()) +}