bima-shark-sdk 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +56 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG.md +131 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +53 -0
  10. data/Rakefile +8 -0
  11. data/bima-shark-sdk.gemspec +36 -0
  12. data/bin/console +24 -0
  13. data/bin/setup +8 -0
  14. data/lib/bima-shark-sdk/rspec.rb +38 -0
  15. data/lib/bima-shark-sdk.rb +3 -0
  16. data/lib/shark/account.rb +7 -0
  17. data/lib/shark/activity.rb +11 -0
  18. data/lib/shark/asset.rb +13 -0
  19. data/lib/shark/base.rb +36 -0
  20. data/lib/shark/client/connection.rb +67 -0
  21. data/lib/shark/concerns/connected.rb +44 -0
  22. data/lib/shark/concerns/normalized_email.rb +13 -0
  23. data/lib/shark/configuration.rb +90 -0
  24. data/lib/shark/consent.rb +31 -0
  25. data/lib/shark/contact.rb +40 -0
  26. data/lib/shark/contact_log.rb +7 -0
  27. data/lib/shark/double_opt_in/execution.rb +50 -0
  28. data/lib/shark/double_opt_in/request.rb +45 -0
  29. data/lib/shark/error.rb +69 -0
  30. data/lib/shark/form_service/base.rb +11 -0
  31. data/lib/shark/form_service/form/container.rb +10 -0
  32. data/lib/shark/form_service/form/element.rb +83 -0
  33. data/lib/shark/form_service/form/multiple_choice.rb +21 -0
  34. data/lib/shark/form_service/form/rating_scale.rb +20 -0
  35. data/lib/shark/form_service/form/rating_star.rb +13 -0
  36. data/lib/shark/form_service/form/structure.rb +13 -0
  37. data/lib/shark/form_service/form/text_area.rb +10 -0
  38. data/lib/shark/form_service/form/text_field.rb +17 -0
  39. data/lib/shark/form_service/v2/base.rb +13 -0
  40. data/lib/shark/form_service/v2/form.rb +18 -0
  41. data/lib/shark/form_service/v2/form_input.rb +15 -0
  42. data/lib/shark/form_service/v2/form_version.rb +19 -0
  43. data/lib/shark/form_service.rb +21 -0
  44. data/lib/shark/group.rb +18 -0
  45. data/lib/shark/mailing_service/base.rb +11 -0
  46. data/lib/shark/mailing_service/configuration.rb +9 -0
  47. data/lib/shark/mailing_service/mail.rb +8 -0
  48. data/lib/shark/mailing_service/mailers/base_mailer.rb +96 -0
  49. data/lib/shark/mailing_service/renderers/context.rb +40 -0
  50. data/lib/shark/mailing_service/renderers/erb_renderer.rb +46 -0
  51. data/lib/shark/mailing_service.rb +23 -0
  52. data/lib/shark/membership.rb +16 -0
  53. data/lib/shark/middleware/compose_request.rb +41 -0
  54. data/lib/shark/middleware/status.rb +36 -0
  55. data/lib/shark/notification.rb +21 -0
  56. data/lib/shark/package.rb +7 -0
  57. data/lib/shark/permission.rb +7 -0
  58. data/lib/shark/rails.rb +13 -0
  59. data/lib/shark/rspec/fake_asset_service/object_cache.rb +76 -0
  60. data/lib/shark/rspec/fake_asset_service/public_id.rb +21 -0
  61. data/lib/shark/rspec/fake_asset_service/request.rb +154 -0
  62. data/lib/shark/rspec/fake_asset_service.rb +20 -0
  63. data/lib/shark/rspec/fake_consent_service/object_cache.rb +44 -0
  64. data/lib/shark/rspec/fake_consent_service/request.rb +53 -0
  65. data/lib/shark/rspec/fake_consent_service.rb +19 -0
  66. data/lib/shark/rspec/fake_contact_service/object_cache.rb +88 -0
  67. data/lib/shark/rspec/fake_contact_service/request.rb +170 -0
  68. data/lib/shark/rspec/fake_contact_service.rb +19 -0
  69. data/lib/shark/rspec/fake_double_opt_in/object_cache.rb +59 -0
  70. data/lib/shark/rspec/fake_double_opt_in/request.rb +133 -0
  71. data/lib/shark/rspec/fake_double_opt_in.rb +19 -0
  72. data/lib/shark/rspec/fake_mailing_service/request.rb +41 -0
  73. data/lib/shark/rspec/fake_mailing_service.rb +13 -0
  74. data/lib/shark/rspec/fake_notification_service/request.rb +53 -0
  75. data/lib/shark/rspec/fake_notification_service.rb +13 -0
  76. data/lib/shark/rspec/fake_subscription_service/object_cache.rb +54 -0
  77. data/lib/shark/rspec/fake_subscription_service/request.rb +100 -0
  78. data/lib/shark/rspec/fake_subscription_service.rb +19 -0
  79. data/lib/shark/rspec/fake_survey_service/object_cache.rb +36 -0
  80. data/lib/shark/rspec/fake_survey_service/request.rb +66 -0
  81. data/lib/shark/rspec/fake_survey_service.rb +19 -0
  82. data/lib/shark/rspec/fixtures/form_inputs.json +26 -0
  83. data/lib/shark/rspec/fixtures/form_structure.json +175 -0
  84. data/lib/shark/rspec/helpers/cache_helper.rb +44 -0
  85. data/lib/shark/rspec/helpers/fixtures.rb +26 -0
  86. data/lib/shark/rspec/helpers/form_service_helper.rb +27 -0
  87. data/lib/shark/rspec/helpers/response.rb +25 -0
  88. data/lib/shark/rspec/helpers.rb +26 -0
  89. data/lib/shark/subscription.rb +43 -0
  90. data/lib/shark/survey.rb +29 -0
  91. data/lib/shark/survey_participant.rb +37 -0
  92. data/lib/shark/version.rb +5 -0
  93. data/lib/shark.rb +91 -0
  94. metadata +291 -0
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webmock/rspec'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeConsentService
8
+ class Request
9
+ include Singleton
10
+
11
+ def self.setup
12
+ instance = self.instance
13
+ instance.stub_requests
14
+ end
15
+
16
+ def stub_requests
17
+ WebMock.stub_request(:post, %r{^#{host}/consents}).to_return do |request|
18
+ log_info "[Shark][ConsentService] Faking POST request with body: #{request.body}"
19
+
20
+ payload_data = JSON.parse(request.body)['data']
21
+ object_data = ObjectCache.instance.add(payload_data)
22
+
23
+ SharkSpec.fake_response(200, data: object_data)
24
+ end
25
+
26
+ WebMock.stub_request(:get, %r{^#{host}/consents/.+}).to_return do |request|
27
+ log_info '[Shark][ConsentService] Faking GET request'
28
+
29
+ id = request.uri.path.split('/')[2]
30
+
31
+ object_data = ObjectCache.instance.objects.detect do |object|
32
+ object['id'] == id
33
+ end
34
+
35
+ if object_data.present?
36
+ SharkSpec.fake_response(200, data: object_data)
37
+ else
38
+ SharkSpec.fake_response(404, errors: [])
39
+ end
40
+ end
41
+ end
42
+
43
+ def host
44
+ Shark.configuration.consent_service.site
45
+ end
46
+
47
+ def log_info(message)
48
+ Shark.logger.info message
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fake_consent_service/object_cache'
4
+ require_relative 'fake_consent_service/request'
5
+
6
+ module Shark
7
+ module RSpec
8
+ module FakeConsentService
9
+ def self.setup
10
+ ObjectCache.clear
11
+ Request.setup
12
+ end
13
+
14
+ def self.reset
15
+ ObjectCache.clear
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shark
4
+ module RSpec
5
+ module FakeContactService
6
+ class ObjectCache
7
+ include Singleton
8
+ include Helpers::CacheHelper
9
+
10
+ attr_accessor :objects
11
+
12
+ def initialize
13
+ @objects = []
14
+ end
15
+
16
+ def self.clear
17
+ instance.objects = []
18
+ end
19
+
20
+ def add(object)
21
+ unless object['attributes'].keys.include?('avatar_url')
22
+ avatar_url = "https://contactservice/path/to/avatar/#{object['id']}.png"
23
+ object['attributes']['avatar_url'] = avatar_url
24
+ end
25
+
26
+ objects.push(object)
27
+
28
+ object
29
+ end
30
+
31
+ def objects_contain(type, params)
32
+ filtered_objects = []
33
+ filter = params['filter']
34
+
35
+ if filter['contact_id']
36
+ filtered_objects = objects.select do |object|
37
+ return false unless object['type'] == type
38
+
39
+ ids = (object['attributes']['contact_ids'] || []).map(&:to_s)
40
+ ids.include?(filter.values.first)
41
+ end
42
+ end
43
+ filtered_objects
44
+ end
45
+
46
+ def search_objects(type, params)
47
+ filtered_objects = []
48
+ filters = params['filter'] && params['filter']['filter']
49
+ condition, filter = filters.first
50
+
51
+ if condition.present? && filter.present?
52
+ filtered_objects = objects.select do |object|
53
+ return false unless object['type'] == type
54
+
55
+ attribute_key, value = filter.first
56
+ attribute = object['attributes'][attribute_key]
57
+
58
+ case condition
59
+ when 'contains_word_prefixes'
60
+ attribute.to_s.start_with?(value)
61
+ when 'contains_words'
62
+ words = case value
63
+ when Array
64
+ value
65
+ when Hash
66
+ value.keys
67
+ # else
68
+ # value.split(",").map(&:strip)
69
+ end
70
+ words.include?(attribute.to_s)
71
+ when 'equals'
72
+ attribute.to_s == value
73
+ when 'is_blank'
74
+ attribute.blank?
75
+ when 'is_true'
76
+ attribute == true
77
+ else
78
+ false
79
+ end
80
+ end
81
+ end
82
+
83
+ filtered_objects
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webmock/rspec'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeContactService
8
+ class Request
9
+ include Singleton
10
+
11
+ def self.setup
12
+ instance = self.instance
13
+ instance.stub_requests
14
+ end
15
+
16
+ def stub_requests
17
+ cache = FakeContactService::ObjectCache.instance
18
+
19
+ WebMock.stub_request(:post, %r{^#{host}/.*}).to_return do |request|
20
+ log_info "[Shark][ContactService] Faking POST request with body: #{request.body}"
21
+ log_info request.uri.to_s
22
+
23
+ id = SecureRandom.uuid
24
+ parsed_data = JSON.parse(request.body)['data']
25
+ parsed_data['id'] = id
26
+
27
+ cache.add(parsed_data)
28
+ SharkSpec.fake_response(201, data: parsed_data)
29
+ end
30
+
31
+ WebMock.stub_request(:get, %r{^#{host}/.*$}).to_return do |request|
32
+ log_info '[Shark][ContactService] Faking GET request'
33
+ log_info request.uri.to_s
34
+
35
+ type = request.uri.path.split('/')[2]
36
+ params = query_params_to_object(request.uri)
37
+
38
+ objects = if %w[contacts accounts].include?(type) && params['filter'].present?
39
+ cache.search_objects(type, params)
40
+ elsif %w[activities].include?(type) && params['filter'].present?
41
+ cache.objects_contain(type, params)
42
+ else
43
+ cache.objects.select do |object|
44
+ object['type'] == type
45
+ end
46
+ end
47
+
48
+ SharkSpec.fake_response(200, data: objects)
49
+ end
50
+
51
+ WebMock.stub_request(:get, %r{^#{host}/.+/.+}).to_return do |request|
52
+ log_info '[Shark][ContactService] Faking GET request with ID'
53
+ log_info request.uri.to_s
54
+
55
+ type = request.uri.path.split('/')[2]
56
+ id = request.uri.path.split('/')[3]
57
+ query = request.uri.query_values
58
+
59
+ object = cache.find(type, id)
60
+
61
+ if object.present?
62
+ body = { data: object }
63
+
64
+ if query && query['include']
65
+ relation_name = query['include']
66
+ included_objects = cache.included_resources(object, query)
67
+
68
+ if included_objects.empty?
69
+ object['relationships'] ||= { relation_name => { data: [] } }
70
+ end
71
+ body = {
72
+ data: object,
73
+ included: included_objects
74
+ }
75
+ end
76
+
77
+ SharkSpec.fake_response(200, body)
78
+ else
79
+ SharkSpec.fake_response(404, errors: [])
80
+ end
81
+ end
82
+
83
+ WebMock.stub_request(:get, %r{^#{host}/groups/.+/memberships}).to_return do |request|
84
+ log_info '[Shark][ContactService] Faking GET memberships request'
85
+ log_info request.uri.to_s
86
+
87
+ type = request.uri.path.split('/')[2]
88
+ group_id = request.uri.path.split('/')[3]
89
+ contact_id = query_params_to_object(request.uri)['filter']['contact_id']
90
+
91
+ group = cache.find(type, group_id)
92
+
93
+ if group.present?
94
+ contacts = group.dig('relationships', 'contacts', 'data')
95
+
96
+ if contacts.present?
97
+ if contacts.detect { |c| c['type'] == 'contacts' && c['id'] == contact_id }
98
+ next SharkSpec.fake_response(200, {})
99
+ end
100
+ end
101
+ end
102
+
103
+ SharkSpec.fake_response(404, errors: [])
104
+ end
105
+
106
+ WebMock.stub_request(:patch, %r{^#{host}/.*/.+}).to_return do |request|
107
+ log_info "[Shark][ContactService] Faking PATCH request with body: #{request.body}"
108
+ log_info request.uri.to_s
109
+
110
+ type = request.uri.path.split('/')[2]
111
+ id = request.uri.path.split('/')[3]
112
+ parsed_data = JSON.parse(request.body)['data']
113
+
114
+ object = cache.find(type, id)
115
+
116
+ if object.present?
117
+ (parsed_data['attributes'] || {}).each do |key, value|
118
+ object['attributes'] = {} if object['attributes'].blank?
119
+ object['attributes'][key] = value
120
+ end
121
+
122
+ (parsed_data['relationships'] || {}).each do |key, value|
123
+ object['relationships'] = {} if object['relationships'].blank?
124
+ object['relationships'][key] = value
125
+ end
126
+
127
+ SharkSpec.fake_response(200, data: object)
128
+ else
129
+ SharkSpec.fake_response(404, errors: [])
130
+ end
131
+ end
132
+
133
+ WebMock.stub_request(:delete, %r{^#{host}/.*/.+}).to_return do |request|
134
+ log_info '[Shark][ContactService] Faking DELETE request'
135
+ log_info request.uri.to_s
136
+
137
+ type = request.uri.path.split('/')[2]
138
+ id = request.uri.path.split('/')[3]
139
+
140
+ object = cache.find(type, id)
141
+
142
+ if object.present?
143
+ cache.objects.delete(object)
144
+
145
+ SharkSpec.fake_response(204, nil)
146
+ else
147
+ SharkSpec.fake_response(404, errors: [])
148
+ end
149
+ end
150
+ end
151
+
152
+ def host
153
+ Shark.configuration.contact_service.site
154
+ end
155
+
156
+ def log_info(message)
157
+ Shark.logger.info message
158
+ end
159
+
160
+ def query_params_to_object(request_uri)
161
+ uri = URI.parse(request_uri)
162
+ return {} if uri.query.blank?
163
+
164
+ query = uri.query.gsub(/%5B[0-9]%5D/, '%5B%5D')
165
+ Rack::Utils.parse_nested_query(query)
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fake_contact_service/object_cache'
4
+ require_relative 'fake_contact_service/request'
5
+
6
+ module Shark
7
+ module RSpec
8
+ module FakeContactService
9
+ def self.setup
10
+ ObjectCache.clear
11
+ Request.setup
12
+ end
13
+
14
+ def self.reset
15
+ ObjectCache.clear
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shark
4
+ module RSpec
5
+ module FakeDoubleOptIn
6
+ class ObjectCache
7
+ include Singleton
8
+ attr_accessor :objects
9
+
10
+ def initialize
11
+ @objects = {}
12
+ end
13
+
14
+ def self.clear
15
+ instance.objects = {}
16
+ end
17
+
18
+ def add_execution(attributes)
19
+ verification_token = SecureRandom.uuid
20
+
21
+ objects[verification_token] = {
22
+ 'id' => verification_token,
23
+ 'attributes' => attributes,
24
+ 'type' => 'executions'
25
+ }
26
+
27
+ objects[verification_token]
28
+ end
29
+
30
+ def find_execution(verification_token)
31
+ objects[verification_token]
32
+ end
33
+
34
+ def remove_execution(verification_token)
35
+ objects.delete(verification_token)
36
+ end
37
+
38
+ def create_request(attributes)
39
+ timeout = attributes['timeout'] || 3600
40
+ leeway_to_terminate = attributes['leeway_to_terminate'] || 3600
41
+
42
+ verification_expires_at = Time.now.to_i + timeout.to_i
43
+ execution_expires_at = verification_expires_at + leeway_to_terminate.to_i
44
+
45
+ add_execution({
46
+ 'payload' => attributes['payload'],
47
+ 'request_type' => attributes['request_type'],
48
+ 'max_verifications' => attributes['max_verifications'] || 10,
49
+ 'verifications_count' => 0,
50
+ 'verification_expires_at' => verification_expires_at,
51
+ 'execution_expires_at' => execution_expires_at
52
+ })
53
+
54
+ attributes
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webmock/rspec'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeDoubleOptIn
8
+ class Request
9
+ include Singleton
10
+
11
+ def self.setup
12
+ instance = self.instance
13
+ instance.stub_requests
14
+ end
15
+
16
+ def stub_requests
17
+ WebMock.stub_request(:post, %r{^#{host}/requests}).to_return do |request|
18
+ log_info "Faking POST request with body: #{request.body}"
19
+
20
+ data = JSON.parse(request.body)['data']
21
+ attributes = data['attributes'] || {}
22
+
23
+ ObjectCache.instance.create_request(attributes)
24
+
25
+ fake_response(200, {
26
+ data: {
27
+ id: SecureRandom.uuid,
28
+ attributes: attributes,
29
+ type: 'requests'
30
+ }
31
+ })
32
+ end
33
+
34
+ WebMock.stub_request(:post, %r{^#{host}/executions/.+/verify}).to_return do |request|
35
+ log_info 'Faking POST request'
36
+
37
+ verification_token = request.uri.path.split('/').reverse[1]
38
+ object = ObjectCache.instance.find_execution(verification_token)
39
+
40
+ if verification_token_invalid?(object)
41
+ fake_response(404, { errors: [] })
42
+ else
43
+ verification_expires_at = object['attributes']['verification_expires_at']
44
+ max_verifications = object['attributes']['max_verifications']
45
+ verifications_count = object['attributes']['verifications_count']
46
+
47
+ is_verification_expired = Time.now.to_i > verification_expires_at
48
+ is_number_of_requests_exceeded = max_verifications <= verifications_count
49
+
50
+ if is_verification_expired
51
+ errors = [{ code: 'verification_expired' }]
52
+ fake_response(422, { errors: errors })
53
+ elsif is_number_of_requests_exceeded
54
+ errors = [{ code: 'exceeded_number_of_verification_requests' }]
55
+ fake_response(422, { errors: errors })
56
+ else
57
+ fake_response(200, { data: object })
58
+ end
59
+ end
60
+ end
61
+
62
+ WebMock.stub_request(:get, %r{^#{host}/executions/.+}).to_return do |request|
63
+ log_info 'Faking GET request'
64
+
65
+ verification_token = request.uri.path.split('/').reverse[0]
66
+ object = ObjectCache.instance.find_execution(verification_token)
67
+
68
+ if verification_token_invalid?(object)
69
+ fake_response(404, { errors: [] })
70
+ else
71
+ attributes = object['attributes']
72
+
73
+ if attributes['verifications_count'].zero?
74
+ fake_response(422, { errors: [{ code: 'requested_unverified_execution' }] })
75
+ else
76
+ fake_response(200, { data: object })
77
+ end
78
+ end
79
+ end
80
+
81
+ WebMock.stub_request(:delete, %r{^#{host}/executions/.+}).to_return do |request|
82
+ log_info 'Faking DELETE request'
83
+
84
+ verification_token = request.uri.path.split('/').reverse[0]
85
+ object = ObjectCache.instance.find_execution(verification_token)
86
+
87
+ if verification_token_invalid?(object)
88
+ fake_response(404, { errors: [] })
89
+ else
90
+ ObjectCache.instance.remove_execution(verification_token)
91
+ fake_response(200, { data: object })
92
+ end
93
+ end
94
+ end
95
+
96
+ def verification_token_invalid?(object)
97
+ return true if object.blank?
98
+
99
+ execution_expires_at = object['attributes']['execution_expires_at']
100
+ verification_expires_at = object['attributes']['verification_expires_at']
101
+ verifications_count = object['attributes']['verifications_count']
102
+
103
+ is_execution_time_expired = Time.now.to_i > execution_expires_at
104
+ is_verification_expired = Time.now.to_i > verification_expires_at
105
+ has_verification_been_verified = verifications_count.positive?
106
+
107
+ return true if is_execution_time_expired
108
+ return true if is_verification_expired && !has_verification_been_verified
109
+
110
+ false
111
+ end
112
+
113
+ def fake_response(status, body)
114
+ {
115
+ headers: {
116
+ content_type: 'application/vnd.api+json'
117
+ },
118
+ status: status,
119
+ body: body.is_a?(String) ? body : body.to_json
120
+ }
121
+ end
122
+
123
+ def host
124
+ Shark.configuration.double_opt_in.site
125
+ end
126
+
127
+ def log_info(message)
128
+ Shark.logger.info "[Shark][DoubleOptInService] #{message}"
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fake_double_opt_in/object_cache'
4
+ require_relative 'fake_double_opt_in/request'
5
+
6
+ module Shark
7
+ module RSpec
8
+ module FakeDoubleOptIn
9
+ def self.setup
10
+ ObjectCache.clear
11
+ Request.setup
12
+ end
13
+
14
+ def self.reset
15
+ ObjectCache.clear
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webmock/rspec'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeMailingService
8
+ class Request
9
+ include Singleton
10
+
11
+ def self.setup
12
+ instance = self.instance
13
+ instance.stub_requests
14
+ end
15
+
16
+ def stub_requests
17
+ WebMock.stub_request(:post, %r{^#{host}/mails}).to_return do |request|
18
+ log_info "[Shark][MailingService] Faking POST request with body: #{request.body}"
19
+
20
+ id = SecureRandom.uuid
21
+ payload_data = JSON.parse(request.body)['data']
22
+
23
+ SharkSpec.fake_response(201, data: {
24
+ type: 'mails',
25
+ id: id,
26
+ attributes: payload_data
27
+ })
28
+ end
29
+ end
30
+
31
+ def host
32
+ Shark.configuration.mailing_service.site
33
+ end
34
+
35
+ def log_info(message)
36
+ message
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fake_mailing_service/request'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeMailingService
8
+ def self.setup
9
+ Request.setup
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webmock/rspec'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeNotificationService
8
+ class Request
9
+ include Singleton
10
+
11
+ def self.setup
12
+ instance = self.instance
13
+ instance.stub_requests
14
+ end
15
+
16
+ def stub_requests
17
+ WebMock.stub_request(
18
+ :post,
19
+ %r{^#{host}/notifications/bulk_creation}
20
+ ).to_return do |request|
21
+ log_info "Faking POST bulk creation request with body: #{request.body}"
22
+
23
+ SharkSpec.fake_response(201, data: {
24
+ type: 'notifications',
25
+ id: '12345678-1234-1234-1234-1234567890ab'
26
+ })
27
+ end
28
+
29
+ WebMock.stub_request(:post, %r{^#{host}/notifications}).to_return do |request|
30
+ log_info "Faking POST request with body: #{request.body}"
31
+
32
+ id = SecureRandom.uuid
33
+ payload_data = JSON.parse(request.body)['data']
34
+
35
+ SharkSpec.fake_response(201, data: {
36
+ type: 'notifications',
37
+ id: id,
38
+ attributes: payload_data
39
+ })
40
+ end
41
+ end
42
+
43
+ def host
44
+ Shark.configuration.notification_service.site
45
+ end
46
+
47
+ def log_info(message)
48
+ Shark.logger.info "[Shark][NotificationService] #{message}"
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fake_notification_service/request'
4
+
5
+ module Shark
6
+ module RSpec
7
+ module FakeNotificationService
8
+ def self.setup
9
+ Request.setup
10
+ end
11
+ end
12
+ end
13
+ end