mirror of
https://github.com/4ier/notion-cli.git
synced 2026-09-14 20:17:00 +08:00
5ec113f07f
Wraps two endpoints added in Notion's 2025 API that the CLI didn't yet expose: - PATCH /v1/comments/:id → 'notion comment update <id> --text ...' - DELETE /v1/comments/:id → 'notion comment delete <id> [<id> ...]' 'update' reuses the existing buildCommentRichText helper so the --mention-user flag works the same way as 'comment add'. 'delete' follows the 'block delete' pattern: variadic args, per-id error isolation, and a summary line (N comment(s) deleted). When the target id is the anchor of a discussion, Notion removes the whole thread; deleting a reply removes just that one comment — this is documented in the Long help. Two new client methods (UpdateComment, DeleteComment) keep the API plumbing in internal/client alongside AddComment. Smoke-tested against a real workspace: create comment → update text → verify new text via 'comment get' → delete → raw DELETE on the same id returns object_not_found as expected (the synchronous GET path is eventually consistent server-side, which is a Notion behavior, not a CLI issue). Closes #33
38 lines
1004 B
Go
38 lines
1004 B
Go
package cmd
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestCommentUpdateCmd_RequiresTextOrMention(t *testing.T) {
|
|
if commentUpdateCmd.Short == "" {
|
|
t.Error("update short help missing")
|
|
}
|
|
// Sanity: the command is registered under the parent.
|
|
for _, expected := range []string{"update", "delete"} {
|
|
found := false
|
|
for _, sub := range commentCmd.Commands() {
|
|
if sub.Name() == expected {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Errorf("comment %s subcommand not registered", expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCommentDeleteCmd_AcceptsVariadic(t *testing.T) {
|
|
// Args validator should accept 1+ ids.
|
|
if err := commentDeleteCmd.Args(commentDeleteCmd, []string{"id1"}); err != nil {
|
|
t.Errorf("one id should be valid: %v", err)
|
|
}
|
|
if err := commentDeleteCmd.Args(commentDeleteCmd, []string{"id1", "id2", "id3"}); err != nil {
|
|
t.Errorf("multiple ids should be valid: %v", err)
|
|
}
|
|
if err := commentDeleteCmd.Args(commentDeleteCmd, []string{}); err == nil {
|
|
t.Errorf("zero ids should fail")
|
|
}
|
|
}
|