leap_salesforce 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91e7d68b35916d600c053d7ec95f01bc26694eebf0bf176da4fa595b07506087
4
- data.tar.gz: c3466149eaef469e70359c88c6d3ea3e125adea0f6b1bffbcdf5415699088d98
3
+ metadata.gz: 13951c22ceafff2467ca471cb6fda3c9b7ab34dd707c7e23371be362aee3199d
4
+ data.tar.gz: 2285ff9c9b90f44da101c8b186646ae8e7d4a7ff83b16bcd04807f72f5432d3c
5
5
  SHA512:
6
- metadata.gz: c6daeecb2f063de6d7b615e16c9ab2931988c74404c53f5ef7d1ab5e79f21645ddcf6587bc377204c5f13314e97e8d6c70bcaaa63188668b5837fe728e1f530d
7
- data.tar.gz: 6afc1a7aa1b7d0574a6821adf1eb5844a91c394f96158e5f970c4f7ee67b986544c1cc42aeb0d92310399482ea8e66de672a994e6cbf5b2192690aed8ea6130a
6
+ metadata.gz: 6377865707517db0bc51c59bf8e2f7d17a7ceba3191c5cd9759dfbde7e904cd2471e4574c8e981a3a781dfa1f9bc487a0f414d3b8c94c6cd618d6b2145d0b752
7
+ data.tar.gz: a033b46017e9dbd28b743a38b97fcd5c16663a5f3addf07dd3039354101a6a610c501c4f004e6ba1357d465d0a5212fb48dac1de8e20787a1565ac612148c21a
data/.gitignore CHANGED
@@ -18,6 +18,7 @@ spec/support/
18
18
 
19
19
  # Here are folders related to testing this project in it's own CI
20
20
  config/credentials/
21
+ .env
21
22
 
22
23
  # rspec failure tracking
23
24
  .rspec_status
data/.leap_salesforce.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  environment: prod # This is irrelevant for sfdx auth which uses user/alias
2
2
  lib_folder: spec/support
3
3
  sfdx: false
4
+ # Example of settings for generating Java classes
5
+ # language: java
6
+ # soql_field_start_text: |
7
+ # package com.salesforce.test.pojo.soqlObjects;
4
8
  soql_objects:
5
9
  - Case
6
10
  - Contact
data/ChangeLog CHANGED
@@ -1,3 +1,9 @@
1
+ Version 1.4
2
+ * Ability to generate Java classes from metadata using the exe 'leap_salesforce create_soql_objects --language=java'
3
+
4
+ Version 1.3.1
5
+ * Require facets so that `snakecase` method ensured to work
6
+
1
7
  Version 1.3.0
2
8
  * Updated sfdx commands to use new terms, not deprecated ones
3
9
 
data/README.md CHANGED
@@ -104,6 +104,8 @@ Credentials are not stored in stored in source control. They can be setting thro
104
104
  * 'client_secret'
105
105
  * 'password'
106
106
 
107
+ > If these variables can be set in a `.env` file they will be loaded automatically
108
+
107
109
  > Security tokens can be set for each user (adding to password in OAuth like in [this article](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm))
108
110
  > To do that set an environment variable as USER_KEY_token. E.g, so for a user with a key of :admin
109
111
  > the token would be set with the `admin_token` environment variable
@@ -174,6 +176,19 @@ custom object.
174
176
  A separate file with the ending `_field_names` is also created from the metadata for each object. This creates
175
177
  accessors for each field in the table with names that map from a Ruby friendly name to the Salesforce backend name.
176
178
 
179
+ A java class can be created using the following syntax in `.leap_salesforce.yml`. The default language will be Ruby
180
+
181
+ ```yaml
182
+ language: java
183
+ lib_folder: main/java # Path to store auto generated Java classes
184
+ soql_field_start_text: |
185
+ package com.salesforce.test.pojo.soqlObjects;
186
+ ```
187
+
188
+ These task can also be executed from the executable of this project with `leap_salesforce create_soql_objects --language=ruby`
189
+
190
+ For generation of other languages, raise an issue
191
+
177
192
  * `leaps:create_enums`
178
193
 
179
194
  This task reads the soql objects defined in `.leap_salesforce.yml` and creates a `metadata/enum` folder that has
data/Rakefile CHANGED
@@ -7,6 +7,8 @@ require 'rake/clean'
7
7
  require 'yard'
8
8
  require 'yard/doctest/rake'
9
9
 
10
+ require 'dotenv'
11
+ Dotenv.load
10
12
  require 'leap_salesforce/rake' # TODO: Append this line to existing repo
11
13
 
12
14
  CLEAN.include 'tmp/*'
data/exe/leap_salesforce CHANGED
@@ -4,6 +4,8 @@
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
5
 
6
6
  require 'thor'
7
+ require 'dotenv'
8
+ Dotenv.load
7
9
  require 'leap_salesforce/parameters'
8
10
  require 'leap_salesforce/generator/generator'
9
11
  require 'leap_salesforce/error'
@@ -58,6 +60,17 @@ module LeapSalesforce
58
60
  puts 'Your .gitignore is already present so not updated.
59
61
  Please ignore "config/credentials/" and "logs/"'.colorize :red
60
62
  end
63
+
64
+ desc 'create_soql_objects', 'Creates SOQL objects from metadata based on .leap_salesforce.yml'
65
+ option :language, default: 'ruby'
66
+ def create_soql_objects
67
+ LeapSalesforce.language = options[:language]
68
+ require 'leap_salesforce/generator/soql_objects'
69
+ LeapSalesforce.oauth_working?
70
+ LeapSalesforce::Users.execute_as_if_present key: :admin do
71
+ LeapSalesforce::Generator::SoqlObjects.new.create_all
72
+ end
73
+ end
61
74
  end
62
75
  end
63
76
 
@@ -26,7 +26,7 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_development_dependency 'bundler', '~> 2.0'
29
+ spec.add_development_dependency 'bundler'
30
30
  spec.add_development_dependency 'parallel'
31
31
  spec.add_development_dependency 'pry'
32
32
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -35,6 +35,8 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
35
35
  spec.add_development_dependency 'yard-doctest'
36
36
  spec.add_dependency 'activerecord', '7'
37
37
  spec.add_dependency 'colorize'
38
+ spec.add_dependency 'dotenv'
39
+ spec.add_dependency 'facets'
38
40
  spec.add_dependency 'factory_bot'
39
41
  spec.add_dependency 'faker', '>= 2.0'
40
42
  spec.add_dependency 'humanize'
@@ -92,6 +92,12 @@ class String
92
92
  name.keyword? ? "my_#{name}" : name
93
93
  end
94
94
 
95
+ # @return [String] Camel case string that is not taken by keywords like 'class', 'alias'
96
+ # @param [Symbol] type :upper or :lower, default :upper
97
+ def unused_camel_name(type = :upper)
98
+ unused_ruby_name.camelize(type)
99
+ end
100
+
95
101
  # @return [String] Zulu time stamp for string
96
102
  def to_zulu_date_string
97
103
  Time.parse(self).strftime('%Y-%m-%dT%H:%M:%S.000Z')
@@ -12,7 +12,8 @@ module LeapSalesforce
12
12
  class SoqlObjects
13
13
  include Generator
14
14
 
15
- SOQL_OBJECT_FOLDER = File.join(LeapSalesforce.lib_folder, 'soql_data').freeze
15
+ SOQL_DATA_FOLDER = LeapSalesforce.language == "java" ? 'SoqlObjects' : 'soql_data'
16
+ SOQL_OBJECT_FOLDER = File.join(LeapSalesforce.lib_folder, SOQL_DATA_FOLDER).freeze
16
17
  FACTORY_FOLDER = File.join(LeapSalesforce.lib_folder, 'factories').freeze
17
18
 
18
19
  # Create temporary class for building API requests on
@@ -31,6 +32,7 @@ module LeapSalesforce
31
32
  raise LeapSalesforce::SetupError, "Error producing Soql data for '#{@soql_class}', soql table " \
32
33
  " '#{@soql_object.backend_name}'. Error message: '#{desc.error_message}'"
33
34
  end
35
+ return unless LeapSalesforce.language == "ruby"
34
36
  content = read_template 'soql_object.rb.erb', binding
35
37
  file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.reference}.rb")
36
38
  generate_file file, content, overwrite: false
@@ -38,13 +40,21 @@ module LeapSalesforce
38
40
 
39
41
  # Generate module with fields for Soql Object
40
42
  def generate_field_module
41
- field_content = read_template 'soql_object_field_names.rb.erb', binding
42
- field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb")
43
- generate_file field_file, field_content
43
+ if LeapSalesforce.language == "ruby"
44
+ field_content = read_template 'soql_object_field_names.rb.erb', binding
45
+ field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb")
46
+ elsif LeapSalesforce.language == "java"
47
+ field_content = read_template 'soql_object_field_names.Java.erb', binding
48
+ field_file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.class_name}.Java")
49
+ else
50
+ raise LeapSalesforce::SetupError, "Unsupported language '#{LeapSalesforce.language}'"
51
+ end
52
+ generate_file field_file, field_content
44
53
  end
45
54
 
46
55
  # Generate factory for mass generating objects using FactoryBot
47
56
  def generate_factory
57
+ return unless LeapSalesforce.language == "ruby"
48
58
  @default_fields, @other_fields = filter_fields
49
59
  content = read_template 'factory.rb.erb', binding
50
60
  file = File.join(FACTORY_FOLDER, "#{@soql_object.reference}.rb")
@@ -62,8 +72,10 @@ module LeapSalesforce
62
72
  generate_field_module
63
73
  generate_factory
64
74
  end
65
- `rubocop -A #{SOQL_OBJECT_FOLDER} --enable-pending-cops`
66
- `rubocop -A #{FACTORY_FOLDER} --enable-pending-cops`
75
+ if LeapSalesforce.language == 'ruby'
76
+ `rubocop -A #{SOQL_OBJECT_FOLDER} --enable-pending-cops`
77
+ `rubocop -A #{FACTORY_FOLDER} --enable-pending-cops`
78
+ end
67
79
  end
68
80
 
69
81
  private
@@ -0,0 +1,22 @@
1
+ <%= LeapSalesforce.soql_field_start_text %>
2
+ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
3
+ import com.fasterxml.jackson.annotation.JsonProperty;
4
+
5
+ /**
6
+ * Auto-generated code created by leap_salesforce. Do not manually
7
+ * update as this can be overwritten when `leap_salesforce create_soql_objects` is run
8
+ */
9
+ @JsonIgnoreProperties(ignoreUnknown=true)
10
+ public class <%= @soql_object.class_name %> {
11
+
12
+ <% @soql_class.fields.each do |field| %>
13
+ @JsonProperty(value="<%= field['name'] %>")
14
+ String <%= field['name'].camelize(:lower) %>;
15
+ <% end %>
16
+
17
+ <% @soql_class.fields.each do |field| %>
18
+ public String get<%= field['label'].unused_camel_name %>() { return <%= field['name'].camelize(:lower) %>; }
19
+ public void set<%= field['label'].unused_camel_name %>(String <%= field['name'].camelize(:lower) %>) { this.<%= field['name'].camelize(:lower) %> = <%= field['name'].camelize(:lower) %>; }
20
+ <% end %>
21
+ }
22
+
@@ -16,6 +16,8 @@ module LeapSalesforce
16
16
  @client_id = ENV['client_id']
17
17
  @client_secret = ENV['client_secret']
18
18
  @password = ENV['password']
19
+ @language = "ruby"
20
+ @soql_field_start_text = ""
19
21
  @environment = nil
20
22
  @logger = Logger.new $stdout
21
23
  @sfdx = false
@@ -130,6 +132,13 @@ module LeapSalesforce
130
132
  # @return [Logger] Logger used by LeapSalesforce
131
133
  attr_accessor :logger
132
134
 
135
+ # @return [Symbol] Name of the language used
136
+ attr_accessor :language
137
+
138
+ # @return [String] Text to be added as start of auto generated Soql field names
139
+ # classes in the Salesforce object
140
+ attr_accessor :soql_field_start_text
141
+
133
142
  # @return [Array] list_of_soql_objects Array describing Soql objects taken from .leap_salesforce.yml
134
143
  def soql_objects=(list_of_soql_objects)
135
144
  @soql_objects = list_of_soql_objects.collect do |soql_object_desc|
@@ -2,5 +2,5 @@
2
2
 
3
3
  module LeapSalesforce
4
4
  # @return [String] Version of leap salesforce
5
- VERSION = '1.3.0'
5
+ VERSION = '1.4.0'
6
6
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'leap_salesforce/version'
4
4
 
5
+ require 'facets/string/snakecase'
5
6
  require 'soaspec'
6
7
  Soaspec::OAuth2.refresh_token = :once # Save access token and reuse it
7
8
  Soaspec.log_warnings = false # Log any API warnings
@@ -20,6 +21,8 @@ require 'faker' # For fake data
20
21
  require 'leap_salesforce/error'
21
22
  require 'leap_salesforce/loader'
22
23
  require 'leap_salesforce/session'
24
+ require 'dotenv'
25
+ Dotenv.load
23
26
 
24
27
  # If variable is present within LeapSalesforce set it
25
28
  def load_variables_from(file)
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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-07-19 00:00:00.000000000 Z
12
+ date: 2024-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '2.0'
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '2.0'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: parallel
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +137,34 @@ dependencies:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: dotenv
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :runtime
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: facets
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
140
168
  - !ruby/object:Gem::Dependency
141
169
  name: factory_bot
142
170
  requirement: !ruby/object:Gem::Requirement
@@ -332,6 +360,7 @@ files:
332
360
  - lib/leap_salesforce/generator/templates/factory.rb.erb
333
361
  - lib/leap_salesforce/generator/templates/picklist.rb.erb
334
362
  - lib/leap_salesforce/generator/templates/soql_object.rb.erb
363
+ - lib/leap_salesforce/generator/templates/soql_object_field_names.Java.erb
335
364
  - lib/leap_salesforce/generator/templates/soql_object_field_names.rb.erb
336
365
  - lib/leap_salesforce/generator/templates/spec/crud_eg_spec.rb.erb
337
366
  - lib/leap_salesforce/generator/templates/spec/limit_spec.rb.erb
@@ -385,7 +414,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
414
  - !ruby/object:Gem::Version
386
415
  version: '0'
387
416
  requirements: []
388
- rubygems_version: 3.5.3
417
+ rubygems_version: 3.2.3
389
418
  signing_key:
390
419
  specification_version: 4
391
420
  summary: Helps with setting up integrated automated test frameworks against Salesforce.