2020-12-29 02:04:20 +01:00
|
|
|
// Vikunja is a to-do list application to facilitate your life.
|
2021-02-02 20:19:13 +01:00
|
|
|
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
2020-12-29 02:04:20 +01:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public Licensee for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public Licensee
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2018-12-28 22:49:46 +01:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
2020-10-11 22:10:03 +02:00
|
|
|
"testing"
|
|
|
|
|
2020-01-26 18:08:06 +01:00
|
|
|
"code.vikunja.io/api/pkg/db"
|
|
|
|
"code.vikunja.io/api/pkg/user"
|
2018-12-28 22:49:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBulkTask_Update(t *testing.T) {
|
|
|
|
type fields struct {
|
2019-08-14 22:19:04 +02:00
|
|
|
IDs []int64
|
|
|
|
Tasks []*Task
|
|
|
|
Task Task
|
2020-01-26 18:08:06 +01:00
|
|
|
User *user.User
|
2018-12-28 22:49:46 +01:00
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
wantErr bool
|
|
|
|
wantForbidden bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Test normal update",
|
|
|
|
fields: fields{
|
|
|
|
IDs: []int64{10, 11, 12},
|
2019-08-14 22:19:04 +02:00
|
|
|
Task: Task{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "bulkupdated",
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
2020-01-26 18:08:06 +01:00
|
|
|
User: &user.User{ID: 1},
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test with one task on different list",
|
|
|
|
fields: fields{
|
|
|
|
IDs: []int64{10, 11, 12, 13},
|
2019-08-14 22:19:04 +02:00
|
|
|
Task: Task{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "bulkupdated",
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
2020-01-26 18:08:06 +01:00
|
|
|
User: &user.User{ID: 1},
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
|
|
|
wantForbidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Test without any tasks",
|
|
|
|
fields: fields{
|
|
|
|
IDs: []int64{},
|
2019-08-14 22:19:04 +02:00
|
|
|
Task: Task{
|
2020-05-16 12:17:44 +02:00
|
|
|
Title: "bulkupdated",
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
2020-01-26 18:08:06 +01:00
|
|
|
User: &user.User{ID: 1},
|
2018-12-28 22:49:46 +01:00
|
|
|
},
|
|
|
|
wantForbidden: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2020-01-26 18:08:06 +01:00
|
|
|
db.LoadAndAssertFixtures(t)
|
|
|
|
|
2020-12-23 16:32:28 +01:00
|
|
|
s := db.NewSession()
|
|
|
|
|
2018-12-28 22:49:46 +01:00
|
|
|
bt := &BulkTask{
|
2019-08-14 22:19:04 +02:00
|
|
|
IDs: tt.fields.IDs,
|
|
|
|
Tasks: tt.fields.Tasks,
|
|
|
|
Task: tt.fields.Task,
|
2018-12-28 22:49:46 +01:00
|
|
|
}
|
2020-12-23 16:32:28 +01:00
|
|
|
allowed, _ := bt.CanUpdate(s, tt.fields.User)
|
2018-12-28 22:49:46 +01:00
|
|
|
if !allowed != tt.wantForbidden {
|
|
|
|
t.Errorf("BulkTask.Update() want forbidden, got %v, want %v", allowed, tt.wantForbidden)
|
|
|
|
}
|
2021-02-02 23:48:37 +01:00
|
|
|
if err := bt.Update(s, tt.fields.User); (err != nil) != tt.wantErr {
|
2018-12-28 22:49:46 +01:00
|
|
|
t.Errorf("BulkTask.Update() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
2020-12-23 16:32:28 +01:00
|
|
|
|
|
|
|
s.Close()
|
2018-12-28 22:49:46 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|