2017-02-04 18:07:26 +05:30
|
|
|
// Copyright 2017 The Gogs Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2017-02-04 18:07:26 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_newIssueUsers(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
2017-02-04 18:07:26 +05:30
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
2017-02-04 18:07:26 +05:30
|
|
|
newIssue := &Issue{
|
|
|
|
RepoID: repo.ID,
|
|
|
|
PosterID: 4,
|
2020-01-17 11:33:40 +05:30
|
|
|
Index: 6,
|
2017-02-04 18:07:26 +05:30
|
|
|
Title: "newTestIssueTitle",
|
|
|
|
Content: "newTestIssueContent",
|
|
|
|
}
|
|
|
|
|
|
|
|
// artificially insert new issue
|
2021-09-19 17:19:59 +05:30
|
|
|
db.AssertSuccessfulInsert(t, newIssue)
|
2017-02-04 18:07:26 +05:30
|
|
|
|
2021-09-23 21:15:36 +05:30
|
|
|
assert.NoError(t, newIssueUsers(db.GetEngine(db.DefaultContext), repo, newIssue))
|
2017-02-04 18:07:26 +05:30
|
|
|
|
|
|
|
// issue_user table should now have entries for new issue
|
2021-09-19 17:19:59 +05:30
|
|
|
db.AssertExistsAndLoadBean(t, &IssueUser{IssueID: newIssue.ID, UID: newIssue.PosterID})
|
|
|
|
db.AssertExistsAndLoadBean(t, &IssueUser{IssueID: newIssue.ID, UID: repo.OwnerID})
|
2017-02-04 18:07:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateIssueUserByRead(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
2017-02-04 18:07:26 +05:30
|
|
|
|
|
|
|
assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
|
2021-09-19 17:19:59 +05:30
|
|
|
db.AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
|
2017-02-04 18:07:26 +05:30
|
|
|
|
|
|
|
assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
|
2021-09-19 17:19:59 +05:30
|
|
|
db.AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
|
2017-02-04 18:07:26 +05:30
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, UpdateIssueUserByRead(db.NonexistentID, db.NonexistentID))
|
2017-02-04 18:07:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateIssueUsersByMentions(t *testing.T) {
|
2021-09-19 17:19:59 +05:30
|
|
|
assert.NoError(t, db.PrepareTestDatabase())
|
|
|
|
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
2017-02-04 18:07:26 +05:30
|
|
|
|
|
|
|
uids := []int64{2, 5}
|
2021-09-23 21:15:36 +05:30
|
|
|
assert.NoError(t, UpdateIssueUsersByMentions(db.DefaultContext, issue.ID, uids))
|
2017-02-04 18:07:26 +05:30
|
|
|
for _, uid := range uids {
|
2021-09-19 17:19:59 +05:30
|
|
|
db.AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: uid}, "is_mentioned=1")
|
2017-02-04 18:07:26 +05:30
|
|
|
}
|
|
|
|
}
|