forked from gitea/gitea
1
0
Fork 0

corect tests + GetIssueWatch

This commit is contained in:
6543 2019-11-01 06:20:49 +01:00
parent 9f3b25c358
commit aa31558a75
No known key found for this signature in database
GPG Key ID: A1CA74D27FD13271
3 changed files with 10 additions and 9 deletions

View File

@ -17,7 +17,7 @@
- -
id: 3 id: 3
user_id: 2 user_id: 2
issue_id: 3 issue_id: 7
is_watching: true is_watching: true
created_unix: 946684800 created_unix: 946684800
updated_unix: 946684800 updated_unix: 946684800
@ -25,7 +25,7 @@
- -
id: 3 id: 3
user_id: 1 user_id: 1
issue_id: 3 issue_id: 7
is_watching: false is_watching: false
created_unix: 946684800 created_unix: 946684800
updated_unix: 946684800 updated_unix: 946684800

View File

@ -53,6 +53,7 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool
exists, err = e. exists, err = e.
Where("user_id = ?", userID). Where("user_id = ?", userID).
And("issue_id = ?", issueID). And("issue_id = ?", issueID).
And("is_watching = ?", true).
Get(iw) Get(iw)
return return
} }
@ -66,7 +67,7 @@ func getIssueWatchers(e Engine, issueID int64) (watches []*IssueWatch, err error
// handle manual watchers // handle manual watchers
err = e. err = e.
Where("`issue_watch`.issue_id = ?", issueID). Where("`issue_watch`.issue_id = ?", issueID).
And("`issue_watch`.is_watching > ?", 0). And("`issue_watch`.is_watching = ?", true).
And("`user`.is_active = ?", true). And("`user`.is_active = ?", true).
And("`user`.prohibit_login = ?", false). And("`user`.prohibit_login = ?", false).
Join("INNER", "`user`", "`user`.id = `issue_watch`.user_id"). Join("INNER", "`user`", "`user`.id = `issue_watch`.user_id").

View File

@ -30,7 +30,7 @@ func TestGetIssueWatch(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
_, exists, err = GetIssueWatch(2, 2) _, exists, err = GetIssueWatch(2, 2)
assert.Equal(t, true, exists) assert.Equal(t, false, exists)
assert.NoError(t, err) assert.NoError(t, err)
_, exists, err = GetIssueWatch(3, 1) _, exists, err = GetIssueWatch(3, 1)
@ -51,12 +51,12 @@ func TestGetIssueWatchers(t *testing.T) {
// Watcher is not watching // Watcher is not watching
assert.Equal(t, 0, len(iws)) assert.Equal(t, 0, len(iws))
iws, err = GetIssueWatchers(3)
assert.NoError(t, err)
// Watcher is not watching
assert.Equal(t, 1, len(iws))
iws, err = GetIssueWatchers(5) iws, err = GetIssueWatchers(5)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 0, len(iws)) assert.Equal(t, 0, len(iws))
iws, err = GetIssueWatchers(7)
assert.NoError(t, err)
// Watcher is not watching
assert.Equal(t, 1, len(iws))
} }