Skip to content

Commit e546e46

Browse files
author
Rimian Perkins
committed
add a validation helper for client_id
1 parent 9eba2a1 commit e546e46

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/xero-ruby/api_client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ def append_to_default_config(default_config, user_config)
5656
config
5757
end
5858

59+
def client_id_valid?
60+
@client_id.match?(/^[A-F,0-9]{32}$/)
61+
end
62+
5963
def authorization_url
6064
url = URI.parse(@config.login_url)
6165
url.query = URI.encode_www_form(

spec/api_client_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@
100100
end
101101
end
102102

103+
describe 'validations' do
104+
subject { XeroRuby::ApiClient.new(config: {}, credentials: credentials) }
105+
106+
context 'when the client id is not valid' do
107+
let(:credentials) { { client_id: '' } }
108+
109+
it { is_expected.not_to be_client_id_valid }
110+
end
111+
112+
context 'when the client id is valid' do
113+
let(:credentials) { { client_id: 'AAAAAA9E3FC416CF84283851A1BB7185' } }
114+
115+
it { is_expected.to be_client_id_valid }
116+
end
117+
end
118+
103119
describe 'api_client helper functions' do
104120
let(:api_client) { XeroRuby::ApiClient.new }
105121
let(:token_set) { {'access_token': 'eyx.authorization.data', 'id_token': 'eyx.authentication.data', 'refresh_token': 'REFRESHMENTS'} }

0 commit comments

Comments
 (0)