-
Notifications
You must be signed in to change notification settings - Fork 400
/
Copy pathbilling_history_test.go
84 lines (73 loc) · 1.91 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
72
73
74
75
76
77
78
79
80
81
82
83
84
package integration
import (
"fmt"
"net/http"
"net/http/httptest"
"net/http/httputil"
"os/exec"
"strings"
"testing"
"github.com/sclevine/spec"
"github.com/stretchr/testify/require"
)
var _ = suite("billingHistory", func(t *testing.T, when spec.G, it spec.S) {
var (
expect *require.Assertions
server *httptest.Server
)
it.Before(func() {
expect = require.New(t)
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Add("content-type", "application/json")
switch req.URL.Path {
case "/v2/customers/my/billing_history":
w.Write([]byte(billingHistoryListResponse))
default:
dump, err := httputil.DumpRequest(req, true)
if err != nil {
t.Fatal("failed to dump request")
}
t.Fatalf("received unknown request: %s", dump)
}
}))
})
it("gets the customer's billing history", func() {
cmd := exec.Command(builtBinaryPath,
"-t", "some-magic-token",
"-u", server.URL,
"billing-history",
"list",
)
output, err := cmd.CombinedOutput()
expect.NoError(err, fmt.Sprintf("received error output: %s", output))
expect.Equal(strings.TrimSpace(billingHistoryListOutput), strings.TrimSpace(string(output)))
})
})
const billingHistoryListOutput string = `
Date Type Description Amount Invoice ID Invoice UUID
2018-06-01T08:44:38Z Invoice Invoice for May 2018 12.34 123 example-uuid
2018-06-02T08:44:38Z Payment Payment (MC 2018) -12.34
`
const billingHistoryListResponse string = `
{
"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
}
}
`