vikunja-api/pkg/models/bulk_task_test.go
konrad 699d3d6060 Add Golangci Lint (#676)
Increase golangci timeout

Fix installing golangci-lint in ci

Remove mage targets replaced by golangci

Run golint in ci

Add goheader linter

Enable & fix more linters

Fix lint issues

Add mage target to automagically fix issues found by golangci

golangci-lint run --fix

Add golangci config

Add golangci mage target

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/676
Co-Authored-By: konrad <konrad@kola-entertainments.de>
Co-Committed-By: konrad <konrad@kola-entertainments.de>
2020-10-11 20:10:03 +00:00

74 lines
1.4 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)
bt := &BulkTask{
IDs: tt.fields.IDs,
Tasks: tt.fields.Tasks,
Task: tt.fields.Task,
}
allowed, _ := bt.CanUpdate(tt.fields.User)
if !allowed != tt.wantForbidden {
t.Errorf("BulkTask.Update() want forbidden, got %v, want %v", allowed, tt.wantForbidden)
}
if err := bt.Update(); (err != nil) != tt.wantErr {
t.Errorf("BulkTask.Update() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}