Testing improvements (#666)
Change method names to avoid doubling db Assert team test exists Assert team member test exists Assert task test exists Assert task relation test exists Assert task comment test exists Better tests for team namespaces Assert exists in namespace users tests Assert exists in namespace tests Assert exists in user list tests Assert exists in list tests Better team list tests Assert label tests exist in db Assert label task tests exist in db Assert label task tests exist in db Assert kanban tests exist in db Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/666 Co-Authored-By: konrad <konrad@kola-entertainments.de> Co-Committed-By: konrad <konrad@kola-entertainments.de>
This commit is contained in:
@ -31,6 +31,7 @@ func TestNamespaceUser_Create(t *testing.T) {
|
||||
type fields struct {
|
||||
ID int64
|
||||
Username string
|
||||
UserID int64
|
||||
NamespaceID int64
|
||||
Right Right
|
||||
Created time.Time
|
||||
@ -52,6 +53,7 @@ func TestNamespaceUser_Create(t *testing.T) {
|
||||
name: "NamespaceUsers Create normally",
|
||||
fields: fields{
|
||||
Username: "user1",
|
||||
UserID: 1,
|
||||
NamespaceID: 2,
|
||||
},
|
||||
},
|
||||
@ -123,6 +125,12 @@ func TestNamespaceUser_Create(t *testing.T) {
|
||||
if (err != nil) && tt.wantErr && !tt.errType(err) {
|
||||
t.Errorf("NamespaceUser.Create() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
||||
}
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "users_namespace", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"namespace_id": tt.fields.NamespaceID,
|
||||
}, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -228,6 +236,7 @@ func TestNamespaceUser_Update(t *testing.T) {
|
||||
type fields struct {
|
||||
ID int64
|
||||
Username string
|
||||
UserID int64
|
||||
NamespaceID int64
|
||||
Right Right
|
||||
Created time.Time
|
||||
@ -246,6 +255,7 @@ func TestNamespaceUser_Update(t *testing.T) {
|
||||
fields: fields{
|
||||
NamespaceID: 3,
|
||||
Username: "user1",
|
||||
UserID: 1,
|
||||
Right: RightAdmin,
|
||||
},
|
||||
},
|
||||
@ -254,6 +264,7 @@ func TestNamespaceUser_Update(t *testing.T) {
|
||||
fields: fields{
|
||||
NamespaceID: 3,
|
||||
Username: "user1",
|
||||
UserID: 1,
|
||||
Right: RightWrite,
|
||||
},
|
||||
},
|
||||
@ -262,6 +273,7 @@ func TestNamespaceUser_Update(t *testing.T) {
|
||||
fields: fields{
|
||||
NamespaceID: 3,
|
||||
Username: "user1",
|
||||
UserID: 1,
|
||||
Right: RightRead,
|
||||
},
|
||||
},
|
||||
@ -297,6 +309,13 @@ func TestNamespaceUser_Update(t *testing.T) {
|
||||
if (err != nil) && tt.wantErr && !tt.errType(err) {
|
||||
t.Errorf("NamespaceUser.Update() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
||||
}
|
||||
if !tt.wantErr {
|
||||
db.AssertExists(t, "users_namespace", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"namespace_id": tt.fields.NamespaceID,
|
||||
"right": tt.fields.Right,
|
||||
}, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -305,6 +324,7 @@ func TestNamespaceUser_Delete(t *testing.T) {
|
||||
type fields struct {
|
||||
ID int64
|
||||
Username string
|
||||
UserID int64
|
||||
NamespaceID int64
|
||||
Right Right
|
||||
Created time.Time
|
||||
@ -340,6 +360,7 @@ func TestNamespaceUser_Delete(t *testing.T) {
|
||||
name: "Try deleting normally",
|
||||
fields: fields{
|
||||
Username: "user1",
|
||||
UserID: 1,
|
||||
NamespaceID: 3,
|
||||
},
|
||||
},
|
||||
@ -365,6 +386,12 @@ func TestNamespaceUser_Delete(t *testing.T) {
|
||||
if (err != nil) && tt.wantErr && !tt.errType(err) {
|
||||
t.Errorf("NamespaceUser.Delete() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name())
|
||||
}
|
||||
if !tt.wantErr {
|
||||
db.AssertMissing(t, "users_namespace", map[string]interface{}{
|
||||
"user_id": tt.fields.UserID,
|
||||
"namespace_id": tt.fields.NamespaceID,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user