68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package adapter
|
|
|
|
import "testing"
|
|
|
|
func TestRoleValid(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
valid := []Role{RoleOwner, RoleMember, RoleSystem, RoleUnknown}
|
|
for _, r := range valid {
|
|
if !r.Valid() {
|
|
t.Errorf("Role(%q).Valid() = false, want true", r)
|
|
}
|
|
}
|
|
if Role("").Valid() {
|
|
t.Error("empty Role.Valid() = true, want false")
|
|
}
|
|
if Role("admin").Valid() {
|
|
t.Error("bogus Role.Valid() = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestActorOwnerDetection(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
actor Actor
|
|
wantOwner bool
|
|
wantGroup bool
|
|
wantSys bool
|
|
}{
|
|
{name: "owner private", actor: Actor{Role: RoleOwner, UserID: "u-1"}, wantOwner: true},
|
|
{name: "member group", actor: Actor{Role: RoleMember, IsGroup: true, GroupID: "g-1"}, wantGroup: true},
|
|
{name: "system", actor: Actor{Role: RoleSystem}, wantSys: true},
|
|
{name: "unknown", actor: Actor{Role: RoleUnknown}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
if got := tt.actor.IsOwner(); got != tt.wantOwner {
|
|
t.Errorf("IsOwner() = %v, want %v", got, tt.wantOwner)
|
|
}
|
|
if got := tt.actor.IsGroupChat(); got != tt.wantGroup {
|
|
t.Errorf("IsGroupChat() = %v, want %v", got, tt.wantGroup)
|
|
}
|
|
if got := tt.actor.IsSystem(); got != tt.wantSys {
|
|
t.Errorf("IsSystem() = %v, want %v", got, tt.wantSys)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestActorResolveInfersGroup(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
actor := Actor{Role: RoleMember, UserID: "u-1", GroupID: "g-1", GroupName: "Team"}
|
|
resolved := actor.Resolve()
|
|
|
|
if !resolved.IsGroup || !resolved.IsGroupChat() {
|
|
t.Errorf("Resolve() = %+v, want IsGroup true", resolved)
|
|
}
|
|
if resolved.GroupID != "g-1" || resolved.GroupName != "Team" {
|
|
t.Errorf("Resolve() = %+v, want group identity preserved", resolved)
|
|
}
|
|
}
|