From 0010fe1facee2eb190ba1f8b2d22920a4f674479 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Thu, 2 Apr 2026 16:51:51 +0200 Subject: [PATCH] feat(batch): add DeleteBatchJob method --- batch/batch.go | 7 +++++++ batch_api.go | 9 +++++++++ batch_test.go | 27 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/batch/batch.go b/batch/batch.go index d7604d3..c9df751 100644 --- a/batch/batch.go +++ b/batch/batch.go @@ -60,3 +60,10 @@ type ListParams struct { Status []string OrderBy *string } + +// DeleteResponse is the response from deleting a batch job. +type DeleteResponse struct { + ID string `json:"id"` + Object string `json:"object"` + Deleted bool `json:"deleted"` +} diff --git a/batch_api.go b/batch_api.go index 37fff08..4e06afe 100644 --- a/batch_api.go +++ b/batch_api.go @@ -76,3 +76,12 @@ func (c *Client) CancelBatchJob(ctx context.Context, jobID string) (*batch.JobOu } return &resp, nil } + +// DeleteBatchJob deletes a batch job. +func (c *Client) DeleteBatchJob(ctx context.Context, jobID string) (*batch.DeleteResponse, error) { + var resp batch.DeleteResponse + if err := c.doJSON(ctx, "DELETE", fmt.Sprintf("/v1/batch/jobs/%s", jobID), nil, &resp); err != nil { + return nil, err + } + return &resp, nil +} diff --git a/batch_test.go b/batch_test.go index f7cf9b9..b307e8e 100644 --- a/batch_test.go +++ b/batch_test.go @@ -121,3 +121,30 @@ func TestCancelBatchJob_Success(t *testing.T) { t.Errorf("got status %q", job.Status) } } + +func TestDeleteBatchJob_Success(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("expected DELETE, got %s", r.Method) + } + if r.URL.Path != "/v1/batch/jobs/batch-123" { + t.Errorf("got path %s", r.URL.Path) + } + json.NewEncoder(w).Encode(map[string]any{ + "id": "batch-123", "object": "batch", "deleted": true, + }) + })) + defer server.Close() + + client := NewClient("key", WithBaseURL(server.URL)) + resp, err := client.DeleteBatchJob(context.Background(), "batch-123") + if err != nil { + t.Fatal(err) + } + if resp.ID != "batch-123" { + t.Errorf("got id %q", resp.ID) + } + if !resp.Deleted { + t.Error("expected deleted=true") + } +}