Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/resend/broadcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def list(params = {})
Resend::Request.new(path, {}, "get").perform
end

def cancel(broadcast_id = "")
path = "broadcasts/#{broadcast_id}/cancel"
Resend::Request.new(path, {}, "post").perform
end

# https://resend.com/docs/api-reference/broadcasts/delete-broadcast
def remove(broadcast_id = "")
path = "broadcasts/#{broadcast_id}"
Expand Down
14 changes: 14 additions & 0 deletions spec/broadcasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@
end
end

describe "cancel" do
it "should cancel broadcast" do
resp = {
"object": "broadcast",
"id": "559ac32e-9ef5-46fb-82a1-b76b840c0f7b"
}
allow(resp).to receive(:body).and_return(resp)
allow(HTTParty).to receive(:send).and_return(resp)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The new cancel spec stubs HTTParty.send (and resp.body) instead of following the file's convention of allow_any_instance_of(Resend::Request).to receive(:perform). Because the HTTP call is stubbed away, the test never asserts that cancel actually hits POST broadcasts/:id/cancel — the expected path, suffix, and verb could all be wrong and the spec would still pass. It effectively only exercises the response-processing plumbing rather than the method being added. Consider stubbing Resend::Request#perform like the other specs, or better, asserting on the request path/verb so the cancel route is actually covered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At spec/broadcasts_spec.rb, line 157:

<comment>The new `cancel` spec stubs `HTTParty.send` (and `resp.body`) instead of following the file's convention of `allow_any_instance_of(Resend::Request).to receive(:perform)`. Because the HTTP call is stubbed away, the test never asserts that `cancel` actually hits `POST broadcasts/:id/cancel` — the expected path, suffix, and verb could all be wrong and the spec would still pass. It effectively only exercises the response-processing plumbing rather than the method being added. Consider stubbing `Resend::Request#perform` like the other specs, or better, asserting on the request path/verb so the cancel route is actually covered.</comment>

<file context>
@@ -147,6 +147,20 @@
+        "id": "559ac32e-9ef5-46fb-82a1-b76b840c0f7b"
+      }
+      allow(resp).to receive(:body).and_return(resp)
+      allow(HTTParty).to receive(:send).and_return(resp)
+
+      broadcast = Resend::Broadcasts.cancel(resp[:id])
</file context>


broadcast = Resend::Broadcasts.cancel(resp[:id])
expect(broadcast[:id]).to eql "559ac32e-9ef5-46fb-82a1-b76b840c0f7b"
end
end

describe "remove" do
it "should remove broadcast" do
allow_any_instance_of(Resend::Request).to receive(:perform).and_return("")
Expand Down