Files
archie/internal/gateway/session_visibility_test.go
T

35 lines
1.0 KiB
Go

package gateway
import (
"testing"
"github.com/samcharles93/archie-core/internal/domain/access"
"github.com/samcharles93/archie-core/internal/domain/messaging"
)
func TestSessionVisibility(t *testing.T) {
for _, tc := range []struct {
name string
service bool
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},
} {
t.Run(tc.name, func(t *testing.T) {
ctx := t.Context()
if !tc.service {
ctx = access.WithPrincipal(ctx, access.Principal{IdentityID: "alice"})
}
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)
}
})
}
}