package apitokens import "testing" func TestChatSessionGrantsMail(t *testing.T) { perms, _, _ := chatSessionGrants(ChatSessionInput{Preset: ChatSessionMail}) if len(perms) == 0 { t.Fatal("expected grants") } found := false for _, p := range perms { if p.Resource == "mail.messages" && p.Read { found = true } } if !found { t.Fatal("expected mail.messages read grant") } } func TestChatSessionGrantsDocs(t *testing.T) { perms, _, drive := chatSessionGrants(ChatSessionInput{ Preset: ChatSessionDocs, DrivePath: "/Docs/note.ultidoc", AllowWrite: true, }) foundRead := false foundWrite := false for _, p := range perms { if p.Resource == "drive.files" && p.Read { foundRead = true foundWrite = p.Write } } if !foundRead || !foundWrite { t.Fatalf("expected drive.files read+write: %+v", perms) } if drive.AllFolders || len(drive.FolderPaths) != 1 { t.Fatalf("unexpected drive scope: %+v", drive) } } func TestChatSessionGrantsDriveScoped(t *testing.T) { _, _, drive := chatSessionGrants(ChatSessionInput{ Preset: ChatSessionDrive, DrivePath: "/docs", }) if drive.AllFolders { t.Fatal("expected folder scope") } if len(drive.FolderPaths) != 1 || drive.FolderPaths[0] != "/docs" { t.Fatalf("unexpected drive scope: %+v", drive) } }