spec/rest/ips/addresses_spec.rb in sendgrid4r-0.5.0 vs spec/rest/ips/addresses_spec.rb in sendgrid4r-1.0.0
- old
+ new
@@ -3,25 +3,23 @@
describe SendGrid4r::REST::Ips::Addresses do
describe 'integration test', :it do
before do
Dotenv.load
- @client = SendGrid4r::Client.new(
- username: ENV['SENDGRID_USERNAME'],
- password: ENV['SENDGRID_PASSWORD'])
+ @client = SendGrid4r::Client.new(api_key: ENV['API_KEY'])
end
context 'account is free' do
describe '#get_ip' do
it 'raise error' do
begin
expect do
- @client.get_ip('10.10.10.10').to raise_error(
+ @client.get_ip(ip: '10.10.10.10').to raise_error(
RestClient::Forbidden
)
end
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
end
@@ -30,20 +28,18 @@
context 'account is silver' do
TEST_POOL = 'test_pool'
before do
begin
- @client = SendGrid4r::Client.new(
- username: ENV['SILVER_SENDGRID_USERNAME'],
- password: ENV['SILVER_SENDGRID_PASSWORD'])
+ @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
# refresh the pool
pools = @client.get_pools
pools.each do |pool|
- @client.delete_pool(TEST_POOL) if pool.name == TEST_POOL
+ @client.delete_pool(name: TEST_POOL) if pool.name == TEST_POOL
end
- @client.post_pool(TEST_POOL)
- rescue => e
+ @client.post_pool(name: TEST_POOL)
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
@@ -55,110 +51,55 @@
ip = ips[0]
expect(ip).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
expect(ip.ip).to be_a(String)
expect(ip.pools).to be_a(Array)
expect(ip.warmup ? true : true).to eq(true)
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
it '#get_ips_assigned' do
begin
ips = @client.get_ips_assigned
expect(ips.length).to be > 0
expect(ips[0]).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
it '#get_ip' do
begin
ips = @client.get_ips_assigned
expect(
- @client.get_ip(ips[0].ip)
+ @client.get_ip(ip: ips[0].ip)
).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
- rescue => e
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
it '#post_ip_to_pool' do
begin
ips = @client.get_ips_assigned
- actual = @client.post_ip_to_pool(TEST_POOL, ips[0].ip)
+ actual = @client.post_ip_to_pool(
+ pool_name: TEST_POOL, ip: ips[0].ip
+ )
expect(actual.ip).to eq(ips[0].ip)
expect(actual.pools).to include(TEST_POOL)
expect(actual.pools).to be_a(Array)
- @client.delete_ip_from_pool(TEST_POOL, ips[0].ip)
- rescue => e
+ @client.delete_ip_from_pool(pool_name: TEST_POOL, ip: ips[0].ip)
+ rescue RestClient::ExceptionWithResponse => e
puts e.inspect
raise e
end
end
end
-
- context 'with block call' do
- it '#get_ips' do
- @client.get_ips do |resp, req, res|
- resp =
- SendGrid4r::REST::Ips::Addresses.create_addresses(
- JSON.parse(resp)
- )
- expect(resp).to be_a(Array)
- expect(req).to be_a(RestClient::Request)
- expect(res).to be_a(Net::HTTPOK)
- end
- end
-
- it '#get_ips_assigned' do
- @client.get_ips_assigned do |resp, req, res|
- resp =
- SendGrid4r::REST::Ips::Addresses.create_addresses(
- JSON.parse(resp)
- )
- expect(resp).to be_a(Array)
- expect(req).to be_a(RestClient::Request)
- expect(res).to be_a(Net::HTTPOK)
- end
- end
-
- it '#get_ip' do
- ips = @client.get_ips_assigned
- @client.get_ip(ips[0].ip) do |resp, req, res|
- resp =
- SendGrid4r::REST::Ips::Addresses.create_address(
- JSON.parse(resp)
- )
- expect(resp).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
- expect(req).to be_a(RestClient::Request)
- expect(res).to be_a(Net::HTTPOK)
- end
- end
-
- it '#post_ip_to_pool' do
- ips = @client.get_ips_assigned
- @client.post_ip_to_pool(TEST_POOL, ips[0].ip) do |resp, req, res|
- resp =
- SendGrid4r::REST::Ips::Addresses.create_address(
- JSON.parse(resp)
- )
- expect(resp).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
- expect(req).to be_a(RestClient::Request)
- expect(res).to be_a(Net::HTTPCreated)
- end
- @client.delete_ip_from_pool(TEST_POOL, ips[0].ip) do |resp, req, res|
- expect(resp).to eq('')
- expect(req).to be_a(RestClient::Request)
- expect(res).to be_a(Net::HTTPNoContent)
- end
- end
- end
end
describe 'unit test', :ut do
let(:client) do
SendGrid4r::Client.new(api_key: '')
@@ -211,16 +152,16 @@
end
end
it '#get_ip' do
allow(client).to receive(:execute).and_return(address)
- actual = client.get_ip('')
+ actual = client.get_ip(ip: '')
expect(actual).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
end
it '#post_ip_to_pool' do
allow(client).to receive(:execute).and_return(address)
- actual = client.post_ip_to_pool('', '')
+ actual = client.post_ip_to_pool(pool_name: '', ip: '')
expect(actual).to be_a(SendGrid4r::REST::Ips::Addresses::Address)
end
it 'creates addresses instance' do
actual = SendGrid4r::REST::Ips::Addresses.create_addresses(addresses)