forked from lokalise/go-lokalise-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc_queuedprocesses_test.go
116 lines (102 loc) · 2.89 KB
/
svc_queuedprocesses_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
package lokalise
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestQueuedProcessService_List(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(
fmt.Sprintf("/projects/%s/processes", testProjectID),
func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
testMethod(t, r, "GET")
testHeader(t, r, apiTokenHeader, testApiToken)
_, _ = fmt.Fprint(w, `{
"project_id": "`+testProjectID+`",
"processes": [
{
"process_id": "2e0559e60e856555fbc15bdf78ab2b0ca3406e8f",
"type": "file-import",
"status": "finished",
"message": "",
"created_by": 1234,
"created_by_email": "[email protected]",
"created_at": "2020-04-20 13:43:43 (Etc/UTC)",
"created_at_timestamp": 1587390223
}
]
}`)
})
r, err := client.QueuedProcesses().List(testProjectID)
if err != nil {
t.Errorf("QueuedProcesses.List returned error: %v", err)
}
want := []QueuedProcess{
{
ID: "2e0559e60e856555fbc15bdf78ab2b0ca3406e8f",
Type: "file-import",
Status: "finished",
Message: "",
WithCreationUser: WithCreationUser{
CreatedBy: 1234,
CreatedByEmail: "[email protected]",
},
WithCreationTime: WithCreationTime{
CreatedAt: "2020-04-20 13:43:43 (Etc/UTC)",
CreatedAtTs: 1587390223,
},
},
}
if !reflect.DeepEqual(r.Processes, want) {
t.Errorf("QueuedProcesses.List returned %+v, want %+v", r.Processes, want)
}
}
func TestQueuedProcessService_Retrieve(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
processId := "2e0559e60e856555fbc15bdf78ab2b0ca3406e8f"
mux.HandleFunc(
fmt.Sprintf("/projects/%s/processes/%s", testProjectID, processId),
func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
testMethod(t, r, "GET")
testHeader(t, r, apiTokenHeader, testApiToken)
_, _ = fmt.Fprint(w, `{
"project_id": "`+testProjectID+`",
"process": {
"process_id": "`+processId+`",
"type": "file-import",
"status": "finished",
"message": "",
"created_by": 1234,
"created_by_email": "[email protected]",
"created_at": "2020-04-20 13:43:43 (Etc/UTC)",
"created_at_timestamp": 1587390223
}
}`)
})
r, err := client.QueuedProcesses().Retrieve(testProjectID, processId)
if err != nil {
t.Errorf("QueuedProcesses.Retrieve returned error: %v", err)
}
want := QueuedProcess{
ID: processId,
Type: "file-import",
Status: "finished",
Message: "",
WithCreationUser: WithCreationUser{
CreatedBy: 1234,
CreatedByEmail: "[email protected]",
},
WithCreationTime: WithCreationTime{
CreatedAt: "2020-04-20 13:43:43 (Etc/UTC)",
CreatedAtTs: 1587390223,
},
}
if !reflect.DeepEqual(r.Process, want) {
t.Errorf("QueuedProcesses.Retrieve returned %+v, want %+v", r.Process, want)
}
}