1
0

Task mentions (#926)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/926
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad
2021-07-29 15:42:49 +00:00
parent e600f61e06
commit 1571dfa825
18 changed files with 619 additions and 15 deletions

View File

@ -19,6 +19,8 @@ package models
import (
"testing"
"code.vikunja.io/api/pkg/events"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
@ -41,6 +43,7 @@ func TestTaskComment_Create(t *testing.T) {
assert.Equal(t, int64(1), tc.Author.ID)
err = s.Commit()
assert.NoError(t, err)
events.AssertDispatched(t, &TaskCommentCreatedEvent{})
db.AssertExists(t, "task_comments", map[string]interface{}{
"id": tc.ID,
@ -62,6 +65,32 @@ func TestTaskComment_Create(t *testing.T) {
assert.Error(t, err)
assert.True(t, IsErrTaskDoesNotExist(err))
})
t.Run("should send notifications for comment mentions", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
task, err := GetTaskByIDSimple(s, 32)
assert.NoError(t, err)
tc := &TaskComment{
Comment: "Lorem Ipsum @user2",
TaskID: 32, // user2 has access to the list that task belongs to
}
err = tc.Create(s, u)
assert.NoError(t, err)
ev := &TaskCommentCreatedEvent{
Task: &task,
Doer: u,
Comment: tc,
}
events.TestListener(t, ev, &SendTaskCommentNotification{})
db.AssertExists(t, "notifications", map[string]interface{}{
"subject_id": tc.ID,
"notifiable_id": 2,
"name": (&TaskCommentNotification{}).Name(),
}, false)
})
}
func TestTaskComment_Delete(t *testing.T) {