forked from Invoiced/invoiced-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_test.go
101 lines (74 loc) · 2.08 KB
/
event_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
95
96
97
98
99
100
101
package invdapi
import (
"reflect"
"testing"
"github.com/gabrielsoaressantos/invoiced-go/invdendpoint"
"github.com/gabrielsoaressantos/invoiced-go/invdmockserver"
)
func TestEvent_ListAll(t *testing.T) {
key := "test api key"
var mockListResponse [1]invdendpoint.Event
mockResponse := new(invdendpoint.Event)
mockResponse.Id = int64(123)
mockListResponse[0] = *mockResponse
server, err := invdmockserver.New(200, mockListResponse, "json", true)
if err != nil {
t.Fatal(err)
}
defer server.Close()
conn := mockConnection(key, server)
entity := conn.NewEvent()
filter := invdendpoint.NewFilter()
sorter := invdendpoint.NewSort()
result, err := entity.ListAll(filter, sorter)
if err != nil {
t.Fatal("Error Creating entity", err)
}
if !reflect.DeepEqual(result[0].Event, mockResponse) {
t.Fatal("Error messages do not match up")
}
}
func TestEvent_List(t *testing.T) {
key := "test api key"
var mockResponses invdendpoint.Events
mockResponseId := int64(1523)
mockResponse := new(invdendpoint.Event)
mockResponse.Id = mockResponseId
mockResponses = append(mockResponses, *mockResponse)
server, err := invdmockserver.New(200, mockResponses, "json", true)
if err != nil {
t.Fatal(err)
}
defer server.Close()
conn := mockConnection(key, server)
entity := conn.NewEvent()
entityResp, nextEndpoint, err := entity.List(nil, nil)
if err != nil {
t.Fatal(err)
}
if nextEndpoint != "" {
t.Fatal(err)
}
if !reflect.DeepEqual(entityResp[0].Event, mockResponse) {
t.Fatal("Error Messages Do Not Match Up")
}
}
func TestEvent_Retrieve(t *testing.T) {
key := "test api key"
mockResponse := new(invdendpoint.Event)
mockResponse.Id = int64(1234)
server, err := invdmockserver.New(200, mockResponse, "json", true)
if err != nil {
t.Fatal(err)
}
defer server.Close()
conn := mockConnection(key, server)
entity := conn.NewEvent()
retrievedPayment, err := entity.Retrieve(int64(1234))
if err != nil {
t.Fatal("Error retrieving entity", err)
}
if !reflect.DeepEqual(retrievedPayment.Event, mockResponse) {
t.Fatal("Error messages do not match up")
}
}