Skip to content

Commit 5bf5f38

Browse files
committed
tests, including an attachment (gitea.png) in an issue
1 parent b2db1a7 commit 5bf5f38

File tree

17 files changed

+201
-39
lines changed

17 files changed

+201
-39
lines changed

models/fixtures/attachment.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,16 @@
153153
download_count: 0
154154
size: 0
155155
created_unix: 946684800
156+
157+
-
158+
id: 13
159+
uuid: 1b267670-1793-4cd0-abc1-449269b7cff9
160+
repo_id: 1
161+
issue_id: 23
162+
release_id: 0
163+
uploader_id: 0
164+
comment_id: 2
165+
name: gitea.png
166+
download_count: 0
167+
size: 1458
168+
created_unix: 946684800

models/fixtures/issue.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,20 @@
372372
created_unix: 1707270422
373373
updated_unix: 1707270422
374374
is_locked: false
375+
376+
-
377+
id: 23
378+
repo_id: 1
379+
index: 6
380+
poster_id: 1
381+
original_author_id: 0
382+
name: issue23
383+
content: 'content including this image: <image alt="gitea.png" src="attachments/1b267670-1793-4cd0-abc1-449269b7cff9" /> with some more content behind it'
384+
milestone_id: 0
385+
priority: 0
386+
is_closed: false
387+
is_pull: false
388+
num_comments: 0
389+
created_unix: 946684801
390+
updated_unix: 978307201
391+
is_locked: false

models/fixtures/issue_index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-
22
group_id: 1
3-
max_index: 5
3+
max_index: 6
44

55
-
66
group_id: 2

models/fixtures/repository.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
num_watches: 4
1010
num_stars: 0
1111
num_forks: 0
12-
num_issues: 2
12+
num_issues: 3
1313
num_closed_issues: 1
1414
num_pulls: 3
1515
num_closed_pulls: 0

models/issues/issue_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func Test_GetIssueIDsByRepoID(t *testing.T) {
5757

5858
ids, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
5959
assert.NoError(t, err)
60-
assert.Len(t, ids, 5)
60+
assert.Len(t, ids, 6)
6161
}
6262

6363
func TestIssueAPIURL(t *testing.T) {
@@ -170,7 +170,7 @@ func TestIssues(t *testing.T) {
170170
PageSize: 4,
171171
},
172172
},
173-
[]int64{1, 2, 3, 5},
173+
[]int64{1, 23, 2, 3},
174174
},
175175
{
176176
issues_model.IssuesOptions{
@@ -249,11 +249,11 @@ func TestIssue_InsertIssue(t *testing.T) {
249249
assert.NoError(t, unittest.PrepareTestDatabase())
250250

251251
// there are 5 issues and max index is 5 on repository 1, so this one should 6
252-
issue := testInsertIssue(t, "my issue1", "special issue's comments?", 6)
252+
issue := testInsertIssue(t, "my issue1", "special issue's comments?", 7)
253253
_, err := db.DeleteByID[issues_model.Issue](db.DefaultContext, issue.ID)
254254
assert.NoError(t, err)
255255

256-
issue = testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?", 7)
256+
issue = testInsertIssue(t, `my issue2, this is my son's love \n \r \ `, "special issue's '' comments?", 8)
257257
_, err = db.DeleteByID[issues_model.Issue](db.DefaultContext, issue.ID)
258258
assert.NoError(t, err)
259259
}
@@ -380,7 +380,7 @@ func TestCountIssues(t *testing.T) {
380380
assert.NoError(t, unittest.PrepareTestDatabase())
381381
count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{})
382382
assert.NoError(t, err)
383-
assert.EqualValues(t, 22, count)
383+
assert.EqualValues(t, 23, count)
384384
}
385385

386386
func TestIssueLoadAttributes(t *testing.T) {

models/issues/issue_user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func Test_NewIssueUsers(t *testing.T) {
2222
newIssue := &issues_model.Issue{
2323
RepoID: repo.ID,
2424
PosterID: 4,
25-
Index: 6,
25+
Index: 7,
2626
Title: "newTestIssueTitle",
2727
Content: "newTestIssueContent",
2828
}

models/repo/attachment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestDeleteAttachments(t *testing.T) {
5151

5252
count, err = repo_model.DeleteAttachmentsByComment(db.DefaultContext, 2, false)
5353
assert.NoError(t, err)
54-
assert.Equal(t, 2, count)
54+
assert.Equal(t, 3, count)
5555

5656
err = repo_model.DeleteAttachment(db.DefaultContext, &repo_model.Attachment{ID: 8}, false)
5757
assert.NoError(t, err)

modules/indexer/issues/indexer_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func searchIssueWithKeyword(t *testing.T) {
5757
Keyword: "issue2",
5858
RepoIDs: []int64{1},
5959
},
60-
[]int64{2},
60+
[]int64{2, 23},
6161
},
6262
{
6363
SearchOptions{
@@ -106,7 +106,7 @@ func searchIssueByIndex(t *testing.T) {
106106
Keyword: "2",
107107
RepoIDs: []int64{1, 2, 3, 32},
108108
},
109-
[]int64{17, 12, 7, 2},
109+
[]int64{17, 12, 7, 2, 23},
110110
},
111111
{
112112
SearchOptions{
@@ -133,7 +133,7 @@ func searchIssueInRepo(t *testing.T) {
133133
SearchOptions{
134134
RepoIDs: []int64{1},
135135
},
136-
[]int64{11, 5, 3, 2, 1},
136+
[]int64{11, 5, 3, 2, 23, 1},
137137
},
138138
{
139139
SearchOptions{
@@ -177,7 +177,7 @@ func searchIssueByID(t *testing.T) {
177177
opts: SearchOptions{
178178
PosterID: optional.Some(int64(1)),
179179
},
180-
expectedIDs: []int64{11, 6, 3, 2, 1},
180+
expectedIDs: []int64{11, 6, 3, 2, 23, 1},
181181
},
182182
{
183183
opts: SearchOptions{
@@ -188,7 +188,7 @@ func searchIssueByID(t *testing.T) {
188188
{
189189
// NOTE: This tests no assignees filtering and also ToSearchOptions() to ensure it will set AssigneeID to 0 when it is passed as -1.
190190
opts: *ToSearchOptions("", &issues.IssuesOptions{AssigneeID: optional.Some(db.NoConditionID)}),
191-
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2},
191+
expectedIDs: []int64{22, 21, 16, 15, 14, 13, 12, 11, 20, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 23},
192192
},
193193
{
194194
opts: SearchOptions{
@@ -212,7 +212,7 @@ func searchIssueByID(t *testing.T) {
212212
opts: SearchOptions{
213213
SubscriberID: optional.Some(int64(1)),
214214
},
215-
expectedIDs: []int64{11, 6, 5, 3, 2, 1},
215+
expectedIDs: []int64{11, 6, 5, 3, 2, 23, 1},
216216
},
217217
{
218218
// issue 20 request user 15 and team 5 which user 15 belongs to
@@ -247,7 +247,7 @@ func searchIssueIsPull(t *testing.T) {
247247
SearchOptions{
248248
IsPull: optional.Some(false),
249249
},
250-
[]int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 1},
250+
[]int64{17, 16, 15, 14, 13, 6, 5, 18, 10, 7, 4, 23, 1},
251251
},
252252
{
253253
SearchOptions{
@@ -272,7 +272,7 @@ func searchIssueIsClosed(t *testing.T) {
272272
SearchOptions{
273273
IsClosed: optional.Some(false),
274274
},
275-
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1},
275+
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 23, 1},
276276
},
277277
{
278278
SearchOptions{
@@ -297,7 +297,7 @@ func searchIssueIsArchived(t *testing.T) {
297297
SearchOptions{
298298
IsArchived: optional.Some(false),
299299
},
300-
[]int64{22, 21, 17, 16, 15, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
300+
[]int64{22, 21, 17, 16, 15, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 23, 1},
301301
},
302302
{
303303
SearchOptions{
@@ -359,7 +359,7 @@ func searchIssueByLabelID(t *testing.T) {
359359
SearchOptions{
360360
ExcludedLabelIDs: []int64{1},
361361
},
362-
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3},
362+
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 23},
363363
},
364364
}
365365
for _, test := range tests {
@@ -378,7 +378,7 @@ func searchIssueByTime(t *testing.T) {
378378
SearchOptions{
379379
UpdatedAfterUnix: optional.Some(int64(0)),
380380
},
381-
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1},
381+
[]int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 23, 1},
382382
},
383383
}
384384
for _, test := range tests {
@@ -397,7 +397,7 @@ func searchIssueWithOrder(t *testing.T) {
397397
SearchOptions{
398398
SortBy: internal.SortByCreatedAsc,
399399
},
400-
[]int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22},
400+
[]int64{1, 23, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22},
401401
},
402402
}
403403
for _, test := range tests {
@@ -451,7 +451,7 @@ func searchIssueWithPaginator(t *testing.T) {
451451
},
452452
},
453453
[]int64{22, 21, 17, 16, 15},
454-
22,
454+
23,
455455
},
456456
}
457457
for _, test := range tests {

services/issue/issue_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestIssue_DeleteIssue(t *testing.T) {
3737

3838
issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
3939
assert.NoError(t, err)
40-
assert.Len(t, issueIDs, 5)
40+
assert.Len(t, issueIDs, 6)
4141

4242
issue := &issues_model.Issue{
4343
RepoID: 1,
@@ -48,7 +48,7 @@ func TestIssue_DeleteIssue(t *testing.T) {
4848
assert.NoError(t, err)
4949
issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
5050
assert.NoError(t, err)
51-
assert.Len(t, issueIDs, 4)
51+
assert.Len(t, issueIDs, 5)
5252

5353
// check attachment removal
5454
attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4)

services/issue/suggestion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ func Test_Suggestion(t *testing.T) {
2626
}{
2727
{
2828
keyword: "",
29-
expectedIndexes: []int64{5, 1, 4, 2, 3},
29+
expectedIndexes: []int64{5, 6, 1, 4, 2},
3030
},
3131
{
3232
keyword: "1",
3333
expectedIndexes: []int64{1},
3434
},
3535
{
3636
keyword: "issue",
37-
expectedIndexes: []int64{4, 1, 2, 3},
37+
expectedIndexes: []int64{6, 4, 1, 2, 3},
3838
},
3939
{
4040
keyword: "pull",

0 commit comments

Comments
 (0)