-
Notifications
You must be signed in to change notification settings - Fork 11
/
invoice_test.go
67 lines (63 loc) · 2.02 KB
/
invoice_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
package harvest
import "testing"
func TestGetInvoice(t *testing.T) {
a := testAPI()
invoiceResponse := mockResponse("invoices", "invoice-example.json")
a.BaseURL = invoiceResponse.URL
invoice, err := a.GetInvoice(12286767, Defaults())
if err != nil {
t.Fatal(err)
}
if invoice == nil {
t.Fatal("GetInvoice returned nil")
}
if invoice.ID != 12286767 {
t.Errorf("Incorrect expense ID '%v'", invoice.ID)
}
if invoice.Client.ID != 3781881 {
t.Errorf("Incorrect client ID '%v'", invoice.Client.ID)
}
if invoice.Notes != "Thank you in advance for your prompt payment, which is essential to our ability to best serve you." {
t.Errorf("Incorrect Invoice Notes '%s'", invoice.Notes)
}
if len(invoice.LineItems) != 2 {
t.Errorf("Failed to parse LineItems from '%d'", invoice.ID)
}
if invoice.LineItems[0].Kind != "Service" {
t.Errorf("Got '%s' for first LineItem Type. Expected 'Service'", invoice.LineItems[0].Kind)
}
}
func TestGetInvoices(t *testing.T) {
a := testAPI()
a.BaseURL = mockDynamicPathResponse().URL
invoices, err := a.GetInvoices(Defaults())
if err != nil {
t.Fatal(err)
}
if len(invoices) != 8 {
t.Errorf("Incorrect number of invoices. Expected 8, got %d", len(invoices))
}
if invoices[0].ID != 12286767 {
t.Errorf("Incorrect invoice ID '%v'. Expected 12286767", invoices[0].ID)
}
if invoices[0].Subject != "Client 1 Invoice 12286767" {
t.Errorf("Incorrect invoice Subject '%s'. Expected 'Client 1 Invoice 12286767'.", invoices[0].Subject)
}
if invoices[7].Subject != "This is the last invoice" {
t.Errorf("Incorrect invoice Subject '%s'. Expected 'This is the last invoice'.", invoices[7].Subject)
}
}
func TestGetSinglePageOfInvoices(t *testing.T) {
a := testAPI()
a.BaseURL = mockDynamicPathResponse().URL
invoices, err := a.GetInvoices(Arguments{"page": "1"})
if err != nil {
t.Fatal(err)
}
if len(invoices) != 8 {
t.Errorf("Incorrect number of invoices. Expected 8, got %d", len(invoices))
}
if invoices[0].ID != 12286767 {
t.Errorf("Incorrect invoice ID '%v'", invoices[0].ID)
}
}