forked from invopop/gobl.ubl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoice_parse_test.go
More file actions
189 lines (152 loc) · 5.36 KB
/
invoice_parse_test.go
File metadata and controls
189 lines (152 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package ubl_test
import (
"testing"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseInvoiceTypes(t *testing.T) {
t.Run("standard invoice (380)", func(t *testing.T) {
e, err := testParseInvoice("peppol/base-example.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, bill.InvoiceTypeStandard, inv.Type)
assert.Empty(t, inv.Tags)
})
t.Run("credit note (381)", func(t *testing.T) {
e, err := testParseInvoice("peppol/base-creditnote-correction.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, bill.InvoiceTypeCreditNote, inv.Type)
assert.Empty(t, inv.Tags)
})
t.Run("proforma invoice (325)", func(t *testing.T) {
e, err := testParseInvoice("peppol/proforma-invoice.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, bill.InvoiceTypeProforma, inv.Type)
assert.Empty(t, inv.Tags)
})
t.Run("self-billed invoice (389)", func(t *testing.T) {
e, err := testParseInvoice("peppol/self-billed-invoice.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, bill.InvoiceTypeStandard, inv.Type)
assert.True(t, inv.HasTags(tax.TagSelfBilled), "should have self-billed tag")
})
t.Run("partial invoice (326)", func(t *testing.T) {
e, err := testParseInvoice("peppol/partial-invoice.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, bill.InvoiceTypeStandard, inv.Type)
assert.True(t, inv.HasTags(tax.TagPartial), "should have partial tag")
})
t.Run("self-billed credit note (261)", func(t *testing.T) {
e, err := testParseInvoice("peppol/self-billed-creditnote.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, bill.InvoiceTypeCreditNote, inv.Type)
assert.True(t, inv.HasTags(tax.TagSelfBilled), "should have self-billed tag")
})
}
func TestParseInvoiceTags(t *testing.T) {
t.Run("invoice with self-billed tag", func(t *testing.T) {
e, err := testParseInvoice("peppol/self-billed-invoice.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.True(t, inv.HasTags(tax.TagSelfBilled), "should have self-billed tag")
})
t.Run("invoice with partial tag", func(t *testing.T) {
e, err := testParseInvoice("peppol/partial-invoice.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.True(t, inv.HasTags(tax.TagPartial), "should have partial tag")
})
t.Run("credit note with self-billed tag", func(t *testing.T) {
e, err := testParseInvoice("peppol/self-billed-creditnote.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.True(t, inv.HasTags(tax.TagSelfBilled), "should have self-billed tag")
})
t.Run("standard invoice without tags", func(t *testing.T) {
e, err := testParseInvoice("peppol/base-example.xml")
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.False(t, inv.HasTags(tax.TagSelfBilled), "standard invoice should not have self-billed tag")
assert.False(t, inv.HasTags(tax.TagPartial), "standard invoice should not have partial tag")
})
}
func TestParseInvoiceTypeAndTagCombinations(t *testing.T) {
tests := []struct {
name string
filename string
expectedType string
expectedTags []string
}{
{
name: "standard invoice (380)",
filename: "peppol/base-example.xml",
expectedType: string(bill.InvoiceTypeStandard),
expectedTags: nil,
},
{
name: "credit note (381)",
filename: "peppol/base-creditnote-correction.xml",
expectedType: string(bill.InvoiceTypeCreditNote),
expectedTags: nil,
},
{
name: "proforma (325)",
filename: "peppol/proforma-invoice.xml",
expectedType: string(bill.InvoiceTypeProforma),
expectedTags: nil,
},
{
name: "self-billed standard (389)",
filename: "peppol/self-billed-invoice.xml",
expectedType: string(bill.InvoiceTypeStandard),
expectedTags: []string{string(tax.TagSelfBilled)},
},
{
name: "partial standard (326)",
filename: "peppol/partial-invoice.xml",
expectedType: string(bill.InvoiceTypeStandard),
expectedTags: []string{string(tax.TagPartial)},
},
{
name: "self-billed credit note (261)",
filename: "peppol/self-billed-creditnote.xml",
expectedType: string(bill.InvoiceTypeCreditNote),
expectedTags: []string{string(tax.TagSelfBilled)},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
e, err := testParseInvoice(tt.filename)
require.NoError(t, err)
inv, ok := e.Extract().(*bill.Invoice)
require.True(t, ok)
assert.Equal(t, tt.expectedType, string(inv.Type), "invoice type mismatch")
if tt.expectedTags == nil {
assert.False(t, inv.HasTags(tax.TagSelfBilled), "should not have self-billed tag")
assert.False(t, inv.HasTags(tax.TagPartial), "should not have partial tag")
} else {
for _, tag := range tt.expectedTags {
assert.True(t, inv.HasTags(cbc.Key(tag)), "missing expected tag: %s", tag)
}
}
})
}
}