Add tests for team_rights
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
45c3148794
commit
e91c7fc1af
|
@ -0,0 +1,110 @@
|
|||
// Vikunja is a todo-list application to facilitate your life.
|
||||
// Copyright 2018 Vikunja and contributors. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License 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 General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.vikunja.io/web"
|
||||
)
|
||||
|
||||
func TestTeam_CanDoSomething(t *testing.T) {
|
||||
type fields struct {
|
||||
ID int64
|
||||
Name string
|
||||
Description string
|
||||
CreatedByID int64
|
||||
CreatedBy User
|
||||
Members []*TeamUser
|
||||
Created int64
|
||||
Updated int64
|
||||
CRUDable web.CRUDable
|
||||
Rights web.Rights
|
||||
}
|
||||
type args struct {
|
||||
a web.Auth
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want map[string]bool
|
||||
}{
|
||||
{
|
||||
name: "CanDoSomething Normally",
|
||||
fields: fields{
|
||||
ID: 1,
|
||||
},
|
||||
args: args{
|
||||
a: &User{ID: 1},
|
||||
},
|
||||
want: map[string]bool{"CanCreate": true, "IsAdmin": true, "CanRead": true, "CanDelete": true, "CanUpdate": true},
|
||||
},
|
||||
{
|
||||
name: "CanDoSomething for a nonexistant namespace",
|
||||
fields: fields{
|
||||
ID: 300,
|
||||
},
|
||||
args: args{
|
||||
a: &User{ID: 1},
|
||||
},
|
||||
want: map[string]bool{"CanCreate": true, "IsAdmin": false, "CanRead": false, "CanDelete": false, "CanUpdate": false},
|
||||
},
|
||||
{
|
||||
name: "CanDoSomething where the user does not have the rights",
|
||||
fields: fields{
|
||||
ID: 1,
|
||||
},
|
||||
args: args{
|
||||
a: &User{ID: 4},
|
||||
},
|
||||
want: map[string]bool{"CanCreate": true, "IsAdmin": false, "CanRead": false, "CanDelete": false, "CanUpdate": false},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tm := &Team{
|
||||
ID: tt.fields.ID,
|
||||
Name: tt.fields.Name,
|
||||
Description: tt.fields.Description,
|
||||
CreatedByID: tt.fields.CreatedByID,
|
||||
CreatedBy: tt.fields.CreatedBy,
|
||||
Members: tt.fields.Members,
|
||||
Created: tt.fields.Created,
|
||||
Updated: tt.fields.Updated,
|
||||
CRUDable: tt.fields.CRUDable,
|
||||
Rights: tt.fields.Rights,
|
||||
}
|
||||
|
||||
if got := tm.CanCreate(tt.args.a); got != tt.want["CanCreate"] { // CanCreate is currently always true
|
||||
t.Errorf("Team.CanCreate() = %v, want %v", got, tt.want["CanCreate"])
|
||||
}
|
||||
if got := tm.CanDelete(tt.args.a); got != tt.want["CanDelete"] {
|
||||
t.Errorf("Team.CanDelete() = %v, want %v", got, tt.want["CanDelete"])
|
||||
}
|
||||
if got := tm.CanUpdate(tt.args.a); got != tt.want["CanUpdate"] {
|
||||
t.Errorf("Team.CanUpdate() = %v, want %v", got, tt.want["CanUpdate"])
|
||||
}
|
||||
if got := tm.CanRead(tt.args.a); got != tt.want["CanRead"] {
|
||||
t.Errorf("Team.CanRead() = %v, want %v", got, tt.want["CanRead"])
|
||||
}
|
||||
if got := tm.IsAdmin(tt.args.a); got != tt.want["IsAdmin"] {
|
||||
t.Errorf("Team.IsAdmin() = %v, want %v", got, tt.want["IsAdmin"])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue