forked from rwestlund/quickbooks-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbill_test.go
94 lines (83 loc) · 2.45 KB
/
bill_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
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
package quickbooks
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"os"
"testing"
"time"
)
func TestBillJSON(t *testing.T) {
jsonFile, err := os.Open("data/testing/bill.json")
if err != nil {
log.Fatal("When opening JSON file: ", err)
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
if err != nil {
log.Fatal("When reading JSON file: ", err)
}
var r struct {
Bill Bill
Time Date
}
err = json.Unmarshal(byteValue, &r)
if err != nil {
log.Fatal("When decoding JSON file: ", err)
}
assert.Equal(t, "2", r.Bill.SyncToken)
assert.Equal(t, "Accounts Payable (A/P)", r.Bill.APAccountRef.Name)
assert.Equal(t, "33", r.Bill.APAccountRef.Value)
assert.Equal(t, "Norton Lumber and Building Materials", r.Bill.VendorRef.Name)
assert.Equal(t, "46", r.Bill.VendorRef.Value)
assert.Equal(t, "2014-11-06T00:00:00+00:00", r.Bill.TxnDate.String())
totalAmt, _ := r.Bill.TotalAmt.Float64()
assert.Equal(t, 103.55, totalAmt)
assert.Equal(t, "United States Dollar", r.Bill.CurrencyRef.Name)
assert.Equal(t, "USD", r.Bill.CurrencyRef.Value)
// LinkedTxn
assert.Equal(t, "3", r.Bill.SalesTermRef.Value)
assert.Equal(t, "2014-12-06T00:00:00+00:00", r.Bill.DueDate.String())
assert.Equal(t, 1, len(r.Bill.Line))
balance, _ := r.Bill.Balance.Int64()
assert.Equal(t, int64(0), balance)
assert.Equal(t, "25", r.Bill.ID)
assert.Equal(t, "2014-11-06T15:37:25-08:00", r.Bill.MetaData.CreateTime.String())
assert.Equal(t, "2015-02-09T10:11:11-08:00", r.Bill.MetaData.LastUpdatedTime.String())
}
func TestBill(t *testing.T) {
qbClient, err := getClient()
if err != nil {
log.Println(err)
t.Skip("Cannot instantiate the client")
}
jsonFile, err := os.Open("data/testing/bill.json")
if err != nil {
t.Fatal("When opening JSON file: ", err)
}
defer jsonFile.Close()
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
t.Fatal("When reading JSON file: ", err)
}
var r struct {
Bill Bill
Time Date
}
err = json.Unmarshal(byteValue, &r)
if err != nil {
t.Fatal("When decoding JSON file: ", err)
}
r.Bill.ID = ""
r.Bill.TxnDate.Time = time.Now()
createdBill, err := qbClient.CreateBill(&r.Bill)
assert.NoError(t, err)
newBill, err := qbClient.GetBillByID(createdBill.ID)
assert.NoError(t, err)
assert.Equal(t, createdBill.ID, newBill.ID)
createdBill.DocNumber = "NewNumber"
newBill, err = qbClient.UpdateBill(createdBill)
assert.NoError(t, err)
assert.Equal(t, "NewNumber", newBill.DocNumber)
}