spec/pesapal_merchant_spec.rb in pesapal-1.5.3 vs spec/pesapal_merchant_spec.rb in pesapal-1.5.4
- old
+ new
@@ -1,46 +1,136 @@
require 'spec_helper'
describe Pesapal::Merchant do
- before :each do
- @pesapal = Pesapal::Merchant.new
- @pesapal_dev = Pesapal::Merchant.new(:development)
- @pesapal_prod = Pesapal::Merchant.new(:production)
+ context 'when mode not specified' do
+
+ before :each do
+ @pesapal = Pesapal::Merchant.new
+ end
+
+ describe '#new' do
+
+ it 'is valid object' do
+ expect(@pesapal).to be_an_instance_of(Pesapal::Merchant)
+ end
+
+ it 'sets default environment variable' do
+ expect(@pesapal.send(:env)).to eq 'development'
+ end
+
+ it 'sets default credentials' do
+ expect(@pesapal.config).to eq({ :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
+ :consumer_key => '<YOUR_CONSUMER_KEY>',
+ :consumer_secret => '<YOUR_CONSUMER_SECRET>'
+ })
+ end
+
+ it 'sets default order details' do
+ expect(@pesapal.order_details).to eq({})
+ end
+ end
+
+ describe '#set_env' do
+
+ it 'sets default environment variable' do
+ @pesapal.set_env
+ expect(@pesapal.send(:env)).to eq 'development'
+ end
+
+ it 'sets endpoints for default environment' do
+ expect(@pesapal.set_env).to eq({:postpesapaldirectorderv4 => 'http://demo.pesapal.com/API/PostPesapalDirectOrderV4',
+ :querypaymentstatus=>'http://demo.pesapal.com/API/QueryPaymentStatus',
+ :querypaymentdetails=>'http://demo.pesapal.com/API/QueryPaymentDetails'
+ })
+ end
+ end
end
- describe '#new' do
+ context 'when mode is specified as development' do
- it 'sets default environment variable' do
- @pesapal.send(:env).should == 'development'
- @pesapal.send(:env).should_not == 'production'
+ before :each do
+ @pesapal = Pesapal::Merchant.new(:development)
end
- it 'sets development environment variable' do
- @pesapal_dev.send(:env).should == 'development'
- @pesapal_dev.send(:env).should_not == 'production'
+ describe '#new(:development)' do
+
+ it 'is valid object' do
+ expect(@pesapal).to be_an_instance_of(Pesapal::Merchant)
+ end
+
+ it 'sets environment variable' do
+ expect(@pesapal.send(:env)).to eq 'development'
+ end
+
+ it 'sets credentials' do
+ expect(@pesapal.config).to eq({ :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
+ :consumer_key => '<YOUR_CONSUMER_KEY>',
+ :consumer_secret => '<YOUR_CONSUMER_SECRET>'
+ })
+ end
+
+ it 'sets order details' do
+ expect(@pesapal.order_details).to eq({})
+ end
end
- it 'sets production environment variable' do
- @pesapal_prod.send(:env).should == 'production'
- @pesapal_prod.send(:env).should_not == 'development'
+ describe '#set_env(:development)' do
+
+ it 'sets environment variable' do
+ @pesapal.set_env :development
+ expect(@pesapal.send(:env)).to eq 'development'
+ end
+
+ it 'sets endpoints for environment' do
+ expect(@pesapal.set_env :development).to eq({:postpesapaldirectorderv4 => 'http://demo.pesapal.com/API/PostPesapalDirectOrderV4',
+ :querypaymentstatus=>'http://demo.pesapal.com/API/QueryPaymentStatus',
+ :querypaymentdetails=>'http://demo.pesapal.com/API/QueryPaymentDetails'
+ })
+ end
end
+ end
- # Check if the initializer successfully sets a Pesapal::Merchant object
- it 'returns a new instance of a pesapal object' do
- @pesapal.should be_an_instance_of Pesapal::Merchant
+ context 'when mode is specified as production' do
+
+ before :each do
+ @pesapal = Pesapal::Merchant.new(:production)
end
- # Checks if the initialized object is properly set with default credentials
- it 'checks if config is set with the default credentials' do
- @pesapal.config.should == { :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
- :consumer_key => '<YOUR_CONSUMER_KEY>',
- :consumer_secret => '<YOUR_CONSUMER_SECRET>'
- }
+ describe '#new(:production)' do
+
+ it 'is valid object' do
+ expect(@pesapal).to be_an_instance_of(Pesapal::Merchant)
+ end
+
+ it 'sets environment variable' do
+ expect(@pesapal.send(:env)).to eq 'production'
+ end
+
+ it 'sets credentials' do
+ expect(@pesapal.config).to eq({ :callback_url => 'http://0.0.0.0:3000/pesapal/callback',
+ :consumer_key => '<YOUR_CONSUMER_KEY>',
+ :consumer_secret => '<YOUR_CONSUMER_SECRET>'
+ })
+ end
+
+ it 'sets order details' do
+ expect(@pesapal.order_details).to eq({})
+ end
end
- # Checks if the initialized object is properly set with empty order details
- it 'checks if config is set with the default credentials' do
- @pesapal.order_details.should == {}
+ describe '#set_env(:production)' do
+
+ it 'sets environment variable' do
+ @pesapal.set_env :production
+ expect(@pesapal.send(:env)).to eq 'production'
+ end
+
+ it 'sets endpoints for environment' do
+ expect(@pesapal.set_env :production).to eq({:postpesapaldirectorderv4 => 'https://www.pesapal.com/API/PostPesapalDirectOrderV4',
+ :querypaymentstatus=>'https://www.pesapal.com/API/QueryPaymentStatus',
+ :querypaymentdetails=>'https://www.pesapal.com/API/QueryPaymentDetails'
+ })
+ end
end
end
end