-
Notifications
You must be signed in to change notification settings - Fork 2
/
document_test.go
130 lines (102 loc) · 2.53 KB
/
document_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package giniapi
import (
"context"
"testing"
"time"
)
func Test_TimingTotal(t *testing.T) {
timing := Timing{
Upload: 2,
Processing: 5,
}
assertEqual(t, timing.Total(), time.Duration(7), "")
}
func Test_DocumentString(t *testing.T) {
doc := Document{
ID: "fb9877fc-f23c-40df-9e81-26e51f26682d",
}
assertEqual(t, doc.String(), "fb9877fc-f23c-40df-9e81-26e51f26682d", "Document.String() should return document ID")
}
func Test_DocumentUpdate(t *testing.T) {
doc := Document{
client: testOauthClient(t),
Name: "original",
Links: Links{
Document: testHTTPServer.URL + "/test/document/update",
},
}
ctx := context.Background()
resp := doc.Update(ctx)
assertEqual(t, resp.Error, nil, "")
assertEqual(t, doc.Name, "Updated!", "")
}
func Test_DocumentDelete(t *testing.T) {
doc := Document{
client: testOauthClient(t),
Links: Links{
Document: testHTTPServer.URL + "/test/document/delete",
},
}
ctx := context.Background()
resp := doc.Delete(ctx)
assertEqual(t, resp.Error, nil, "")
}
func Test_DocumentGetLayout(t *testing.T) {
doc := Document{
client: testOauthClient(t),
Links: Links{
Layout: testHTTPServer.URL + "/test/layout",
},
}
ctx := context.Background()
_, resp := doc.GetLayout(ctx)
assertEqual(t, resp.Error, nil, "")
}
func Test_DocumentGetExtractions(t *testing.T) {
doc := Document{
client: testOauthClient(t),
Links: Links{
Extractions: testHTTPServer.URL + "/test/extractions",
},
}
ctx := context.Background()
_, resp := doc.GetExtractions(ctx, false)
assertEqual(t, resp.Error, nil, "")
}
func Test_DocumentGetProcessed(t *testing.T) {
doc := Document{
client: testOauthClient(t),
Links: Links{
Processed: testHTTPServer.URL + "/test/processed",
},
}
ctx := context.Background()
docBytes, resp := doc.GetProcessed(ctx)
assertEqual(t, resp.Error, nil, "")
assertEqual(t, string(docBytes), "get processed", "")
}
func Test_DocumentSubmitFeedback(t *testing.T) {
doc := Document{
client: testOauthClient(t),
Links: Links{
Extractions: testHTTPServer.URL + "/test/feedback",
},
}
feedback := map[string]map[string]interface{}{
"iban": map[string]interface{}{
"entity": "iban",
"value": "DE22222111117777766666",
},
}
ctx := context.Background()
resp := doc.SubmitFeedback(ctx, feedback)
// single label
assertEqual(t, resp.Error, nil, "")
feedback["bic"] = map[string]interface{}{
"entity": "bic",
"value": "HYVEDEMMXXX",
}
resp = doc.SubmitFeedback(ctx, feedback)
// multiple labels
assertEqual(t, resp.Error, nil, "")
}