-
Notifications
You must be signed in to change notification settings - Fork 51
/
services_spec.rb
107 lines (81 loc) · 3.27 KB
/
services_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'spec_helper'
describe Dnsimple::Client, ".services" do
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").services }
describe "#list_services" do
before do
stub_request(:get, %r{/v2/services}).
to_return(read_http_fixture("listServices/success.http"))
end
it "builds the correct request" do
subject.list_services
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services").
with(headers: { "Accept" => "application/json" })
end
it "supports pagination" do
subject.services(page: 2)
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services?page=2")
end
it "supports extra request options" do
subject.services(query: { foo: "bar" })
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services?foo=bar")
end
it "supports sorting" do
subject.services(sort: "short_name:asc")
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services?sort=short_name:asc")
end
it "returns the list of available services" do
response = subject.list_services
expect(response).to be_a(Dnsimple::CollectionResponse)
response.data.each do |service|
expect(service).to be_a(Dnsimple::Struct::Service)
expect(service.id).to be_a(Fixnum)
expect(service.name).to be_a(String)
expect(service.short_name).to be_a(String)
expect(service.description).to be_a(String)
service.settings.each do |service_setting|
expect(service_setting).to be_a(Dnsimple::Struct::Service::Setting)
end
end
end
end
describe "#all_services" do
before do
stub_request(:get, %r{/v2/services}).
to_return(read_http_fixture("listServices/success.http"))
end
it "delegates to client.paginate" do
expect(subject).to receive(:paginate).with(:services, foo: "bar")
subject.all_services(foo: "bar")
end
it "supports sorting" do
subject.all_services(sort: "short_name:asc")
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services?page=1&per_page=100&sort=short_name:asc")
end
end
describe "#service" do
let(:service_id) { 1 }
before do
stub_request(:get, %r{/v2/services/#{service_id}$}).
to_return(read_http_fixture("getService/success.http"))
end
it "builds the correct request" do
subject.service(service_id)
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services/#{service_id}").
with(headers: { "Accept" => "application/json" })
end
it "returns the service" do
response = subject.service(service_id)
expect(response).to be_a(Dnsimple::Response)
service = response.data
expect(service).to be_a(Dnsimple::Struct::Service)
expect(service.id).to eq(1)
expect(service.name).to eq("Service 1")
expect(service.short_name).to eq("service1")
expect(service.description).to eq("First service example.")
expect(service.setup_description).to be_nil
expect(service.requires_setup).to be_falsey
expect(service.default_subdomain).to be_nil
expect(service.settings).to eq([])
end
end
end