leap_salesforce 1.0.1 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +4 -25
- data/ChangeLog +18 -0
- data/README.md +16 -3
- data/leap_salesforce.gemspec +1 -1
- data/lib/leap_salesforce/error.rb +4 -0
- data/lib/leap_salesforce/ext/string.rb +2 -2
- data/lib/leap_salesforce/generator/default.rb +1 -1
- data/lib/leap_salesforce/generator/exe_helpers.rb +3 -3
- data/lib/leap_salesforce/generator/generator.rb +11 -2
- data/lib/leap_salesforce/generator/soql_enums.rb +1 -1
- data/lib/leap_salesforce/generator/soql_objects.rb +2 -2
- data/lib/leap_salesforce/parameters.rb +3 -2
- data/lib/leap_salesforce/soql_data/soql_global_object_data.rb +2 -2
- data/lib/leap_salesforce/soql_data/soql_object_describe.rb +23 -0
- data/lib/leap_salesforce/users/user.rb +2 -4
- data/lib/leap_salesforce/users/users.rb +5 -5
- data/lib/leap_salesforce/version.rb +1 -1
- data/lib/leap_salesforce.rb +4 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50460046dd520df2e2b92b0384733e4b7785109d55f42c88d5dd9c81faad23c0
|
4
|
+
data.tar.gz: 1124dc04f4dea935ac48e21b1fccfb8b498b6675f1936164087cd35d75152f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9674782b9b65f4c60fbac4e376594e7ff626c0a538f1f9e1b3ca745d2905bf9ef420a10f7c93d34ab433304cc3989d9329446efa30e2152923e7d07811f0f42c
|
7
|
+
data.tar.gz: f35b3686b4404083210e07cf71ab5ec7c21e132e04bb013dc9aadad245c9538f1152037b64995844b3323431e23bb0070f1195083424757377bf09c3b8d72f4f
|
data/.gitlab-ci.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
include:
|
2
2
|
- template: Code-Quality.gitlab-ci.yml
|
3
3
|
|
4
|
-
image: ruby:
|
4
|
+
image: ruby:3.0
|
5
5
|
|
6
6
|
stages:
|
7
7
|
- test
|
@@ -18,7 +18,7 @@ variables:
|
|
18
18
|
pages:
|
19
19
|
stage: deploy
|
20
20
|
dependencies:
|
21
|
-
-
|
21
|
+
- test
|
22
22
|
script:
|
23
23
|
- mv coverage/ public
|
24
24
|
artifacts:
|
@@ -612,18 +612,8 @@ pages:
|
|
612
612
|
sfdx force:auth:jwt:grant --clientid "$SF_CONSUMER_KEY" --jwtkeyfile assets/server.key --username "$SF_USERNAME" --setdefaultdevhubusername --setalias HubOrg
|
613
613
|
}
|
614
614
|
|
615
|
-
|
616
|
-
image: ruby:
|
617
|
-
stage: test
|
618
|
-
script:
|
619
|
-
- *sfdx_helpers
|
620
|
-
- setup_integration_env
|
621
|
-
- bundle exec rake check_oauth # Check OAuth
|
622
|
-
- bundle exec rake leaps:create_soql_objects
|
623
|
-
- bundle exec rake leaps:create_enums
|
624
|
-
- bundle exec rspec
|
625
|
-
|
626
|
-
test_2.7:
|
615
|
+
test:
|
616
|
+
image: ruby:3.0
|
627
617
|
script:
|
628
618
|
# Decrypt server key
|
629
619
|
- *sfdx_helpers
|
@@ -635,14 +625,3 @@ test_2.7:
|
|
635
625
|
artifacts:
|
636
626
|
paths:
|
637
627
|
- coverage/
|
638
|
-
|
639
|
-
test_3.0:
|
640
|
-
image: ruby:3.0
|
641
|
-
script:
|
642
|
-
# Decrypt server key
|
643
|
-
- *sfdx_helpers
|
644
|
-
- setup_integration_env
|
645
|
-
- bundle exec rake check_oauth # Check OAuth
|
646
|
-
- bundle exec rake leaps:create_soql_objects
|
647
|
-
- bundle exec rake leaps:create_enums
|
648
|
-
- bundle exec rspec
|
data/ChangeLog
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
Version 1.0.5
|
2
|
+
* Fix
|
3
|
+
* Stabilize using of active record by fixing version
|
4
|
+
|
5
|
+
Version 1.0.4
|
6
|
+
* Enhancement
|
7
|
+
* Strip out ':' from user key for when it is accidentally added
|
8
|
+
|
9
|
+
Version 1.0.3
|
10
|
+
* Enhancement
|
11
|
+
* Allow templates to be sourced from external gems for generator
|
12
|
+
|
13
|
+
Version 1.0.2
|
14
|
+
* Enhancement
|
15
|
+
* Only load sub folders of leap_salesforce.lib_folder that are needed by this gem, allowing room for UI
|
16
|
+
and other gems to use other folders independently
|
17
|
+
* New method 'accessors' on object to make it easy to pass list of fields for an object
|
18
|
+
|
1
19
|
Version 1.0.1
|
2
20
|
* Bug fix
|
3
21
|
* Fix #28 allowing !nil for query by non null values
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Welcome to LeapSalesforce gem. This gem helps ones to perform integration tests on Salesforce. It reads the Metadata
|
4
4
|
from Salesforce and creates the foundation for API tests.
|
5
5
|
|
6
|
-
|
6
|
+
Support for UI testing is being worked on in another gem [leap_salesforce_ui](https://gitlab.com/leap-dojo/leap_salesforce_ui)
|
7
7
|
|
8
8
|
## Is this for you?
|
9
9
|
|
@@ -27,7 +27,7 @@ The benefits of an open source tool like this are:
|
|
27
27
|
and can add extra unit tests if you need more confidence
|
28
28
|
* Built with and for CI in Gitlab. Designed to work within Docker containers
|
29
29
|
* Will integrate with `sfdx` leveraging all of it's benefits
|
30
|
-
* Supported by [
|
30
|
+
* Supported by [Sentify](https://www.sentify.co/) who can provide
|
31
31
|
[support and training](https://gitlab.com/leap-dojo/leap_salesforce/wikis/SupportModel)
|
32
32
|
to help you get started and overcome challenges
|
33
33
|
|
@@ -260,7 +260,19 @@ The value of request body can be interrogated with `entity.request_parameters.bo
|
|
260
260
|
|
261
261
|
##### Logging
|
262
262
|
|
263
|
-
By default, API traffic will be logged in a log file in a `logs` folder.
|
263
|
+
By default, API traffic will be logged in a log file in a `logs` folder. The gem `soaspec` is
|
264
|
+
used to log this traffic.
|
265
|
+
|
266
|
+
Following is an example of changing some of the default logging.
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
# Turn this true if you need debug authentication
|
270
|
+
Soaspec::OAuth2.debug_oauth = true
|
271
|
+
# Turn this to true if you want to see API traffic on the terminal
|
272
|
+
Soaspec::SpecLogger.output_to_terminal = true
|
273
|
+
```
|
274
|
+
|
275
|
+
See more configuration parameters in the [Soaspec repo](https://gitlab.com/samuel-garratt/soaspec#logging)
|
264
276
|
|
265
277
|
### CRUD of data
|
266
278
|
|
@@ -565,4 +577,5 @@ Everyone interacting in the LeapSalesforce project’s codebases, issue trackers
|
|
565
577
|
* Presentation on this library [here](https://gitpitch.com/leap-dojo/leap_salesforce?grs=gitlab)
|
566
578
|
* Example of this library within a CI/CD pipeline [here](https://gitlab.com/iqa_public/labs/salesforce_cicd_demo)
|
567
579
|
* Using `leap_salesforce` to download event log files [here](https://gitlab.com/samuel-garratt/leap_salesforce_event_log_files)
|
580
|
+
* Video walking through setting up automation using this [here](https://youtu.be/Xvj0mAnDKfA)
|
568
581
|
|
data/leap_salesforce.gemspec
CHANGED
@@ -32,7 +32,7 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
|
|
32
32
|
spec.add_development_dependency 'semaphore_test_boosters'
|
33
33
|
spec.add_development_dependency 'topoisomerase'
|
34
34
|
spec.add_development_dependency 'yard-doctest'
|
35
|
-
spec.add_dependency 'activerecord'
|
35
|
+
spec.add_dependency 'activerecord', '6.1'
|
36
36
|
spec.add_dependency 'colorize'
|
37
37
|
spec.add_dependency 'factory_bot'
|
38
38
|
spec.add_dependency 'faker', '>= 2.0'
|
@@ -3,12 +3,16 @@
|
|
3
3
|
module LeapSalesforce
|
4
4
|
# Any error specific to LeapSalesforce
|
5
5
|
class Error < StandardError; end
|
6
|
+
|
6
7
|
# Error related to handling a request
|
7
8
|
class RequestError < StandardError; end
|
9
|
+
|
8
10
|
# Error related to handling a response
|
9
11
|
class ResponseError < StandardError; end
|
12
|
+
|
10
13
|
# Error related to setup of test automation suite
|
11
14
|
class SetupError < Error; end
|
15
|
+
|
12
16
|
# Error related to Test Users
|
13
17
|
class UserError < Error; end
|
14
18
|
end
|
@@ -27,8 +27,8 @@ class String
|
|
27
27
|
def to_ruby_friendly
|
28
28
|
tr('&|=', '_').gsub('<', '_lt_').gsub('>', '_gt_')
|
29
29
|
.remove_macrons
|
30
|
-
.gsub(
|
31
|
-
.gsub(
|
30
|
+
.gsub(/\s+/, '_')
|
31
|
+
.gsub(/\W/, '') # Remove any other special characters
|
32
32
|
.handle_initial_characters # Previous step could have removed all characters
|
33
33
|
.humanize_numbered_string
|
34
34
|
end
|
@@ -23,7 +23,7 @@ module LeapSalesforce
|
|
23
23
|
when 'boolean' then set('true')
|
24
24
|
when 'picklist' then set("#{class_name}::#{field['label'].to_class_name}.sample")
|
25
25
|
when 'reference'
|
26
|
-
return set(
|
26
|
+
return set(%{User.find(CreatedDate: "<#{0.days.ago}").id}) if field['name'] == 'OwnerId'
|
27
27
|
|
28
28
|
soql_obj = LeapSalesforce.soql_objects.find { |so| so.backend_name == field['relationshipName'] }&.reference
|
29
29
|
if soql_obj
|
@@ -34,8 +34,8 @@ module LeapSalesforce
|
|
34
34
|
def verify_oauth
|
35
35
|
unless LeapSalesforce.sfdx
|
36
36
|
LeapSalesforce.client_id = options[:client_id] || input_for('Client id (Customer Id)')
|
37
|
-
LeapSalesforce.client_secret = options[:client_secret] ||
|
38
|
-
LeapSalesforce.password = options[:password] ||
|
37
|
+
LeapSalesforce.client_secret = options[:client_secret] || $stdin.getpass('Client secret (Consumer Secret)')
|
38
|
+
LeapSalesforce.password = options[:password] || $stdin.getpass('Password (Recommendation is that 1 password' \
|
39
39
|
' be shared across all test users to be easier to manage):')
|
40
40
|
end
|
41
41
|
LeapSalesforce.api_user = ERB.new(options[:username] || input_for('Salesforce username. It is ideal to start with a System admin' \
|
@@ -50,7 +50,7 @@ module LeapSalesforce
|
|
50
50
|
' leap_salesforce testing repo'.colorize(:green)
|
51
51
|
verify_environment
|
52
52
|
verify_oauth
|
53
|
-
@user_key = options[:user_key] || input_for('Enter a key to refer to this user (This will be stored as a Symbol)')
|
53
|
+
@user_key = options[:user_key] || input_for('Enter a key to refer to this user (This will be stored as a Symbol)').delete(':')
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -8,11 +8,20 @@ require 'colorize'
|
|
8
8
|
module LeapSalesforce
|
9
9
|
# Generators for creating code
|
10
10
|
module Generator
|
11
|
+
# @param [String] filename Relative filename to this file
|
12
|
+
# @param [String] folder Folder where templates are stored (for external gems)
|
13
|
+
# @return [String] Location of template file
|
14
|
+
def template_loc(filename, folder: nil)
|
15
|
+
template_dir = folder || __dir__
|
16
|
+
File.join(template_dir, 'templates', filename)
|
17
|
+
end
|
18
|
+
|
11
19
|
# @param [String] filename Relative filename to this file
|
12
20
|
# @param [Binding] binding Binding object used for ERB variables
|
21
|
+
# @param [String] folder Folder where templates are stored (for external gems)
|
13
22
|
# @return [String] Interpreted file after calculating ERB for template file passed
|
14
|
-
def read_template(filename, binding)
|
15
|
-
ERB.new(File.read(
|
23
|
+
def read_template(filename, binding, folder: nil)
|
24
|
+
ERB.new(File.read(template_loc(filename, folder: folder))).result(binding)
|
16
25
|
end
|
17
26
|
|
18
27
|
# Generate file creating necessary folder if necessary
|
@@ -70,7 +70,7 @@ module LeapSalesforce
|
|
70
70
|
|
71
71
|
# Clean up files generated for all picklists
|
72
72
|
def cleanup_files_created
|
73
|
-
`rubocop -
|
73
|
+
`rubocop -A #{ENUM_FOLDER} --display-only-fail-level-offenses --enable-pending-cops`
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -62,8 +62,8 @@ module LeapSalesforce
|
|
62
62
|
generate_field_module
|
63
63
|
generate_factory
|
64
64
|
end
|
65
|
-
`rubocop -
|
66
|
-
`rubocop -
|
65
|
+
`rubocop -A #{SOQL_OBJECT_FOLDER} --enable-pending-cops`
|
66
|
+
`rubocop -A #{FACTORY_FOLDER} --enable-pending-cops`
|
67
67
|
end
|
68
68
|
|
69
69
|
private
|
@@ -17,7 +17,7 @@ module LeapSalesforce
|
|
17
17
|
@client_secret = ENV['client_secret']
|
18
18
|
@password = ENV['password']
|
19
19
|
@environment = nil
|
20
|
-
@logger = Logger.new
|
20
|
+
@logger = Logger.new $stdout
|
21
21
|
@sfdx = false
|
22
22
|
# @access_token = nil
|
23
23
|
@instance_url = nil
|
@@ -98,7 +98,7 @@ module LeapSalesforce
|
|
98
98
|
else
|
99
99
|
LeapSalesforce::Users.where(user)&.username
|
100
100
|
end
|
101
|
-
Soaspec::SpecLogger.info "Using user '#{@api_user}'"
|
101
|
+
Soaspec::SpecLogger.info "Using user '#{@api_user}' for API"
|
102
102
|
end
|
103
103
|
|
104
104
|
# @return [String] Salesforce username used to execute API tests. This can be changed during tests
|
@@ -128,6 +128,7 @@ module LeapSalesforce
|
|
128
128
|
attr_reader :soql_objects
|
129
129
|
# @return [Logger] Logger used by LeapSalesforce
|
130
130
|
attr_accessor :logger
|
131
|
+
|
131
132
|
# @return [Array] list_of_soql_objects Array describing Soql objects taken from .leap_salesforce.yml
|
132
133
|
def soql_objects=(list_of_soql_objects)
|
133
134
|
@soql_objects = list_of_soql_objects.collect do |soql_object_desc|
|
@@ -72,13 +72,13 @@ module SoqlGlobalObjectData
|
|
72
72
|
# @param [Hash] lookup Key value pair unique to Salesforce to query for
|
73
73
|
# @yield [id] Perform block for each id returned. The 'id' parameter in a block represents an id matching the query
|
74
74
|
# @return [Array] List of ids matching criteria. Only used if no block given
|
75
|
-
def ids_where(lookup = {})
|
75
|
+
def ids_where(lookup = {}, &block)
|
76
76
|
lookup[:limit] ||= nil # Don't limit results returned
|
77
77
|
SoqlHandler.new("Each Id where #{self}").use
|
78
78
|
results = soql.query soql.soql_id(lookup), wait: false
|
79
79
|
ids = results.ids
|
80
80
|
if block_given?
|
81
|
-
ids.each
|
81
|
+
ids.each(&block)
|
82
82
|
else
|
83
83
|
ids
|
84
84
|
end
|
@@ -98,4 +98,27 @@ module SoqlObjectDescribe
|
|
98
98
|
def field_names
|
99
99
|
fields.collect { |field| field['name'] }
|
100
100
|
end
|
101
|
+
|
102
|
+
# @return [Hash] List of accessors for an object and what they relate to
|
103
|
+
def accessors
|
104
|
+
return @attr_hash if @attr_hash
|
105
|
+
|
106
|
+
@attr_hash = {}
|
107
|
+
fields.each do |field|
|
108
|
+
@attr_hash[field['label'].unused_ruby_name.to_sym] = important_attributes_for(field)
|
109
|
+
end
|
110
|
+
@attr_hash
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
# @return [Hash] Important attributes for a field
|
116
|
+
def important_attributes_for(field)
|
117
|
+
important_attributes = { backend: field['name'],
|
118
|
+
label: field['label'],
|
119
|
+
type: field['type'] }
|
120
|
+
relationship_name = field['relationshipName']
|
121
|
+
important_attributes[:related_object] = relationship_name if relationship_name
|
122
|
+
important_attributes
|
123
|
+
end
|
101
124
|
end
|
@@ -85,11 +85,9 @@ module LeapSalesforce
|
|
85
85
|
private
|
86
86
|
|
87
87
|
# Execute block as admin user, raising error if User class is not defined
|
88
|
-
def admin_query_user
|
88
|
+
def admin_query_user(&block)
|
89
89
|
if defined? ::User
|
90
|
-
Users.execute_as_if_present key: :admin
|
91
|
-
yield
|
92
|
-
end
|
90
|
+
Users.execute_as_if_present key: :admin, &block
|
93
91
|
else
|
94
92
|
raise LeapSalesforce::SetupError, "'User' class must be defined " \
|
95
93
|
" to check presence of user in environment #{LeapSalesforce.environment}"
|
@@ -60,11 +60,11 @@ module LeapSalesforce
|
|
60
60
|
alias [] where
|
61
61
|
|
62
62
|
# Iterate through each user, narrowing on filter if provided
|
63
|
-
def each(filter = nil)
|
63
|
+
def each(filter = nil, &block)
|
64
64
|
if filter
|
65
|
-
where({**filter, all: true}).each
|
65
|
+
where({ **filter, all: true }).each(&block)
|
66
66
|
else
|
67
|
-
list.each
|
67
|
+
list.each(&block)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -92,11 +92,11 @@ module LeapSalesforce
|
|
92
92
|
# Execute block as user matching filter if that user is present
|
93
93
|
# If user is not present the current user will be used
|
94
94
|
# @return [Object] Result of block
|
95
|
-
def execute_as_if_present(user_filter)
|
95
|
+
def execute_as_if_present(user_filter, &block)
|
96
96
|
raise ArgumentError, 'Pass block to :execute_as_if_present method' unless block_given?
|
97
97
|
|
98
98
|
if any? user_filter
|
99
|
-
execute_as(user_filter)
|
99
|
+
execute_as(user_filter, &block)
|
100
100
|
else
|
101
101
|
LeapSalesforce.logger.warn "No user found user filter #{user_filter}, using '#{LeapSalesforce.api_user}'"
|
102
102
|
yield
|
data/lib/leap_salesforce.rb
CHANGED
@@ -74,7 +74,10 @@ module LeapSalesforce
|
|
74
74
|
require 'leap_salesforce/limits'
|
75
75
|
|
76
76
|
FileUtils.mkdir_p lib_folder unless Dir.exist? lib_folder
|
77
|
-
|
77
|
+
%w[factories metadata soql_data].each do |folder|
|
78
|
+
sub_folder = File.join(lib_folder, folder)
|
79
|
+
require_all sub_folder if Dir.exist? sub_folder
|
80
|
+
end
|
78
81
|
|
79
82
|
self.objects_to_verify = SoqlData.descendants if objects_to_verify.empty?
|
80
83
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IQA
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -99,16 +99,16 @@ dependencies:
|
|
99
99
|
name: activerecord
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - '='
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
104
|
+
version: '6.1'
|
105
105
|
type: :runtime
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - '='
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
111
|
+
version: '6.1'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: colorize
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|