-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathparty_test.go
More file actions
91 lines (77 loc) · 3.02 KB
/
Copy pathparty_test.go
File metadata and controls
91 lines (77 loc) · 3.02 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
package ubl_test
import (
"testing"
ubl "github.com/invopop/gobl.ubl"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/catalogues/iso"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewParty(t *testing.T) {
t.Run("invoice-complete.json", func(t *testing.T) {
doc := testInvoiceFrom(t, "invoice-complete.json")
assert.Equal(t, "inbox@example.com", doc.AccountingSupplierParty.Party.EndpointID.Value)
assert.Equal(t, "EM", doc.AccountingSupplierParty.Party.EndpointID.SchemeID)
})
t.Run("identities with iso scheme id propagate to SchemeID", func(t *testing.T) {
env := loadTestEnvelope(t, "invoice-complete.json")
inv, ok := env.Extract().(*bill.Invoice)
require.True(t, ok)
// Supplier identity without a Scope, carrying iso scheme ID:
// exercises newParty's third-pass branch.
inv.Supplier.Identities = []*org.Identity{
{
Code: "TEST-001",
Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"}),
},
}
// Payee with a legal identity carrying an ISO scheme ID.
if inv.Payment == nil {
inv.Payment = &bill.PaymentDetails{}
}
inv.Payment.Payee = &org.Party{
Name: "Test Payee",
Identities: []*org.Identity{
{
Code: "PAYEE-001",
Scope: org.IdentityScopeLegal,
Ext: tax.ExtensionsOf(cbc.CodeMap{iso.ExtKeySchemeID: "0088"}),
},
},
}
require.NoError(t, env.Calculate())
doc, err := ubl.ConvertInvoice(env)
require.NoError(t, err)
require.NotEmpty(t, doc.AccountingSupplierParty.Party.PartyIdentification)
pid := doc.AccountingSupplierParty.Party.PartyIdentification[0]
require.NotNil(t, pid.ID.SchemeID)
assert.Equal(t, "0088", *pid.ID.SchemeID)
assert.Equal(t, "TEST-001", pid.ID.Value)
require.NotNil(t, doc.PayeeParty)
// The sole identity lands in PartyLegalEntity.CompanyID without
// being duplicated into PartyIdentification (UBL-SR-20).
assert.Empty(t, doc.PayeeParty.PartyIdentification)
require.NotNil(t, doc.PayeeParty.PartyLegalEntity)
require.NotNil(t, doc.PayeeParty.PartyLegalEntity.CompanyID.SchemeID)
assert.Equal(t, "0088", *doc.PayeeParty.PartyLegalEntity.CompanyID.SchemeID)
})
t.Run("norwegian VAT numbers carry the MVA suffix", func(t *testing.T) {
env := loadTestEnvelope(t, "invoice-complete.json")
inv, ok := env.Extract().(*bill.Invoice)
require.True(t, ok)
inv.Supplier.TaxID = &tax.Identity{Country: "NO", Code: "923456783"}
require.NoError(t, env.Calculate())
doc, err := ubl.ConvertInvoice(env)
require.NoError(t, err)
require.NotEmpty(t, doc.AccountingSupplierParty.Party.PartyTaxScheme)
assert.Equal(t, "NO923456783MVA", doc.AccountingSupplierParty.Party.PartyTaxScheme[0].CompanyID.Value)
// An already-suffixed code must not be doubled.
inv.Supplier.TaxID.Code = "923456783MVA"
doc, err = ubl.ConvertInvoice(env)
require.NoError(t, err)
assert.Equal(t, "NO923456783MVA", doc.AccountingSupplierParty.Party.PartyTaxScheme[0].CompanyID.Value)
})
}