forked from Invoiced/invoiced-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_test.go
98 lines (70 loc) · 1.96 KB
/
file_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
package invdapi
import (
"reflect"
"testing"
"time"
"github.com/gabrielsoaressantos/invoiced-go/invdendpoint"
"github.com/gabrielsoaressantos/invoiced-go/invdmockserver"
)
func TestFile_Create(t *testing.T) {
key := "test api key"
mockResponse := new(invdendpoint.File)
mockResponse.Id = int64(1234)
mockResponse.CreatedAt = time.Now().UnixNano()
mockResponse.Name = "nomenclature"
server, err := invdmockserver.New(200, mockResponse, "json", true)
if err != nil {
t.Fatal(err)
}
defer server.Close()
conn := mockConnection(key, server)
entity := conn.NewFile()
requestEntity := entity.NewFile()
requestEntity.Id = int64(1234)
requestEntity.Name = "nomenclature"
createdEntity, err := entity.Create(requestEntity)
if err != nil {
t.Fatal("Error Creating entity", err)
}
if !reflect.DeepEqual(createdEntity.File, mockResponse) {
t.Fatal("entity was not created", createdEntity.File, mockResponse)
}
}
func TestFile_Delete(t *testing.T) {
key := "api key"
mockResponse := ""
mockResponseId := int64(1234)
server, err := invdmockserver.New(204, mockResponse, "json", true)
if err != nil {
t.Fatal(err)
}
defer server.Close()
conn := mockConnection(key, server)
entity := conn.NewFile()
entity.Id = mockResponseId
err = entity.Delete()
if err != nil {
t.Fatal("Error occurred deleting entity")
}
}
func TestFile_Retrieve(t *testing.T) {
key := "test api key"
mockResponse := new(invdendpoint.File)
mockResponse.Id = int64(1234)
mockResponse.Name = "nomenclature"
mockResponse.CreatedAt = time.Now().UnixNano()
server, err := invdmockserver.New(200, mockResponse, "json", true)
if err != nil {
t.Fatal(err)
}
defer server.Close()
conn := mockConnection(key, server)
entity := conn.NewFile()
retrievedPayment, err := entity.Retrieve(int64(1234))
if err != nil {
t.Fatal("Error retrieving entity", err)
}
if !reflect.DeepEqual(retrievedPayment.File, mockResponse) {
t.Fatal("Error messages do not match up")
}
}