8d1a09b5a2
Fix lint Fix lint Fix loading tasks with search Fix loading lists Fix loading task Fix loading lists and namespaces Fix tests Fix user commands Fix upload Fix migration handlers Fix all manual root handlers Fix session in avatar Fix session in list duplication & routes Use sessions in migration code Make sure the openid stuff uses a session Add alias for db type in db package Use sessions for file Use a session for everything in users Use a session for everything in users Make sure to use a session everywhere in models Create new session from db Add session handling for user list Add session handling for unsplash Add session handling for teams and related Add session handling for tasks and related entities Add session handling for task reminders Add session handling for task relations Add session handling for task comments Add session handling for task collections Add session handling for task attachments Add session handling for task assignees Add session handling for saved filters Add session handling for namespace and related types Add session handling for namespace and related types Add session handling for list users Add session handling for list tests Add session handling to list teams and related entities Add session handling for link shares and related entities Add session handling for labels and related entities Add session handling for kanban and related entities Add session handling for bulk task and related entities Add session handling for lists and related entities Add session configuration for web handler Update web handler Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/750 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
78 lines
1.5 KiB
Go
78 lines
1.5 KiB
Go
package models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.vikunja.io/api/pkg/db"
|
|
"code.vikunja.io/api/pkg/user"
|
|
)
|
|
|
|
func TestBulkTask_Update(t *testing.T) {
|
|
type fields struct {
|
|
IDs []int64
|
|
Tasks []*Task
|
|
Task Task
|
|
User *user.User
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
wantErr bool
|
|
wantForbidden bool
|
|
}{
|
|
{
|
|
name: "Test normal update",
|
|
fields: fields{
|
|
IDs: []int64{10, 11, 12},
|
|
Task: Task{
|
|
Title: "bulkupdated",
|
|
},
|
|
User: &user.User{ID: 1},
|
|
},
|
|
},
|
|
{
|
|
name: "Test with one task on different list",
|
|
fields: fields{
|
|
IDs: []int64{10, 11, 12, 13},
|
|
Task: Task{
|
|
Title: "bulkupdated",
|
|
},
|
|
User: &user.User{ID: 1},
|
|
},
|
|
wantForbidden: true,
|
|
},
|
|
{
|
|
name: "Test without any tasks",
|
|
fields: fields{
|
|
IDs: []int64{},
|
|
Task: Task{
|
|
Title: "bulkupdated",
|
|
},
|
|
User: &user.User{ID: 1},
|
|
},
|
|
wantForbidden: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
db.LoadAndAssertFixtures(t)
|
|
|
|
s := db.NewSession()
|
|
|
|
bt := &BulkTask{
|
|
IDs: tt.fields.IDs,
|
|
Tasks: tt.fields.Tasks,
|
|
Task: tt.fields.Task,
|
|
}
|
|
allowed, _ := bt.CanUpdate(s, tt.fields.User)
|
|
if !allowed != tt.wantForbidden {
|
|
t.Errorf("BulkTask.Update() want forbidden, got %v, want %v", allowed, tt.wantForbidden)
|
|
}
|
|
if err := bt.Update(s); (err != nil) != tt.wantErr {
|
|
t.Errorf("BulkTask.Update() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
|
|
s.Close()
|
|
})
|
|
}
|
|
}
|