Begin implementing the underlying method to create a new Sauce Labs account for the heroku user
This commit is contained in:
parent
35a07e0b50
commit
1c18c33487
|
@ -7,6 +7,8 @@ module Sauce
|
|||
class Sauce
|
||||
attr_reader :config
|
||||
|
||||
API_CLIENT_ID = '0C309258-40FA-4138-91AF-C226F17C6954'
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
@ -24,7 +26,7 @@ module Sauce
|
|||
:body => body.to_json,
|
||||
:basic_auth => {:username => config.username,
|
||||
:password => config.access_key},
|
||||
:headers => {'Content-Type' => 'application/json'})
|
||||
:headers => default_headers)
|
||||
|
||||
if response.code == 401
|
||||
raise Errors::SauceAuthenticationError, 'Authentication failed'
|
||||
|
@ -43,10 +45,34 @@ module Sauce
|
|||
return response['embed']
|
||||
end
|
||||
|
||||
def default_headers
|
||||
@headers ||= begin
|
||||
{
|
||||
'Content-Type' => 'application/json'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def scout_url
|
||||
return nil unless config.configured?
|
||||
"https://saucelabs.com/rest/v1/users/#{config.username}/scout"
|
||||
end
|
||||
|
||||
def create_account(username, password, email, full_name)
|
||||
if username.nil? || email.nil? || password.nil?
|
||||
raise Errors::InvalidParametersError
|
||||
end
|
||||
full_name ||= ''
|
||||
data = {:username => username,
|
||||
:email => email,
|
||||
:password => password,
|
||||
:name => full_name,
|
||||
:token => API_CLIENT_ID}
|
||||
|
||||
response = HTTParty.post(account_url,
|
||||
:body => data.to_json,
|
||||
:headers => default_headers)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -108,4 +108,41 @@ describe Sauce::Heroku::API::Sauce do
|
|||
it { should_not be_empty }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#default_headers' do
|
||||
subject { api.default_headers }
|
||||
it { should have_key 'Content-Type' }
|
||||
it { expect(subject['Content-Type']).to eql('application/json') }
|
||||
end
|
||||
|
||||
describe '#create_account' do
|
||||
it { should respond_to :create_account }
|
||||
|
||||
context 'without valid parameters' do
|
||||
it 'should raise an error if nils are passed' do
|
||||
expect {
|
||||
api.create_account(nil, nil, nil, nil)
|
||||
}.to raise_error(Sauce::Heroku::Errors::InvalidParametersError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid parameters' do
|
||||
let(:url) { 'http://create/user' }
|
||||
let(:username) { 'rspec' }
|
||||
let(:password) { 'bdd' }
|
||||
let(:email) { 'rspec@example.org ' }
|
||||
|
||||
before :each do
|
||||
api.stub(:account_url => url)
|
||||
end
|
||||
|
||||
it 'should POST to Sauce Labs' do
|
||||
HTTParty.should_receive(:post).with(
|
||||
url,
|
||||
hash_including(:body)
|
||||
)
|
||||
api.create_account(username, password, email, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -143,9 +143,5 @@ describe Sauce::Heroku::Config do
|
|||
end
|
||||
|
||||
describe '#write!' do
|
||||
subject { config.write! }
|
||||
context 'without credentials' do
|
||||
it { should be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue