Files
傅洋 5d37c1b145 fix(api): polish path, body, and help for the escape-hatch command (#27)
- Auto-prefix /v1 when a path starts with / but not /v1/, with a stderr
  note so power users see the rewrite. Previously `notion api GET /users/me`
  returned an opaque 'invalid_request_url' error.
- Support `--body @file.json` (curl-style) and `--body -` for explicit
  stdin reads. The existing implicit stdin fallback for POST/PATCH/PUT
  still works.
- Reject GET requests with a body up-front instead of silently dropping it.
- Route PATCH through c.Patch() unconditionally (previously it hit c.Post
  first and was overwritten, which made error paths confusing).
- Drop the misleading positional-arg example from --help; the flag was
  the only supported form.

Closes #24
2026-04-30 12:58:19 +08:00

26 lines
508 B
Go

package cmd
import "testing"
func TestNormalizeAPIPath(t *testing.T) {
tests := []struct {
input string
want string
}{
{"/v1/users/me", "/v1/users/me"},
{"/v1", "/v1"},
{"/users/me", "/v1/users/me"},
{"users/me", "/v1/users/me"},
{"/search", "/v1/search"},
{"", ""},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := normalizeAPIPath(tt.input)
if got != tt.want {
t.Errorf("normalizeAPIPath(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}