spec/nexmos/number_spec.rb in nexmos-0.2 vs spec/nexmos/number_spec.rb in nexmos-0.3
- old
+ new
@@ -1,66 +1,68 @@
require 'spec_helper'
describe ::Nexmos::Number do
let(:webmock_default_headers) do
{
- :headers => {
- 'Accept' => 'application/json',
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
- 'User-Agent' => ::Nexmos.user_agent
- }
+ :headers => {
+ 'Accept' => 'application/json',
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
+ 'User-Agent' => ::Nexmos.user_agent
+ }
}
end
let(:finland_numbers_search) do
- {"numbers" => [
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950816",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950815",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950814",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950813",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950812",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950806",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950805",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950804",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950798",
- "country" => "FI",
- "cost" => "3.00"},
- {"type" => "mobile-lvn",
- "msisdn" => "3584573950796",
- "country" => "FI",
- "cost" => "3.00"}],
- "count" => 22}
+ {
+ "numbers" => [
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950816",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950815",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950814",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950813",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950812",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950806",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950805",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950804",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950798",
+ "country" => "FI",
+ "cost" => "3.00" },
+ { "type" => "mobile-lvn",
+ "msisdn" => "3584573950796",
+ "country" => "FI",
+ "cost" => "3.00" }
+ ],
+ "count" => 22 }.to_json
end
before(:each) do
::Nexmos.reset!
::Nexmos.setup do |c|
- c.api_key = 'default_key'
+ c.api_key = 'default_key'
c.api_secret = 'default_secret'
end
end
subject { ::Nexmos::Number.new }
@@ -70,19 +72,19 @@
expect { subject.search }.to raise_error('country params required')
end
it 'should return list of numbers' do
request = stub_request(:get, "https://rest.nexmo.com/number/search?api_key=default_key&api_secret=default_secret&country=FI").
- with(webmock_default_headers).to_return(:status => 200, :body => finland_numbers_search, :headers => {})
- res = subject.search(:country => 'FI')
- res.should be_kind_of(::Hash)
- res.success?.should be_true
- res['count'].should == 22
- res['numbers'].should be_kind_of(::Array)
- res['numbers'].size.should == 10
- res['numbers'].first.keys.sort.should == ["cost", "country", "msisdn", "type"]
- request.should have_been_made.once
+ with(webmock_default_headers).to_return(:status => 200, :body => finland_numbers_search, :headers => {'Content-Type' => 'application/json'})
+ res = subject.search(:country => 'FI')
+ expect(res).to be_kind_of(::Hash)
+ expect(res.success?).to be_truthy
+ expect(res['count']).to eq(22)
+ expect(res['numbers']).to be_kind_of(::Array)
+ expect(res['numbers'].size).to eq(10)
+ expect(res['numbers'].first.keys.sort).to eq(["cost", "country", "msisdn", "type"])
+ expect(request).to have_been_made.once
end
end
context '#buy' do
it 'should return error on missed params' do
@@ -93,16 +95,16 @@
end
it 'should buy number' do
request = stub_request(:post, "https://rest.nexmo.com/number/buy").
with(
- :headers => {'Accept'=>'application/json', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=> ::Nexmos.user_agent},
- :body => {"api_key"=>"default_key", "api_secret"=>"default_secret", "country"=>"FI", "msisdn"=>"3584573950816"}
- ).to_return(:status => 200, :body => "", :headers => {})
- res = subject.buy(:country => 'FI', :msisdn => '3584573950816' )
- res.should be_kind_of(::Hash)
- res.success?.should be_true
- request.should have_been_made.once
+ :headers => { 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => ::Nexmos.user_agent },
+ :body => { "api_key" => "default_key", "api_secret" => "default_secret", "country" => "FI", "msisdn" => "3584573950816" }
+ ).to_return(:status => 200, :body => "", :headers => {'Content-Type' => 'application/json'})
+ res = subject.buy(:country => 'FI', :msisdn => '3584573950816')
+ expect(res).to be_kind_of(::Hash)
+ expect(res.success?).to be_truthy
+ expect(request).to have_been_made.once
end
end
context '#cancel' do