-
Notifications
You must be signed in to change notification settings - Fork 0
/
tin_test.go
61 lines (54 loc) · 1.44 KB
/
tin_test.go
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
package tin
import (
"context"
"testing"
"github.com/invopop/gobl.tin/test"
"github.com/invopop/gobl/bill"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLookupTin(t *testing.T) {
tests := []struct {
name string
file string
expectedError error
}{
{
name: "Valid invoice",
file: "test/data/invoice-valid.json",
expectedError: ErrInvalid.WithMessage("Supplier: TIN is invalid"),
},
{
name: "No customer",
file: "test/data/invoice-no-customer.json",
expectedError: ErrInput.WithMessage("no customer found"),
},
{
name: "No tax ID",
file: "test/data/invoice-no-taxid.json",
expectedError: ErrInput.WithMessage("Customer: no tax ID provided"),
},
{
name: "Invalid Country",
file: "test/data/invoice-invalid-country.json",
expectedError: ErrNotSupported.WithMessage("Supplier: country code not supported"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
env, err := test.LoadTestEnvelope(tt.file)
require.NoError(t, err)
inv, ok := env.Extract().(*bill.Invoice)
require.True(t, ok)
ctx := context.Background()
c := New()
err = c.Lookup(ctx, inv)
if err == nil {
assert.Nil(t, tt.expectedError)
} else {
assert.Equal(t, tt.expectedError.Error(), err.Error())
assert.IsType(t, tt.expectedError, err)
}
})
}
}