feat(channel): 跨平台 IM 接入抽象契约(UnifiedMessage/PlatformAdapter/Capabilities/Actor 身份)
This commit is contained in:
1 parent
a21176ec0a
commit
c52ddfd9c7
8 files changed
+767
No files matched your search
@@ -0,0 +1,67 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user