-
Notifications
You must be signed in to change notification settings - Fork 301
/
billing_history_test.go
71 lines (66 loc) · 1.68 KB
/
billing_history_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
package godo
import (
"fmt"
"net/http"
"reflect"
"testing"
"time"
)
func TestBillingHistory_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/customers/my/billing_history", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"billing_history": [
{
"description": "Invoice for May 2018",
"amount": "12.34",
"invoice_id": "123",
"invoice_uuid": "example-uuid",
"date": "2018-06-01T08:44:38Z",
"type": "Invoice"
},
{
"description": "Payment (MC 2018)",
"amount": "-12.34",
"date": "2018-06-02T08:44:38Z",
"type": "Payment"
}
],
"meta": {
"total": 2
}
}`)
})
history, resp, err := client.BillingHistory.List(ctx, nil)
if err != nil {
t.Errorf("BillingHistory.List returned error: %v", err)
}
expectedBillingHistory := []BillingHistoryEntry{
{
Description: "Invoice for May 2018",
Amount: "12.34",
InvoiceID: PtrTo("123"),
InvoiceUUID: PtrTo("example-uuid"),
Date: time.Date(2018, 6, 1, 8, 44, 38, 0, time.UTC),
Type: "Invoice",
},
{
Description: "Payment (MC 2018)",
Amount: "-12.34",
InvoiceID: nil,
InvoiceUUID: nil,
Date: time.Date(2018, 6, 2, 8, 44, 38, 0, time.UTC),
Type: "Payment",
},
}
entries := history.BillingHistory
if !reflect.DeepEqual(entries, expectedBillingHistory) {
t.Errorf("BillingHistory.List\nBillingHistory: got=%#v\nwant=%#v", entries, expectedBillingHistory)
}
expectedMeta := &Meta{Total: 2}
if !reflect.DeepEqual(resp.Meta, expectedMeta) {
t.Errorf("BillingHistory.List\nMeta: got=%#v\nwant=%#v", resp.Meta, expectedMeta)
}
}