Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit b3ab722

Browse files
committed
Adds access via root attribute for webhooks index
Adds access via root attribute for webhooks index calls.
1 parent cfd4a8c commit b3ab722

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

lib/shipcloud/webhook.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ class Webhook < Base
33
include Shipcloud::Operations::All
44

55
attr_reader :url, :event_types
6+
7+
def self.index_response_root
8+
"webhooks"
9+
end
610
end
711
end

spec/shipcloud/webhooks_spec.rb

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
describe ".all" do
3434
it "makes a new Get request using the correct API endpoint" do
35-
expect(Shipcloud).to receive(:request).with(:get, "webhooks", {}).and_return([])
35+
expect(Shipcloud).to receive(:request).
36+
with(:get, "webhooks", {}).
37+
and_return("webhooks" => [])
3638

3739
Shipcloud::Webhook.all
3840
end
@@ -49,21 +51,25 @@
4951
end
5052

5153
def stub_webhooks_request
52-
allow(Shipcloud).to receive(:request).with(:get, "webhooks", {}).and_return(
53-
[
54-
{
55-
"id" => "583cfd8b-77c7-4447-a3a0-1568bb9cc553",
56-
"url" => "https://example.com/webhook",
57-
"event_types" => ["shipment.tracking.delayed", "shipment.tracking.delivered"],
58-
"deactivated" => false
59-
},
60-
{
61-
"id" => "e0ff4250-6c8e-494d-a069-afd9d566e372",
62-
"url" => "https://example.com/webhook",
63-
"event_types" => ["shipment.tracking.delayed", "shipment.tracking.delivered"],
64-
"deactivated" => false
65-
}
66-
]
67-
)
54+
allow(Shipcloud).to receive(:request).
55+
with(:get, "webhooks", {}).
56+
and_return("webhooks" => webhooks_array)
57+
end
58+
59+
def webhooks_array
60+
[
61+
{
62+
"id" => "583cfd8b-77c7-4447-a3a0-1568bb9cc553",
63+
"url" => "https://example.com/webhook",
64+
"event_types" => ["shipment.tracking.delayed", "shipment.tracking.delivered"],
65+
"deactivated" => false
66+
},
67+
{
68+
"id" => "e0ff4250-6c8e-494d-a069-afd9d566e372",
69+
"url" => "https://example.com/webhook",
70+
"event_types" => ["shipment.tracking.delayed", "shipment.tracking.delivered"],
71+
"deactivated" => false
72+
}
73+
]
6874
end
6975
end

0 commit comments

Comments
 (0)