-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathissues_test.go
311 lines (243 loc) · 7.21 KB
/
issues_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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
package redmine
import (
"os"
"strconv"
"testing"
)
var (
testIssueSubject = "Test issue subject"
testIssueDescription = "Test issue description"
testIssueSubject2 = "Test issue subject2"
testIssueDescription2 = "Test issue description2"
testIssueNote = "Test issue note"
testIssuePrivateNote = "Test issue private note"
testIssueStartDate = "2022-07-01"
testIssueDueDate = "2022-07-02"
testIssueStartDate2 = "2022-07-03"
testIssueDueDate2 = "2022-07-04"
)
func TestIssuesCRUD(t *testing.T) {
var r Context
// Get env variables
testIssueTrackerID, err := strconv.ParseInt(os.Getenv("REDMINE_TRACKER_ID"), 10, 64)
if err != nil {
t.Fatal("Issue test error: env variable `REDMINE_TRACKER_ID` is incorrect")
}
testMembershipRoleID, err := strconv.ParseInt(os.Getenv("REDMINE_ROLE_ID_1"), 10, 64)
if err != nil {
t.Fatal("Issue test error: env variable `REDMINE_ROLE_ID_1` is incorrect")
}
if testIssueTrackerID == 0 ||
testMembershipRoleID == 0 {
t.Fatal("Issue test error: env variables `REDMINE_TRACKER_ID` or `REDMINE_ROLE_ID_1` does not set")
}
// Init Redmine context
initTest(&r, t)
// Preparing auxiliary data
pCreated := testProjectCreate(t, r, []int64{testIssueTrackerID})
defer testProjectDetele(t, r, pCreated.Identifier)
uCreated := testUserCreate(t, r)
defer testUserDetele(t, r, uCreated.ID)
testMembershipAdd(t, r, pCreated.Identifier, uCreated.ID, testMembershipRoleID)
// Add and delete
iCreated := testIssueCreate(t, r, pCreated.ID, uCreated.ID, nil)
defer testIssueDetele(t, r, iCreated.ID)
// Signle get
testIssueSingleGet(t, r, iCreated.ID, uCreated.ID)
// Update
testIssueNoteAdd(t, r, iCreated.ID, testIssueNote, false)
testIssueNoteAdd(t, r, iCreated.ID, testIssuePrivateNote, true)
testIssueUpdate(t, r, iCreated.ID)
// Get multi
testIssueMultiGet(t, r, iCreated.ID)
// Get all
testIssueAllGet(t, r, iCreated.ID)
// Watchers delete and add
testIssueWatcherDelete(t, r, iCreated.ID, uCreated.ID)
testIssueWatcherAdd(t, r, iCreated.ID, uCreated.ID)
}
func testIssueCreate(t *testing.T, r Context, projectID, userID int64, upload *AttachmentUploadObject) IssueObject {
var (
u []AttachmentUploadObject
w []int64
)
if upload != nil {
u = append(u, *upload)
}
if userID > 0 {
w = append(w, userID)
}
i, s, err := r.IssueCreate(
IssueCreate{
Issue: IssueCreateObject{
ProjectID: projectID,
Subject: testIssueSubject,
WatcherUserIDs: &w,
Description: &testIssueDescription,
StartDate: &testIssueStartDate,
DueDate: &testIssueDueDate,
Uploads: &u,
},
},
)
if err != nil {
t.Fatal("Issue create error:", err, s)
}
o, s, err := r.IssueSingleGet(i.ID, IssueSingleGetRequest{})
if err != nil {
t.Fatal("Issue create error:", err, s)
}
if (o.StartDate == nil || o.DueDate == nil) || (*o.StartDate != testIssueStartDate || *o.DueDate != testIssueDueDate) {
t.Fatal("Issue create error: incorrect issue start or due date")
}
t.Logf("Issue create: success")
return i
}
func testIssueUpdate(t *testing.T, r Context, id int64) {
s, err := r.IssueUpdate(
id,
IssueUpdate{
Issue: IssueUpdateObject{
Subject: &testIssueSubject2,
Description: &testIssueDescription2,
StartDate: &testIssueStartDate2,
DueDate: &testIssueDueDate2,
IsPrivate: BoolPtr(true),
},
},
)
if err != nil {
t.Fatal("Issue update error:", err, s)
}
o, s, err := r.IssueSingleGet(id, IssueSingleGetRequest{})
if err != nil {
t.Fatal("Issue update error:", err, s)
}
if (o.StartDate == nil || o.DueDate == nil) || (*o.StartDate != testIssueStartDate2 || *o.DueDate != testIssueDueDate2) {
t.Fatal("Issue update error: incorrect issue start or due date")
}
t.Logf("Issue update: success")
}
func testIssueNoteAdd(t *testing.T, r Context, id int64, notes string, privateNotes bool) {
s, err := r.IssueUpdate(
id,
IssueUpdate{
Issue: IssueUpdateObject{
Notes: ¬es,
PrivateNotes: &privateNotes,
},
},
)
if err != nil {
t.Fatal("Issue notes add error:", err, s)
}
o, s, err := r.IssueSingleGet(id, IssueSingleGetRequest{
Includes: []IssueInclude{
IssueIncludeJournals,
},
})
if err != nil {
t.Fatal("Issue notes add error:", err, s)
}
if o.Journals == nil || len(*o.Journals) == 0 {
t.Fatal("Issue notes add error: bad journals count")
}
js := *o.Journals
j := js[len(js)-1]
if j.Notes != notes || j.PrivateNotes != privateNotes {
t.Fatal("Issue notes add error: incorrect comment text or notes privacy")
}
t.Logf("Issue notes add: success")
}
func testIssueDetele(t *testing.T, r Context, id int64) {
_, err := r.IssueDelete(id)
if err != nil {
t.Fatal("Issue delete error:", err)
}
t.Logf("Issue delete: success")
}
func testIssueAllGet(t *testing.T, r Context, id int64) {
i, s, err := r.IssuesAllGet(IssueAllGetRequest{
Includes: []IssueInclude{
IssueIncludeRelations,
IssueIncludeAttachments,
},
Filters: IssueGetRequestFiltersInit().
FieldAdd("issue_id", strconv.FormatInt(id, 10)).
FieldAdd("subject", testIssueSubject2).
FieldAdd("description", testIssueDescription2),
})
if err != nil {
t.Fatal("Issues all get error:", err, s)
}
if len(i.Issues) == 0 {
t.Fatal("Issues all get error: can't find any issues satisfies specified filters")
}
t.Logf("Issues all get: success")
}
func testIssueMultiGet(t *testing.T, r Context, id int64) {
i, s, err := r.IssuesMultiGet(IssueMultiGetRequest{
Includes: []IssueInclude{
IssueIncludeRelations,
IssueIncludeAttachments,
},
Filters: IssueGetRequestFiltersInit().
FieldAdd("issue_id", strconv.FormatInt(id, 10)).
FieldAdd("subject", testIssueSubject2).
FieldAdd("description", testIssueDescription2),
Limit: 100,
Offset: 0,
})
if err != nil {
t.Fatal("Issues multi get error:", err, s)
}
if len(i.Issues) == 0 {
t.Fatal("Issues multi get error: can't find any issues satisfies specified filters")
}
t.Logf("Issues multi get: success")
}
func testIssueSingleGet(t *testing.T, r Context, id, userID int64) {
i, s, err := r.IssueSingleGet(id, IssueSingleGetRequest{
Includes: []IssueInclude{
IssueIncludeChildren,
IssueIncludeAttachments,
IssueIncludeRelations,
IssueIncludeChangesets,
IssueIncludeJournals,
IssueIncludeWatchers,
IssueIncludeAllowedStatuses,
},
},
)
if err != nil {
t.Fatal("Issue get error:", err, s)
}
if i.Subject != testIssueSubject {
t.Fatal("Issue get error: incorrect subject")
}
if i.Description != testIssueDescription {
t.Fatal("Issue get error: incorrect description")
}
if i.Watchers == nil || len(*i.Watchers) != 1 {
t.Fatal("Issue get error: incorrect watchers count")
}
ws := *i.Watchers
if ws[0].ID != userID {
t.Fatal("Issue get error: incorrect issue watchers")
}
t.Logf("Issue get: success")
}
func testIssueWatcherAdd(t *testing.T, r Context, id int64, userID int64) {
s, err := r.IssueWatcherAdd(id, userID)
if err != nil {
t.Fatal("Issue add watcher error:", err, s)
}
t.Logf("Issue add watcher: success")
}
func testIssueWatcherDelete(t *testing.T, r Context, id int64, userID int64) {
s, err := r.IssueWatcherDelete(id, userID)
if err != nil {
t.Fatal("Issue delete watcher error:", err, s)
}
t.Logf("Issue delete watcher: success")
}