2017-02-04 07:37:26 -05:00
|
|
|
// 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 07:49:59 -04:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 09:36:47 -05:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2021-11-17 07:34:35 -05:00
|
|
|
|
2017-02-04 07:37:26 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_newIssueUsers(t *testing.T) {
|
2021-11-12 09:36:47 -05:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-02-04 07:37:26 -05:00
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2017-02-04 07:37:26 -05:00
|
|
|
newIssue := &Issue{
|
|
|
|
RepoID: repo.ID,
|
|
|
|
PosterID: 4,
|
2020-01-17 01:03:40 -05:00
|
|
|
Index: 6,
|
2017-02-04 07:37:26 -05:00
|
|
|
Title: "newTestIssueTitle",
|
|
|
|
Content: "newTestIssueContent",
|
|
|
|
}
|
|
|
|
|
|
|
|
// artificially insert new issue
|
2021-11-16 03:53:21 -05:00
|
|
|
unittest.AssertSuccessfulInsert(t, newIssue)
|
2017-02-04 07:37:26 -05:00
|
|
|
|
2021-12-09 20:27:50 -05:00
|
|
|
assert.NoError(t, newIssueUsers(db.DefaultContext, repo, newIssue))
|
2017-02-04 07:37:26 -05:00
|
|
|
|
|
|
|
// issue_user table should now have entries for new issue
|
2021-11-16 03:53:21 -05:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &IssueUser{IssueID: newIssue.ID, UID: newIssue.PosterID})
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &IssueUser{IssueID: newIssue.ID, UID: repo.OwnerID})
|
2017-02-04 07:37:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateIssueUserByRead(t *testing.T) {
|
2021-11-12 09:36:47 -05:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 03:53:21 -05:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
2017-02-04 07:37:26 -05:00
|
|
|
|
|
|
|
assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
|
2021-11-16 03:53:21 -05:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
|
2017-02-04 07:37:26 -05:00
|
|
|
|
|
|
|
assert.NoError(t, UpdateIssueUserByRead(4, issue.ID))
|
2021-11-16 03:53:21 -05:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: 4}, "is_read=1")
|
2017-02-04 07:37:26 -05:00
|
|
|
|
2021-11-16 03:53:21 -05:00
|
|
|
assert.NoError(t, UpdateIssueUserByRead(unittest.NonexistentID, unittest.NonexistentID))
|
2017-02-04 07:37:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdateIssueUsersByMentions(t *testing.T) {
|
2021-11-12 09:36:47 -05:00
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2021-11-16 03:53:21 -05:00
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
2017-02-04 07:37:26 -05:00
|
|
|
|
|
|
|
uids := []int64{2, 5}
|
2021-09-23 11:45:36 -04:00
|
|
|
assert.NoError(t, UpdateIssueUsersByMentions(db.DefaultContext, issue.ID, uids))
|
2017-02-04 07:37:26 -05:00
|
|
|
for _, uid := range uids {
|
2021-11-16 03:53:21 -05:00
|
|
|
unittest.AssertExistsAndLoadBean(t, &IssueUser{IssueID: issue.ID, UID: uid}, "is_mentioned=1")
|
2017-02-04 07:37:26 -05:00
|
|
|
}
|
|
|
|
}
|