leap_salesforce 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,13 @@
1
+ Version 0.1.2
2
+ * Enhancements
3
+ * Added color to output messages
4
+ * Add ticks when successful
5
+ * Check for Salesforce connectivity and OAuth connection on initialisation
6
+ * Add picklist spec into initially created spec files
7
+
1
8
  Version 0.1.1
2
9
  * Enhancements
3
10
  * Suggestions for generated factory
4
11
  * Begin unit tests
5
- * Handle Macrons by ensuring they're not copied into Ruby names / Modules
12
+ * Handle Macrons by ensuring they're not copied into Ruby names / Modules
13
+ * Created executable
data/README.md CHANGED
@@ -23,7 +23,15 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- TODO: Write usage instructions here
26
+ After installing the gem, to get started in creating a fresh repository, the `leap_salesforce` executable can be used.
27
+
28
+ E.g
29
+
30
+ ```
31
+ leap_salesforce init
32
+ ```
33
+
34
+
27
35
 
28
36
  ## Docs
29
37
 
data/exe/leap_salesforce CHANGED
@@ -6,6 +6,8 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
6
6
  require 'thor'
7
7
  require 'leap_salesforce/parameters'
8
8
  require 'leap_salesforce/generator/generator'
9
+ require 'leap_salesforce/error'
10
+ require 'colorize'
9
11
 
10
12
  module LeapSalesforce
11
13
  # Executable for setting up Leap Salesforce
@@ -26,26 +28,26 @@ module LeapSalesforce
26
28
  def init
27
29
  # Ask user to create OAuth application by following
28
30
  unless options[:setup_done]
29
- oauth_setup = input_for "Have you set up OAuth application by following #{OAUTH_WIKI} (y/n)?"
31
+ oauth_setup = input_for "Have you set up OAuth application by following #{OAUTH_WIKI} (y/n)?", :red
30
32
  exit if oauth_setup.downcase == 'n'
31
33
  end
32
34
 
33
35
  query_for_parameters
34
36
  generate_files binding, ['Gemfile', 'Rakefile', '.leap_salesforce.yml', '.rspec',
35
37
  { config: ['general.rb', { credentials: 'salesforce_oauth2.yml' }] },
36
- { spec: %w[spec_helper.rb limit_spec.rb crud_eg_spec.rb] }]
38
+ { spec: %w[spec_helper.rb limit_spec.rb crud_eg_spec.rb picklists_spec.rb] }]
37
39
 
38
40
  environment_content = read_template File.join('config', 'environments', 'specific_file.rb.erb'),
39
41
  binding
40
- generate_file File.join('config', 'environments', "#{@environment}.rb"), environment_content,
41
- overwrite: false
42
+ generate_file File.join('config', 'environments', "#{LeapSalesforce.environment}.rb"),
43
+ environment_content, overwrite: false
42
44
 
43
- puts 'Initial files created!'
44
- puts 'Installing gems'
45
+ puts "\u2713 Initial files created!".colorize :green
46
+ puts 'Installing gems'.colorize :yellow
45
47
  puts `bundle install`
46
- puts 'Creating initial Soql objects. See ".leap_salesforce.yml" for list'
48
+ puts 'Creating initial Soql objects. See ".leap_salesforce.yml" for list'.colorize :yellow
47
49
  puts `rake leaps:create_soql_objects`
48
- puts 'Creating enums'
50
+ puts 'Creating enums'.colorize :yellow
49
51
  puts `rake leaps:create_enums`
50
52
  end
51
53
  end
@@ -31,6 +31,7 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
32
  spec.add_development_dependency 'topoisomerase'
33
33
  spec.add_dependency 'activerecord'
34
+ spec.add_dependency 'colorize'
34
35
  spec.add_dependency 'factory_bot'
35
36
  spec.add_dependency 'faker'
36
37
  spec.add_dependency 'rake'
@@ -0,0 +1,10 @@
1
+ module LeapSalesforce
2
+ # Any error specific to LeapSalesforce
3
+ class Error < StandardError; end
4
+ # Error related to handling a response
5
+ class ResponseError < StandardError; end
6
+ # Error related to setup of test automation suite
7
+ class SetupError < Error; end
8
+ # Error related to Test Users
9
+ class UserError < Error; end
10
+ end
@@ -1,29 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'io/console'
4
+ require 'rest-client'
5
+ require 'soaspec'
6
+
3
7
  module LeapSalesforce
4
8
  # Helpers for LeapSalesforce executable
5
9
  module ExeHelpers
6
10
  # Return input for query
7
11
  # @param [String] query Query to ask on terminal
8
12
  # @return [String] User input to store
9
- def input_for(query)
10
- puts query
13
+ def input_for(query, color = nil)
14
+ if color
15
+ puts query.colorize(color)
16
+ else
17
+ puts query
18
+ end
11
19
  $stdin.gets.strip
12
20
  end
13
21
 
22
+ # Retrieve environment and ensure that environment can be connected to
23
+ def verify_environment
24
+ LeapSalesforce.environment = options[:environment] || input_for('Enter the environment you want to set things up for ' \
25
+ '(This will be parameterised so can be changed later). For production used "prod". Otherwise preference is to use the' \
26
+ ' part of the URL that is unique for the environment')
27
+ # Verify connection to environment
28
+ RestClient.get(LeapSalesforce.general_url)
29
+ rescue SocketError
30
+ message = "Unable to connect to #{LeapSalesforce.general_url}. Potentially problem with" \
31
+ ' internet or proxy settings'.colorize :red
32
+ raise LeapSalesforce::SetupError, message
33
+ else
34
+ puts "\u2713 Connection to #{LeapSalesforce.general_url} successful".colorize :green
35
+ end
36
+
37
+ # Retrieve OAuth credentials and verify that they're correct
38
+ def verify_oauth
39
+ LeapSalesforce.client_id = options[:client_id] || input_for('Client id (Customer Id)')
40
+ LeapSalesforce.client_secret = options[:client_secret] || STDIN.getpass('Client secret (Consumer Secret)')
41
+ LeapSalesforce.api_user = options[:username] || input_for('Salesforce username. It is ideal to start with a System admin' \
42
+ ' so that any necessary metadata can be read. More users can be added later. You can use ERB to make name' \
43
+ ' vary according to environment (e.g., test.user@<%= LeapSalesforce.environment %>.my.company.com)')
44
+ LeapSalesforce.password = options[:password] || STDIN.getpass('Password (Recommendation is that 1 password' \
45
+ ' be shared across all test users to be easier to manage):')
46
+ Soaspec::OAuth2.debug_oauth = true
47
+ Soaspec::OAuth2.new(LeapSalesforce.oauth_settings).access_token
48
+ rescue StandardError
49
+ raise LeapSalesforce::SetupError, "Cannot perform OAuth. See 'logs' folder for details of what was sent"
50
+ else
51
+ puts "\u2713 OAuth successful".colorize :green
52
+ end
53
+
14
54
  # Ask user to enter parameters specific to their Salesforce environment
15
55
  def query_for_parameters
16
- puts 'Please enter the following information to generate files for a new leap_salesforce testing repo'
17
- # Ask for OAuth credential details
18
- @client_id = options[:client_id] || input_for('Enter the client id')
19
- @client_secret = options[:client_secret] || input_for('Enter the client secret')
20
- @username = options[:username] || input_for('Enter the Salesforce username. It is ideal to start with a System admin' \
21
- ' so that any necessary metadata can be read')
56
+ puts 'Please enter the following information to generate files for a new' \
57
+ ' leap_salesforce testing repo'.colorize(:green)
58
+ verify_environment
59
+ verify_oauth
22
60
  @user_key = options[:user_key] || input_for('Enter a key to refer to this user (This will be stored as a Symbol)')
23
- @password = options[:password] || input_for('Enter password for this user. Recommendation is that 1 password be shared across' \
24
- ' all test users to be easier to manage')
25
- @environment = options[:environment] || input_for('Enter the environment you want to set things up for ' \
26
- '(This will be parameterised so can be changed later)')
27
61
  end
28
62
  end
29
63
  end
@@ -2,6 +2,7 @@
2
2
  require 'erb'
3
3
  require 'fileutils'
4
4
  require_relative 'exe_helpers'
5
+ require 'colorize'
5
6
 
6
7
  module LeapSalesforce
7
8
  # Generators for creating code
@@ -18,10 +19,10 @@ module LeapSalesforce
18
19
  # @param [String] content Content to put within file
19
20
  def generate_file(filename, content, overwrite: true)
20
21
  FileUtils.mkdir_p File.dirname filename unless File.directory? File.dirname(filename)
21
- return puts "File '#{filename}' already exists, skipping..." if (File.exist?(filename) && !overwrite)
22
+ return puts "File '#{filename}' already exists, skipping...".colorize :red if File.exist?(filename) && !overwrite
22
23
 
23
24
  File.write filename, content
24
- puts "Created file at #{filename}"
25
+ puts "\u2713 Created file at #{filename}".colorize :green
25
26
  end
26
27
 
27
28
  # @example Create a spec_helper file and test file in spec folder
@@ -1,4 +1,4 @@
1
- environment: <%= @environment %>
1
+ environment: <%= LeapSalesforce.environment %>
2
2
  # lib_folder: lib/leap_salesforce # Default folder where assets will be stored
3
3
  soql_objects:
4
4
  - Case
@@ -1,3 +1,3 @@
1
- client_id: '<%= @client_id %>'
2
- client_secret: '<%= @client_secret %>'
3
- password: '<%= @password %>'
1
+ client_id: '<%= LeapSalesforce.client_id %>'
2
+ client_secret: '<%= LeapSalesforce.client_secret %>'
3
+ password: '<%= LeapSalesforce.password %>'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Add users to LeapSalesforce context. First user is the default
4
4
  module LeapSalesforce
5
- Users.add User.new <%= ":#{@user_key}" %>, '<%= @username %>'
5
+ Users.add User.new <%= ":#{@user_key}" %>, '<%= LeapSalesforce.api_user %>'
6
6
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Picklists' do
4
+ LeapSalesforce.objects_to_verify.each do |data_class|
5
+ SoqlEnum.values_for(data_class).each do |picklist|
6
+ it "#{picklist} has not changed values" do
7
+ expect(picklist.values).to match_array data_class.picklist_for(picklist.name)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,7 +3,7 @@
3
3
  require_relative 'users/users'
4
4
  require_relative 'soql_object'
5
5
 
6
- # Adding parameters to set for authentication
6
+ # Adding parameters to set for authentication, environment and other common settings
7
7
  module LeapSalesforce
8
8
  @config_folder = 'config'
9
9
  @lib_folder = File.join('lib', 'leap_salesforce').freeze
@@ -20,6 +20,23 @@ module LeapSalesforce
20
20
  ENV['LEAP_ENV'] || @environment
21
21
  end
22
22
 
23
+ # @return [Hash] OAuth2 parameters used in connecting to salesforce
24
+ def oauth_settings
25
+ settings = {
26
+ username: '<%= LeapSalesforce.api_user %>', password: LeapSalesforce.password,
27
+ client_id: LeapSalesforce.client_id,
28
+ client_secret: LeapSalesforce.client_secret,
29
+ token_url: "#{LeapSalesforce.general_url}/services/oauth2/token"
30
+ }
31
+ settings[:security_token] = LeapSalesforce.security_token if LeapSalesforce.security_token
32
+ settings
33
+ end
34
+
35
+ # @return [String] General salesforce URL for logging in to
36
+ def general_url
37
+ "https://#{LeapSalesforce.environment == 'prod' ? 'login' : 'test'}.salesforce.com"
38
+ end
39
+
23
40
  # @param [String, LeapSalesforce::User] user User or email address of user
24
41
  def api_user=(user)
25
42
  @api_user = case user
@@ -47,6 +64,8 @@ module LeapSalesforce
47
64
  attr_accessor :client_id
48
65
  # @return [String] Client secret in Salesforce OAuth app
49
66
  attr_accessor :client_secret
67
+ # @return [String] Token specific to a user used for authentication
68
+ attr_accessor :security_token
50
69
  # @return [String] Path where library generated assets are stored. By default lib/leap_salesforce
51
70
  attr_accessor :lib_folder
52
71
  # @return [Array] List of objects to verify metadata for. This includes enums, required values
@@ -2,14 +2,12 @@
2
2
 
3
3
  require 'soaspec'
4
4
 
5
- # Handles basic Soql interactions.
5
+ # Handles basic Soql interactions. These are done through classes that are tied to this handler, i.e, the SoqlData
6
+ # class.
6
7
  # Credentials are stored either in 'config/credentials' folder or via environment variables
7
8
  # To check out SOQL SCHEMA go to workbench.developerforce.com. Use Sandbox and login
8
9
  class SoqlHandler < Soaspec::RestHandler
9
- oauth2 username: '<%= LeapSalesforce.api_user %>', password: LeapSalesforce.password,
10
- client_id: LeapSalesforce.client_id,
11
- client_secret: LeapSalesforce.client_secret,
12
- token_url: "https://#{LeapSalesforce.environment == 'prod' ? 'login' : 'test'}.salesforce.com/services/oauth2/token"
10
+ oauth2 LeapSalesforce.oauth_settings
13
11
  base_url '<%= instance_url %>/services/data/v<%= api_version %>/'
14
12
 
15
13
  pascal_keys true
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LeapSalesforce
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -13,17 +13,7 @@ require 'require_all'
13
13
  require 'rake'
14
14
  require 'factory_bot' # For mass production of data
15
15
  require 'faker' # For fake data
16
-
17
- module LeapSalesforce
18
- class Error < StandardError; end
19
- # Error related to handling a response
20
- class ResponseError < StandardError; end
21
- # Error related to setup of test automation suite
22
- class SetupError < Error; end
23
- # Error related to Test Users
24
- class UserError < Error;
25
- end
26
- end
16
+ require 'leap_salesforce/error'
27
17
 
28
18
  LEAP_CONFIG_FILE = '.leap_salesforce.yml'
29
19
  CREDENTIAL_FILE = File.join('config', 'credentials', 'salesforce_oauth2.yml')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leap_salesforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: colorize
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: factory_bot
86
100
  requirement: !ruby/object:Gem::Requirement
@@ -231,6 +245,7 @@ files:
231
245
  - exe/leap_salesforce
232
246
  - leap_salesforce.gemspec
233
247
  - lib/leap_salesforce.rb
248
+ - lib/leap_salesforce/error.rb
234
249
  - lib/leap_salesforce/ext/string.rb
235
250
  - lib/leap_salesforce/ext/time.rb
236
251
  - lib/leap_salesforce/generator/default.rb
@@ -251,6 +266,7 @@ files:
251
266
  - lib/leap_salesforce/generator/templates/soql_object_field_names.rb.erb
252
267
  - lib/leap_salesforce/generator/templates/spec/crud_eg_spec.rb.erb
253
268
  - lib/leap_salesforce/generator/templates/spec/limit_spec.rb.erb
269
+ - lib/leap_salesforce/generator/templates/spec/picklists_spec.rb.erb
254
270
  - lib/leap_salesforce/generator/templates/spec/spec_helper.rb.erb
255
271
  - lib/leap_salesforce/limits.rb
256
272
  - lib/leap_salesforce/parameters.rb