(t *testing.T)
| 288 | } |
| 289 | |
| 290 | func TestGmailDraftsCreateCmd_JSON(t *testing.T) { |
| 291 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 292 | if strings.Contains(r.URL.Path, "/gmail/v1/users/me/drafts") && r.Method == http.MethodPost { |
| 293 | w.Header().Set("Content-Type", "application/json") |
| 294 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 295 | "id": "d1", |
| 296 | "message": map[string]any{ |
| 297 | "id": "m1", |
| 298 | }, |
| 299 | }) |
| 300 | return |
| 301 | } |
| 302 | http.NotFound(w, r) |
| 303 | })) |
| 304 | defer srv.Close() |
| 305 | |
| 306 | svc := newGmailServiceFromServer(t, srv) |
| 307 | flags := &RootFlags{Account: "a@b.com"} |
| 308 | |
| 309 | var jsonOut bytes.Buffer |
| 310 | ctx := withGmailTestService(newCmdRuntimeJSONOutputContext(t, &jsonOut, io.Discard), svc) |
| 311 | if err := runKong(t, &GmailDraftsCreateCmd{}, []string{"--to", "a@example.com", "--subject", "S", "--body", "Hello"}, ctx, flags); err != nil { |
| 312 | t.Fatalf("execute: %v", err) |
| 313 | } |
| 314 | |
| 315 | var parsed struct { |
| 316 | DraftID string `json:"draftId"` |
| 317 | ThreadID string `json:"threadId"` |
| 318 | } |
| 319 | if err := json.Unmarshal(jsonOut.Bytes(), &parsed); err != nil { |
| 320 | t.Fatalf("json parse: %v", err) |
| 321 | } |
| 322 | if parsed.DraftID != "d1" { |
| 323 | t.Fatalf("unexpected json: %#v", parsed) |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | func TestGmailDraftsCreateCmd_BodyHTMLFile(t *testing.T) { |
| 328 | htmlPath := filepath.Join(t.TempDir(), "body.html") |
nothing calls this directly
no test coverage detected