gogcli/internal/cmd/slides_delete_slide_test.go
Chris Parsons 8b08d11777
feat(slides): add add-slide, list-slides, and delete-slide commands (#214)
* feat(slides): add `slides add-slide` command for full-bleed image slides

Adds a new `gog slides add-slide <presentationId> <image>` command that
appends a slide with a full-bleed image and optional speaker notes using
the native Google Slides API (presentations.batchUpdate).

Workflow: create a deck with `gog slides create`, then add slides one at
a time with this command. Supports --notes for inline text and
--notes-file for multiline markdown speaker notes.

Also registers ServiceSlides in the auth layer with proper scopes and
readonly support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(slides): add list-slides and delete-slide commands

list-slides shows all slide object IDs in a presentation.
delete-slide removes a slide by its object ID.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(slides): add --before flag to add-slide for insertion ordering

Allow inserting a slide before a specific existing slide ID instead of
always appending to the end of the presentation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(slides): add read-slide, update-notes, and replace-slide commands

Adds three new commands to support in-place editing of existing slides:

- `slides read-slide` — shows slide content including speaker notes,
  text elements, and image references (supports --json output)
- `slides update-notes` — updates speaker notes on an existing slide
  without deleting/re-adding (--notes or --notes-file)
- `slides replace-slide` — atomically swaps the image on an existing
  slide using the ReplaceImage API, optionally updating notes in the
  same batch operation

These eliminate the error-prone delete+add-before workflow when editing
slides in existing decks.

Closes chrismdp/gogcli#1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(slides): rebase PR 214, clear notes semantics, and hard-fail missing placeholders (#214) (thanks @chrismdp)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-02-14 00:21:59 +01:00

106 lines
2.6 KiB
Go

package cmd
import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"google.golang.org/api/option"
"google.golang.org/api/slides/v1"
"github.com/steipete/gogcli/internal/ui"
)
func TestSlidesDeleteSlide(t *testing.T) {
origSlides := newSlidesService
t.Cleanup(func() { newSlidesService = origSlides })
var deletedObjectID string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
switch {
case strings.HasSuffix(r.URL.Path, ":batchUpdate") && r.Method == http.MethodPost:
var req slides.BatchUpdatePresentationRequest
if err := json.NewDecoder(r.Body).Decode(&req); err == nil {
for _, rr := range req.Requests {
if rr.DeleteObject != nil {
deletedObjectID = rr.DeleteObject.ObjectId
}
}
}
_ = json.NewEncoder(w).Encode(map[string]any{
"presentationId": "pres1",
"replies": []any{},
})
default:
http.NotFound(w, r)
}
}))
defer srv.Close()
svc, err := slides.NewService(context.Background(),
option.WithoutAuthentication(),
option.WithHTTPClient(srv.Client()),
option.WithEndpoint(srv.URL+"/"),
)
if err != nil {
t.Fatalf("slides.NewService: %v", err)
}
newSlidesService = func(context.Context, string) (*slides.Service, error) { return svc, nil }
flags := &RootFlags{Account: "a@b.com"}
out := captureStdout(t, func() {
u, uiErr := ui.New(ui.Options{Stdout: io.Discard, Stderr: io.Discard, Color: "never"})
if uiErr != nil {
t.Fatalf("ui.New: %v", uiErr)
}
ctx := ui.WithUI(context.Background(), u)
cmd := &SlidesDeleteSlideCmd{
PresentationID: "pres1",
SlideID: "slide_abc",
}
if err := cmd.Run(ctx, flags); err != nil {
t.Fatalf("Run: %v", err)
}
})
_ = out
if deletedObjectID != "slide_abc" {
t.Errorf("expected delete of slide_abc, got %q", deletedObjectID)
}
}
func TestSlidesDeleteSlide_EmptyID(t *testing.T) {
origSlides := newSlidesService
t.Cleanup(func() { newSlidesService = origSlides })
newSlidesService = func(context.Context, string) (*slides.Service, error) {
t.Fatal("slides service should not be created")
return nil, context.Canceled
}
flags := &RootFlags{Account: "a@b.com"}
u, uiErr := ui.New(ui.Options{Stdout: io.Discard, Stderr: io.Discard, Color: "never"})
if uiErr != nil {
t.Fatalf("ui.New: %v", uiErr)
}
ctx := ui.WithUI(context.Background(), u)
cmd := &SlidesDeleteSlideCmd{
PresentationID: "pres1",
SlideID: " ",
}
err := cmd.Run(ctx, flags)
if err == nil || !strings.Contains(err.Error(), "empty slideId") {
t.Fatalf("expected empty slideId error, got: %v", err)
}
}