aboutsummaryrefslogtreecommitdiffstats
path: root/internal/multicase/multicase_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/multicase/multicase_test.go')
-rw-r--r--internal/multicase/multicase_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/multicase/multicase_test.go b/internal/multicase/multicase_test.go
new file mode 100644
index 0000000..6c737eb
--- /dev/null
+++ b/internal/multicase/multicase_test.go
@@ -0,0 +1,68 @@
+package multicase
+
+import "testing"
+
+var header = []string{"Firma", "Year", "Month", "Day", "Konto", "Bilagsnummer", "Belop", "MvaKode",
+ "BilagsArt", "BilagsArtTekst", "Tekst", "Faktura kundenr", "LevNr.", "BuntHodeID"}
+
+func row(account, number, amount, vat, typ, typeText, customer, batch string) []string {
+ return []string{"Demo AS", "2026", "10", "1", account, number, amount, vat, typ, typeText, "Demo", customer, "", batch}
+}
+
+func TestParse(t *testing.T) {
+ grid := [][]string{
+ header,
+ row("3000", "100", "-125", "3", "11", "Faktura", "20001", "1"),
+ row("20001", "100", "125", "", "11", "Faktura", "20001", "1"),
+ row("1460", "0", "-10", "", "31", "Lagerkorrigering", "", "1"),
+ row("4301", "0", "10", "", "31", "Lagerkorrigering", "", "1"),
+ row("1460", "0", "5", "", "31", "Lagerkorrigering", "", "2"),
+ row("4301", "0", "-5", "", "31", "Lagerkorrigering", "", "2"),
+ }
+ vs, err := Parse(grid)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(vs) != 3 {
+ t.Fatalf("got %d vouchers, want 3", len(vs))
+ }
+ keys := map[string]bool{}
+ for _, v := range vs {
+ keys[v.Key()] = true
+ if v.Balance() != 0 {
+ t.Errorf("%s does not balance", v.Label())
+ }
+ }
+ for _, k := range []string{"multicase:11:100", "multicase:31:bunt-1", "multicase:31:bunt-2"} {
+ if !keys[k] {
+ t.Errorf("missing voucher %s in %v", k, keys)
+ }
+ }
+ if got := vs[0].Lines[0].Amount; got != -12500 {
+ t.Errorf("amount = %d øre, want -12500", got)
+ }
+}
+
+func TestParseRejectsMissingColumns(t *testing.T) {
+ if _, err := Parse([][]string{{"Konto", "Belop"}}); err == nil {
+ t.Fatal("expected an error for a file that is not a buntfil")
+ }
+}
+
+func TestParseAmount(t *testing.T) {
+ tests := map[string]int64{
+ "": 0,
+ "46.7": 4670,
+ "-46.7": -4670,
+ "44587.125": 4458713,
+ "-4053.375": -405338,
+ "0.1": 10,
+ "1,5": 150,
+ }
+ for in, want := range tests {
+ got, err := ParseAmount(in)
+ if err != nil || got != want {
+ t.Errorf("ParseAmount(%q) = %d, %v; want %d", in, got, err, want)
+ }
+ }
+}