Skip to content

Commit

Permalink
Merge pull request #18 from bulletproofnetworks/set_company_name
Browse files Browse the repository at this point in the history
Set company name
  • Loading branch information
keviny22 committed Jan 28, 2016
2 parents b7c3436 + 56e8c80 commit 48f5898
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@
/pkg/
/spec/reports/
/tmp/
*.gem
31 changes: 31 additions & 0 deletions README.md
Expand Up @@ -65,6 +65,7 @@ aws_utils = AwsAccountUtils::AwsAccountUtils.new(
* [request_consolidated_billing](#request_consolidated_billing)
* [set_alternate_contacts](#set_alternate_contacts)
* [set_challenge_questions](#set_challenge_questions)
* [set_company_name](#set_company_name)

create_account
------------
Expand Down Expand Up @@ -468,6 +469,36 @@ answers: (optional, Hash) - A hash of answers to fill in for the security questi

---

set_company_name
------------

> Sets company name for the account (any time after account is created)
`set_company_name(account_email:, account_password:, company_name:)`

**Examples:**
```Ruby

resp = aws_utils.set_alternate_contacts(account_email: 'adfefef@gmail.com',
account_password: 'foobar1212121,
name: 'The Munsters, Inc.')
resp #=> True/False
```
**Parameters:**
```
account_email: (required, String) - The email address to use with this account
account_password: (required, String) - The password to use with this account
contact_info: (required, String) - The company name to add to this account
```
**Returns:**
`#return => Boolean`
---
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
18 changes: 16 additions & 2 deletions lib/aws_account_utils.rb
Expand Up @@ -13,6 +13,7 @@
require 'aws_account_utils/root_access_keys'
require 'aws_account_utils/password'
require 'aws_account_utils/alternate_contacts'
require 'aws_account_utils/company_name'
require 'aws_account_utils/logout'

module AwsAccountUtils
Expand Down Expand Up @@ -148,12 +149,21 @@ def set_alternate_contacts(account_email:, account_password:, contact_info:)
raise ArgumentError, "contact_info: must be a hash." unless contact_info.is_a?(Hash)

resp = alternate_contacts.set account_email, account_password, contact_info
logger.info 'Set alterante contacts.' if resp
logger.info 'Set alternate contacts.' if resp
resp
ensure
browser.close rescue nil
end

def set_company_name(account_email:, account_password:, name:)
resp = company_name.set account_email, account_password, name
logger.info 'Set company name.' if resp
resp
ensure
browser.close rescue nil
end


private
def account_registration
@account_registration ||= AccountRegistration.new logger, browser
Expand All @@ -163,6 +173,10 @@ def alternate_contacts
@alternate_contacts ||= AlternateContacts.new logger, browser
end

def company_name
@company_name ||= CompanyName.new logger, browser
end

def browser
@browser ||= WatirBrowser.new(logger).create
end
Expand Down Expand Up @@ -211,4 +225,4 @@ def logout
@logout ||= Logout.new logger, browser
end
end
end
end
35 changes: 35 additions & 0 deletions lib/aws_account_utils/company_name.rb
@@ -0,0 +1,35 @@
require 'aws_account_utils/base'
require 'aws_account_utils/login'

module AwsAccountUtils
class CompanyName < Base
attr_reader :logger, :browser

def initialize(logger, browser)
@logger = logger
@browser = browser
end

def set(account_email, account_password, company_name)
logger.debug "Updating Company Name details."
Login.new(logger, browser).execute url,
account_email,
account_password
browser.a(:xpath => '//a[@ng-click="toggleEditingContactInfoState()"]').when_present.click
browser.input(:xpath => '//input[@ng-model="address.company"]').to_subtype.set(company_name)
# screenshot(browser, "1")
browser.button(:xpath => '//button[@ng-click="updateContactInformation()"]').when_present.click
browser.div(:xpath => '//div[@ng-show="options.status == \'success\'"]').wait_until_present
true
rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
screenshot(browser, "error")
raise StandardError, "#{self.class.name} - #{e}"
end

private
def url
'https://console.aws.amazon.com/billing/home?#/account'
end

end
end
2 changes: 1 addition & 1 deletion lib/aws_account_utils/version.rb
@@ -1,3 +1,3 @@
module AwsAccountUtils
VERSION = "0.1.3"
VERSION = "0.1.4"
end
61 changes: 61 additions & 0 deletions spec/aws_account_utils/company_name_spec.rb
@@ -0,0 +1,61 @@
require 'spec_helper'

describe AwsAccountUtils::CompanyName do
let(:logger) { Logger.new(STDOUT) }
let(:subject) { AwsAccountUtils::CompanyName.new logger, browser }
let(:login) { AwsAccountUtils::Login.new logger, browser }
let(:browser) { double 'browser' }
let(:a) { double 'browser element a' }
let(:div) { double 'browser element div' }
let(:input) { double 'browser input' }
let(:button) { double 'browser button' }
let(:text_field) { double 'browser text field' }
let(:url) { 'https://console.aws.amazon.com/billing/home?#/account' }
let(:name) { 'company_name' }

it "should update Contact Details" do
expect(logger).to receive(:debug).with('Updating Company Name details.')
expect(browser).to receive(:text_field).with({:id=>"ap_email"}).and_return text_field
expect(text_field).to receive(:when_present).and_return text_field
expect(text_field).to receive(:set)

expect(browser).to receive(:text_field).with({:id=>"ap_password"}).and_return text_field
expect(text_field).to receive(:when_present).and_return text_field
expect(text_field).to receive(:set)

expect(browser).to receive(:button).with({:id=>"signInSubmit-input"}).and_return button
expect(button).to receive(:when_present).and_return button
expect(button).to receive(:click)

expect(browser).to receive(:goto).with(url)
expect(browser).to receive(:url).and_return('https://www.amazon.com/ap/signin?')
expect(logger).to receive(:debug).with('Logging into AWS.')

expect(browser).to receive(:a)
.with({:xpath=>"//a[@ng-click=\"toggleEditingContactInfoState()\"]"})
.and_return a
expect(a).to receive(:when_present).and_return a
expect(a).to receive(:click)


expect(browser).to receive(:input)
.with({:xpath=>"//input[@ng-model=\"address.company\"]"})
.and_return input
expect(input).to receive(:to_subtype).and_return input
expect(input).to receive(:set).with('company_name').and_return input


expect(browser).to receive(:button)
.with({:xpath=>"//button[@ng-click=\"updateContactInformation()\"]"})
.and_return button
expect(button).to receive(:when_present).and_return button
expect(button).to receive(:click)

expect(browser).to receive(:div)
.with({:xpath=>"//div[@ng-show=\"options.status == 'success'\"]"})
.and_return div
expect(div).to receive(:wait_until_present)

expect(subject.set('my_user', 'my_password', 'company_name')).to be_truthy
end
end

0 comments on commit 48f5898

Please sign in to comment.