Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a validation helper for client_id #234

Open
wants to merge 1 commit into
base: feature/sdk-automation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/xero-ruby/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def append_to_default_config(default_config, user_config)
config
end

def client_id_valid?
@client_id.match?(/^[A-F,0-9]{32}$/)
end

def authorization_url
url = URI.parse(@config.login_url)
url.query = URI.encode_www_form(
Expand Down
16 changes: 16 additions & 0 deletions spec/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@
end
end

describe 'validations' do
subject { XeroRuby::ApiClient.new(config: {}, credentials: credentials) }

context 'when the client id is not valid' do
let(:credentials) { { client_id: '' } }

it { is_expected.not_to be_client_id_valid }
end

context 'when the client id is valid' do
let(:credentials) { { client_id: 'AAAAAA9E3FC416CF84283851A1BB7185' } }

it { is_expected.to be_client_id_valid }
end
end

describe 'api_client helper functions' do
let(:api_client) { XeroRuby::ApiClient.new }
let(:token_set) { {'access_token': 'eyx.authorization.data', 'id_token': 'eyx.authentication.data', 'refresh_token': 'REFRESHMENTS'} }
Expand Down