Files
archie/internal/gateway/session_visibility_test.go
T

42 lines
1.4 KiB
Go

package gateway
import (
"testing"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/messaging"
"github.com/samcharles93/archie-core/internal/domain/presence"
)
func TestSessionVisibility(t *testing.T) {
for _, tc := range []struct {
name string
service bool
caller string
platform, owner string
want bool
}{
{"own history", false, "", "web", "alice", true},
{"another user in the same org", false, "", "web", "bob", false},
{"anonymous history is not assigned to a person", false, "", "web", "", false},
{"other channel history", false, "", "telegram", "alice", false},
{"curator service", true, "", "web", "bob", true},
{"messaging acting for an org agent sees channel history", false, presence.Messaging, "telegram", "alice", true},
{"messaging acting for an org agent never sees web history", false, presence.Messaging, "web", "bob", false},
} {
t.Run(tc.name, func(t *testing.T) {
ctx := t.Context()
if !tc.service {
ctx = access.WithPrincipal(ctx, access.Principal{IdentityID: "alice"})
}
if tc.caller != "" {
ctx = access.WithSource(ctx, tc.caller)
}
session := SessionContext{Source: messaging.SessionSource{Platform: tc.platform, ThreadID: tc.owner}}
if got := sessionVisible(ctx, session); got != tc.want {
t.Fatalf("visible=%v want=%v", got, tc.want)
}
})
}
}