Commands now auto-detect timezone from user's primary calendar. New flags: --today, --tomorrow, --week, --days for intuitive time ranges. Supports relative expressions: "today", "tomorrow", "monday", etc. Updated commands: - calendar events: --today, --tomorrow, --week, --days - calendar search: --today, --week - calendar conflicts: --today, --week, --days 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"google.golang.org/api/calendar/v3"
|
|
"google.golang.org/api/option"
|
|
)
|
|
|
|
func TestExecute_CalendarCalendars_JSON(t *testing.T) {
|
|
origNew := newCalendarService
|
|
t.Cleanup(func() { newCalendarService = origNew })
|
|
|
|
srv := httptest.NewServer(withPrimaryCalendar(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if !(strings.Contains(r.URL.Path, "calendarList") && r.Method == http.MethodGet) {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_ = json.NewEncoder(w).Encode(map[string]any{
|
|
"items": []map[string]any{
|
|
{"id": "c1", "summary": "One", "accessRole": "owner"},
|
|
{"id": "c2", "summary": "Two", "accessRole": "reader"},
|
|
},
|
|
})
|
|
})))
|
|
defer srv.Close()
|
|
|
|
svc, err := calendar.NewService(context.Background(),
|
|
option.WithoutAuthentication(),
|
|
option.WithHTTPClient(srv.Client()),
|
|
option.WithEndpoint(srv.URL+"/"),
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("NewService: %v", err)
|
|
}
|
|
newCalendarService = func(context.Context, string) (*calendar.Service, error) { return svc, nil }
|
|
|
|
out := captureStdout(t, func() {
|
|
_ = captureStderr(t, func() {
|
|
if err := Execute([]string{"--json", "--account", "a@b.com", "calendar", "calendars"}); err != nil {
|
|
t.Fatalf("Execute: %v", err)
|
|
}
|
|
})
|
|
})
|
|
|
|
var parsed struct {
|
|
Calendars []struct {
|
|
ID string `json:"id"`
|
|
Summary string `json:"summary"`
|
|
AccessRole string `json:"accessRole"`
|
|
} `json:"calendars"`
|
|
NextPageToken string `json:"nextPageToken"`
|
|
}
|
|
if err := json.Unmarshal([]byte(out), &parsed); err != nil {
|
|
t.Fatalf("json parse: %v\nout=%q", err, out)
|
|
}
|
|
if len(parsed.Calendars) != 2 || parsed.Calendars[0].ID != "c1" || parsed.Calendars[1].ID != "c2" {
|
|
t.Fatalf("unexpected calendars: %#v", parsed.Calendars)
|
|
}
|
|
}
|