From 9ba96a006f4cdb528b12467575ec9dbbb350ce1a Mon Sep 17 00:00:00 2001 From: Harry Lewis Date: Sat, 9 Mar 2024 13:55:06 -0500 Subject: [PATCH] Support `test_mode_override` argument in Payrix::Configuration.url --- lib/payrix/configuration.rb | 7 +++- spec/lib/payrix/configuration_spec.rb | 60 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/payrix/configuration.rb b/lib/payrix/configuration.rb index 0c63a8c..7a727ec 100644 --- a/lib/payrix/configuration.rb +++ b/lib/payrix/configuration.rb @@ -11,8 +11,11 @@ def initialize @test_mode = false end - def url - if @test_mode + def url(test_mode_override = nil) + test_mode = @test_mode + test_mode = test_mode_override if [true, false].include?(test_mode_override) + + if test_mode 'https://test-api.payrix.com' else 'https://api.payrix.com' diff --git a/spec/lib/payrix/configuration_spec.rb b/spec/lib/payrix/configuration_spec.rb index 95cbe44..da1a623 100644 --- a/spec/lib/payrix/configuration_spec.rb +++ b/spec/lib/payrix/configuration_spec.rb @@ -41,5 +41,65 @@ expect(configuration.url).to eq('https://api.payrix.com') end end + + context 'when nil is passed and the default test mode is on' do + it 'returns https://test-api.payrix.com' do + configuration = described_class.new + + configuration.test_mode = true + + expect(configuration.url(nil)).to eq('https://test-api.payrix.com') + end + end + + context 'when nil is passed and the default test mode is off' do + it 'returns https://api.payrix.com' do + configuration = described_class.new + + configuration.test_mode = false + + expect(configuration.url(nil)).to eq('https://api.payrix.com') + end + end + + context 'when true is passed and the default test mode is on' do + it 'returns https://test-api.payrix.com' do + configuration = described_class.new + + configuration.test_mode = true + + expect(configuration.url(true)).to eq('https://test-api.payrix.com') + end + end + + context 'when true is passed and the default test mode is off' do + it 'returns https://test-api.payrix.com' do + configuration = described_class.new + + configuration.test_mode = false + + expect(configuration.url(true)).to eq('https://test-api.payrix.com') + end + end + + context 'when false is passed and the default test mode is on' do + it 'returns https://api.payrix.com' do + configuration = described_class.new + + configuration.test_mode = true + + expect(configuration.url(false)).to eq('https://api.payrix.com') + end + end + + context 'when false is passed and the default test mode is off' do + it 'returns https://api.payrix.com' do + configuration = described_class.new + + configuration.test_mode = false + + expect(configuration.url(false)).to eq('https://api.payrix.com') + end + end end end