bima-shark-sdk 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.rubocop.yml +56 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +131 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +8 -0
- data/bima-shark-sdk.gemspec +36 -0
- data/bin/console +24 -0
- data/bin/setup +8 -0
- data/lib/bima-shark-sdk/rspec.rb +38 -0
- data/lib/bima-shark-sdk.rb +3 -0
- data/lib/shark/account.rb +7 -0
- data/lib/shark/activity.rb +11 -0
- data/lib/shark/asset.rb +13 -0
- data/lib/shark/base.rb +36 -0
- data/lib/shark/client/connection.rb +67 -0
- data/lib/shark/concerns/connected.rb +44 -0
- data/lib/shark/concerns/normalized_email.rb +13 -0
- data/lib/shark/configuration.rb +90 -0
- data/lib/shark/consent.rb +31 -0
- data/lib/shark/contact.rb +40 -0
- data/lib/shark/contact_log.rb +7 -0
- data/lib/shark/double_opt_in/execution.rb +50 -0
- data/lib/shark/double_opt_in/request.rb +45 -0
- data/lib/shark/error.rb +69 -0
- data/lib/shark/form_service/base.rb +11 -0
- data/lib/shark/form_service/form/container.rb +10 -0
- data/lib/shark/form_service/form/element.rb +83 -0
- data/lib/shark/form_service/form/multiple_choice.rb +21 -0
- data/lib/shark/form_service/form/rating_scale.rb +20 -0
- data/lib/shark/form_service/form/rating_star.rb +13 -0
- data/lib/shark/form_service/form/structure.rb +13 -0
- data/lib/shark/form_service/form/text_area.rb +10 -0
- data/lib/shark/form_service/form/text_field.rb +17 -0
- data/lib/shark/form_service/v2/base.rb +13 -0
- data/lib/shark/form_service/v2/form.rb +18 -0
- data/lib/shark/form_service/v2/form_input.rb +15 -0
- data/lib/shark/form_service/v2/form_version.rb +19 -0
- data/lib/shark/form_service.rb +21 -0
- data/lib/shark/group.rb +18 -0
- data/lib/shark/mailing_service/base.rb +11 -0
- data/lib/shark/mailing_service/configuration.rb +9 -0
- data/lib/shark/mailing_service/mail.rb +8 -0
- data/lib/shark/mailing_service/mailers/base_mailer.rb +96 -0
- data/lib/shark/mailing_service/renderers/context.rb +40 -0
- data/lib/shark/mailing_service/renderers/erb_renderer.rb +46 -0
- data/lib/shark/mailing_service.rb +23 -0
- data/lib/shark/membership.rb +16 -0
- data/lib/shark/middleware/compose_request.rb +41 -0
- data/lib/shark/middleware/status.rb +36 -0
- data/lib/shark/notification.rb +21 -0
- data/lib/shark/package.rb +7 -0
- data/lib/shark/permission.rb +7 -0
- data/lib/shark/rails.rb +13 -0
- data/lib/shark/rspec/fake_asset_service/object_cache.rb +76 -0
- data/lib/shark/rspec/fake_asset_service/public_id.rb +21 -0
- data/lib/shark/rspec/fake_asset_service/request.rb +154 -0
- data/lib/shark/rspec/fake_asset_service.rb +20 -0
- data/lib/shark/rspec/fake_consent_service/object_cache.rb +44 -0
- data/lib/shark/rspec/fake_consent_service/request.rb +53 -0
- data/lib/shark/rspec/fake_consent_service.rb +19 -0
- data/lib/shark/rspec/fake_contact_service/object_cache.rb +88 -0
- data/lib/shark/rspec/fake_contact_service/request.rb +170 -0
- data/lib/shark/rspec/fake_contact_service.rb +19 -0
- data/lib/shark/rspec/fake_double_opt_in/object_cache.rb +59 -0
- data/lib/shark/rspec/fake_double_opt_in/request.rb +133 -0
- data/lib/shark/rspec/fake_double_opt_in.rb +19 -0
- data/lib/shark/rspec/fake_mailing_service/request.rb +41 -0
- data/lib/shark/rspec/fake_mailing_service.rb +13 -0
- data/lib/shark/rspec/fake_notification_service/request.rb +53 -0
- data/lib/shark/rspec/fake_notification_service.rb +13 -0
- data/lib/shark/rspec/fake_subscription_service/object_cache.rb +54 -0
- data/lib/shark/rspec/fake_subscription_service/request.rb +100 -0
- data/lib/shark/rspec/fake_subscription_service.rb +19 -0
- data/lib/shark/rspec/fake_survey_service/object_cache.rb +36 -0
- data/lib/shark/rspec/fake_survey_service/request.rb +66 -0
- data/lib/shark/rspec/fake_survey_service.rb +19 -0
- data/lib/shark/rspec/fixtures/form_inputs.json +26 -0
- data/lib/shark/rspec/fixtures/form_structure.json +175 -0
- data/lib/shark/rspec/helpers/cache_helper.rb +44 -0
- data/lib/shark/rspec/helpers/fixtures.rb +26 -0
- data/lib/shark/rspec/helpers/form_service_helper.rb +27 -0
- data/lib/shark/rspec/helpers/response.rb +25 -0
- data/lib/shark/rspec/helpers.rb +26 -0
- data/lib/shark/subscription.rb +43 -0
- data/lib/shark/survey.rb +29 -0
- data/lib/shark/survey_participant.rb +37 -0
- data/lib/shark/version.rb +5 -0
- data/lib/shark.rb +91 -0
- metadata +291 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
module RSpec
|
5
|
+
module FakeSubscriptionService
|
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(payload_data)
|
19
|
+
id = payload_data.delete('id')
|
20
|
+
|
21
|
+
if id && !objects.find { |subscription| subscription['id'] == id }
|
22
|
+
object = {
|
23
|
+
id: id,
|
24
|
+
attributes: payload_data
|
25
|
+
}
|
26
|
+
|
27
|
+
objects << object
|
28
|
+
else
|
29
|
+
objects << {
|
30
|
+
id: SecureRandom.uuid,
|
31
|
+
attributes: payload_data
|
32
|
+
}
|
33
|
+
end
|
34
|
+
objects.last
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_multiple(payload_data)
|
38
|
+
added = []
|
39
|
+
payload_data.each { |subscription| added << add(subscription) }
|
40
|
+
added.compact
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove(id)
|
44
|
+
objects.delete_if { |subscription| subscription[:id] == id }
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove_multiple(payload_data)
|
48
|
+
payload_data.each { |subscription| remove(subscription['id']) }
|
49
|
+
objects
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
module Shark
|
6
|
+
module RSpec
|
7
|
+
module FakeSubscriptionService
|
8
|
+
class Request
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
ALLOWED_FILTERS = %w[name subscriberId].freeze
|
12
|
+
|
13
|
+
def self.setup
|
14
|
+
instance = self.instance
|
15
|
+
instance.stub_requests
|
16
|
+
end
|
17
|
+
|
18
|
+
def stub_requests
|
19
|
+
WebMock.stub_request(:post, %r{^#{host}/subscriptions}).to_return do |request|
|
20
|
+
log_info "Faking POST request with body: #{request.body}"
|
21
|
+
|
22
|
+
payload_data = JSON.parse(request.body)['data']['attributes']
|
23
|
+
|
24
|
+
object_data = ObjectCache.instance.add(payload_data)
|
25
|
+
|
26
|
+
SharkSpec.fake_response(201, data: object_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
WebMock.stub_request(
|
30
|
+
:post,
|
31
|
+
%r{^#{host}/subscriptions/bulk_creation}
|
32
|
+
).to_return do |request|
|
33
|
+
log_info "Faking POST request with body: #{request.body}"
|
34
|
+
|
35
|
+
payload_data = JSON.parse(request.body)['data']['attributes']['subscriptions']
|
36
|
+
|
37
|
+
objects_data = ObjectCache.instance.add_multiple(payload_data)
|
38
|
+
|
39
|
+
SharkSpec.fake_response(201, data: objects_data)
|
40
|
+
end
|
41
|
+
|
42
|
+
WebMock.stub_request(
|
43
|
+
:post,
|
44
|
+
%r{^#{host}/subscriptions/bulk_deletion}
|
45
|
+
).to_return do |request|
|
46
|
+
log_info "Faking POST request with body: #{request.body}"
|
47
|
+
|
48
|
+
payload_data = JSON.parse(request.body)['data']['attributes']['subscriptions']
|
49
|
+
ObjectCache.instance.remove_multiple(payload_data)
|
50
|
+
|
51
|
+
SharkSpec.fake_response(204, nil)
|
52
|
+
end
|
53
|
+
|
54
|
+
WebMock.stub_request(:delete, %r{^#{host}/subscriptions/.+}).to_return do |request|
|
55
|
+
log_info "Faking DELETE request with body: #{request.body}"
|
56
|
+
|
57
|
+
id = request.uri.path.split('/')[2]
|
58
|
+
|
59
|
+
ObjectCache.instance.remove(id)
|
60
|
+
|
61
|
+
SharkSpec.fake_response(204, nil)
|
62
|
+
end
|
63
|
+
|
64
|
+
WebMock.stub_request(:get, %r{^#{host}/subscriptions}).to_return do |request|
|
65
|
+
log_info 'Faking GET request'
|
66
|
+
|
67
|
+
query_parameters = request.uri.query_values
|
68
|
+
|
69
|
+
objects_data = if query_parameters
|
70
|
+
params = {}
|
71
|
+
query_parameters.each do |key, value|
|
72
|
+
parsed_key = key.match(/filter\[(.*)\]/)[1].camelize(:lower)
|
73
|
+
params[parsed_key] = value if ALLOWED_FILTERS.include?(parsed_key)
|
74
|
+
end
|
75
|
+
|
76
|
+
ObjectCache.instance.objects.select do |subscription|
|
77
|
+
conditions = params.map do |param, value|
|
78
|
+
subscription[:attributes][param] == value
|
79
|
+
end
|
80
|
+
conditions.all?
|
81
|
+
end
|
82
|
+
else
|
83
|
+
ObjectCache.instance.objects
|
84
|
+
end
|
85
|
+
|
86
|
+
SharkSpec.fake_response(200, data: objects_data)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def host
|
91
|
+
Shark.configuration.subscription_service.site
|
92
|
+
end
|
93
|
+
|
94
|
+
def log_info(message)
|
95
|
+
Shark.logger.info "[Shark::SubscriptionService] #{message}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'fake_subscription_service/object_cache'
|
4
|
+
require_relative 'fake_subscription_service/request'
|
5
|
+
|
6
|
+
module Shark
|
7
|
+
module RSpec
|
8
|
+
module FakeSubscriptionService
|
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,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
module RSpec
|
5
|
+
module FakeSurveyService
|
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(payload)
|
19
|
+
payload['id'] = SecureRandom.uuid if payload['id'].blank?
|
20
|
+
|
21
|
+
objects << payload unless objects.detect { |o| o['id'] == id }
|
22
|
+
|
23
|
+
payload
|
24
|
+
end
|
25
|
+
|
26
|
+
def find(id, type)
|
27
|
+
objects.detect { |o| o['id'] == id && o['type'] == type }
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove(id, type)
|
31
|
+
objects.delete_if { |o| o['id'] == id && o['type'] == type }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
module Shark
|
6
|
+
module RSpec
|
7
|
+
module FakeSurveyService
|
8
|
+
class Request
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
attr_accessor :cache
|
12
|
+
|
13
|
+
def self.setup
|
14
|
+
instance = self.instance
|
15
|
+
instance.stub_requests
|
16
|
+
instance.cache = ObjectCache.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_requests
|
20
|
+
WebMock.stub_request(:post, %r{^#{host}/.*$}).to_return do |request|
|
21
|
+
log "POST #{request.uri}"
|
22
|
+
log "Body #{request.body}"
|
23
|
+
|
24
|
+
payload = JSON.parse(request.body)['data']
|
25
|
+
object = cache.add(payload)
|
26
|
+
|
27
|
+
SharkSpec.fake_response(201, data: object)
|
28
|
+
end
|
29
|
+
|
30
|
+
WebMock.stub_request(:delete, %r{^#{host}/.+/.+}).to_return do |request|
|
31
|
+
log "DELETE #{request.uri}"
|
32
|
+
|
33
|
+
id = request.uri.path.split('/')[2]
|
34
|
+
|
35
|
+
ObjectCache.instance.remove(id)
|
36
|
+
|
37
|
+
SharkSpec.fake_response(204, nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
WebMock.stub_request(:get, %r{^#{host}/.+/.+}).to_return do |request|
|
41
|
+
log "GET #{request.uri}"
|
42
|
+
|
43
|
+
type = request.uri.path.split('/')[4]
|
44
|
+
id = request.uri.path.split('/')[5]
|
45
|
+
|
46
|
+
object = cache.find(id, type)
|
47
|
+
|
48
|
+
if object.present?
|
49
|
+
SharkSpec.fake_response(200, data: object)
|
50
|
+
else
|
51
|
+
SharkSpec.fake_response(404, errors: [])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def host
|
57
|
+
Shark.configuration.survey_service.site
|
58
|
+
end
|
59
|
+
|
60
|
+
def log(message)
|
61
|
+
Shark.logger.info "[Shark] #{message}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'fake_survey_service/object_cache'
|
4
|
+
require_relative 'fake_survey_service/request'
|
5
|
+
|
6
|
+
module Shark
|
7
|
+
module RSpec
|
8
|
+
module FakeSurveyService
|
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,26 @@
|
|
1
|
+
{
|
2
|
+
"data": [
|
3
|
+
{
|
4
|
+
"id": "24",
|
5
|
+
"type": "form_input",
|
6
|
+
"attributes": {
|
7
|
+
"additional_data": {},
|
8
|
+
"data": {
|
9
|
+
"c1e74363": [
|
10
|
+
"neutral"
|
11
|
+
],
|
12
|
+
"21ef058f": [
|
13
|
+
"-1"
|
14
|
+
],
|
15
|
+
"86083327": [
|
16
|
+
"-1"
|
17
|
+
],
|
18
|
+
"53bc9530": "Hier etwas Freitext"
|
19
|
+
},
|
20
|
+
"user_id": "6a36d558e8f44882c7f9662063190113",
|
21
|
+
"created_at": "2017-07-20T10:59:15.000+02:00",
|
22
|
+
"updated_at": "2017-07-20T15:45:35.000+02:00"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
@@ -0,0 +1,175 @@
|
|
1
|
+
{
|
2
|
+
"id": "12a3b05a",
|
3
|
+
"type": "form",
|
4
|
+
"elements": [
|
5
|
+
{
|
6
|
+
"id": "a00a5058",
|
7
|
+
"type": "form_container",
|
8
|
+
"elements": [
|
9
|
+
{
|
10
|
+
"id": "50f759ed",
|
11
|
+
"type": "form_container",
|
12
|
+
"elements": [
|
13
|
+
{
|
14
|
+
"id": "f1f0a9fa",
|
15
|
+
"type": "form_multiple_choice",
|
16
|
+
"mandatory": true,
|
17
|
+
"multiple_choices": false,
|
18
|
+
"valid_values": [
|
19
|
+
"Bundesamt für ABC",
|
20
|
+
"oerifjeroif",
|
21
|
+
"eorigfjeaoörgij",
|
22
|
+
"eorigjaöoeirgj",
|
23
|
+
"223423",
|
24
|
+
"fjewriofj",
|
25
|
+
"anderes"
|
26
|
+
],
|
27
|
+
"attribute_definitions": [
|
28
|
+
{
|
29
|
+
"name": "more_on_choice",
|
30
|
+
"type": "string",
|
31
|
+
"value": ""
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"attribute_definitions": [
|
37
|
+
{
|
38
|
+
"name": "legend",
|
39
|
+
"type": "string",
|
40
|
+
"value": "a)"
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"name": "text",
|
44
|
+
"type": "html",
|
45
|
+
"value": "Fworgnweiog jweif jweif jweiof weoifj weoif jweoif?"
|
46
|
+
}
|
47
|
+
]
|
48
|
+
}
|
49
|
+
],
|
50
|
+
"attribute_definitions": [
|
51
|
+
{
|
52
|
+
"name": "legend",
|
53
|
+
"type": "string",
|
54
|
+
"value": "Frage 1"
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"name": "text",
|
58
|
+
"type": "html",
|
59
|
+
"value": "Eeroigj eroigj eriogj eorig jeorgj eroig jeorigj eaöoirgj eaörg jeaiöorgj eaoöirgj eaorg jeaoirg jearoig jeaorigj eaoöirgj eaoörgj aeöorgj aeoörigj eiaoörgj eroij eoirj eoir jearoig jaeorigj aeorigj eaorigj eaorij eaorigj eraiojg eioajg eoarijg aeöiogjr oaieög."
|
60
|
+
}
|
61
|
+
]
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"id": "95cb27d0",
|
65
|
+
"type": "form_container",
|
66
|
+
"elements": [
|
67
|
+
{
|
68
|
+
"id": "bb86c4cf",
|
69
|
+
"type": "form_textarea",
|
70
|
+
"mandatory": true,
|
71
|
+
"attribute_definitions": [
|
72
|
+
{
|
73
|
+
"name": "legend",
|
74
|
+
"type": "string",
|
75
|
+
"value": "a)"
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}
|
79
|
+
],
|
80
|
+
"attribute_definitions": [
|
81
|
+
{
|
82
|
+
"name": "legend",
|
83
|
+
"type": "string",
|
84
|
+
"value": "Frage 2"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"name": "text",
|
88
|
+
"type": "html",
|
89
|
+
"value": "weiofj woiefj woeifj woeifj woiejf oweifj woiefj woiefj?"
|
90
|
+
}
|
91
|
+
]
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"id": "51ab3a5c",
|
95
|
+
"type": "form_container",
|
96
|
+
"attribute_definitions": [
|
97
|
+
{
|
98
|
+
"name": "legend",
|
99
|
+
"type": "string",
|
100
|
+
"value": "Frage 3"
|
101
|
+
},
|
102
|
+
{
|
103
|
+
"name": "text",
|
104
|
+
"type": "html",
|
105
|
+
"value": ""
|
106
|
+
}
|
107
|
+
]
|
108
|
+
},
|
109
|
+
{
|
110
|
+
"id": "2ed1579d",
|
111
|
+
"type": "form_container",
|
112
|
+
"attribute_definitions": [
|
113
|
+
{
|
114
|
+
"name": "legend",
|
115
|
+
"type": "string",
|
116
|
+
"value": "Frage 4"
|
117
|
+
},
|
118
|
+
{
|
119
|
+
"name": "text",
|
120
|
+
"type": "html",
|
121
|
+
"value": ""
|
122
|
+
}
|
123
|
+
]
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"id": "de64f672",
|
127
|
+
"type": "form_container",
|
128
|
+
"elements": [
|
129
|
+
{
|
130
|
+
"id": "c9529f9a",
|
131
|
+
"type": "form_rating_scale",
|
132
|
+
"mandatory": true,
|
133
|
+
"allow_no_information": true,
|
134
|
+
"no_information_label": "keine Angabe",
|
135
|
+
"scale_start": "1",
|
136
|
+
"scale_start_legend": "schlecht",
|
137
|
+
"scale_end": "5",
|
138
|
+
"scale_end_legend": "gut",
|
139
|
+
"default_value": "-1",
|
140
|
+
"attribute_definitions": [
|
141
|
+
{
|
142
|
+
"name": "legend",
|
143
|
+
"type": "string",
|
144
|
+
"value": "a)"
|
145
|
+
}
|
146
|
+
]
|
147
|
+
}
|
148
|
+
],
|
149
|
+
"attribute_definitions": [
|
150
|
+
{
|
151
|
+
"name": "legend",
|
152
|
+
"type": "string",
|
153
|
+
"value": "Frage 5"
|
154
|
+
},
|
155
|
+
{
|
156
|
+
"name": "text",
|
157
|
+
"type": "html",
|
158
|
+
"value": "Wwignweifj woiefjg woiefj weoijf oiwejf woiejf w49ofj lwigj alergveaorigj eaoirjg eoairjg aeorig jearoig jaeoirg j?"
|
159
|
+
}
|
160
|
+
]
|
161
|
+
}
|
162
|
+
],
|
163
|
+
"attribute_definitions": [
|
164
|
+
{
|
165
|
+
"name": "final_words",
|
166
|
+
"type": "html",
|
167
|
+
"value": "Danke"
|
168
|
+
},
|
169
|
+
{
|
170
|
+
"name": "submit",
|
171
|
+
"type": "string",
|
172
|
+
"value": "Absenden"
|
173
|
+
}
|
174
|
+
]
|
175
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
module RSpec
|
5
|
+
module Helpers
|
6
|
+
module CacheHelper
|
7
|
+
def find(type, id)
|
8
|
+
objects.detect { |o| o['type'] == type && o['id'] == id }
|
9
|
+
end
|
10
|
+
|
11
|
+
def included_resources(object_or_objects, params)
|
12
|
+
return [] unless params['include'].present?
|
13
|
+
|
14
|
+
relationships = params['include'].split(',')
|
15
|
+
included_objects = []
|
16
|
+
|
17
|
+
to_array(object_or_objects).each do |object|
|
18
|
+
relationships.each do |name|
|
19
|
+
rdata = object.dig('relationships', name, 'data')
|
20
|
+
to_array(rdata).each do |r|
|
21
|
+
included_objects << find(r['type'], r['id'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
included_objects.compact
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def to_array(object_or_objects)
|
32
|
+
case object_or_objects
|
33
|
+
when Hash
|
34
|
+
[object_or_objects]
|
35
|
+
when Array
|
36
|
+
object_or_objects
|
37
|
+
else
|
38
|
+
Array(object_or_objects)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
module RSpec
|
5
|
+
module Helpers
|
6
|
+
module Fixtures
|
7
|
+
def form_structure_json
|
8
|
+
load_json_fixture('form_structure.json')
|
9
|
+
end
|
10
|
+
|
11
|
+
def form_inputs_json
|
12
|
+
load_json_fixture('form_inputs.json')
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_json_fixture(filename)
|
16
|
+
JSON.parse(load_fixture(filename))
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_fixture(filename)
|
20
|
+
filepath = File.expand_path("../../fixtures/#{filename}", __FILE__)
|
21
|
+
File.read(filepath)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
module RSpec
|
5
|
+
module Helpers
|
6
|
+
module FormServiceHelper
|
7
|
+
def form_version(attributes = {})
|
8
|
+
defaults = {
|
9
|
+
id: 1,
|
10
|
+
state: 'active',
|
11
|
+
structure: SharkSpec.form_structure_json
|
12
|
+
}
|
13
|
+
|
14
|
+
Shark::FormService::V2::FormVersion.new(defaults.merge(attributes))
|
15
|
+
end
|
16
|
+
|
17
|
+
def form_inputs(attributes = {})
|
18
|
+
data = SharkSpec.form_inputs_json['data']
|
19
|
+
data.map do |input|
|
20
|
+
input['attributes'].merge!(attributes)
|
21
|
+
Shark::FormService::V2::FormInput.new(input)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
module RSpec
|
5
|
+
module Helpers
|
6
|
+
module Response
|
7
|
+
def fake_response(status, body)
|
8
|
+
serialized_body = if body.nil? || body.is_a?(String)
|
9
|
+
body
|
10
|
+
else
|
11
|
+
body.to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
{
|
15
|
+
headers: {
|
16
|
+
content_type: 'application/vnd.api+json'
|
17
|
+
},
|
18
|
+
status: status,
|
19
|
+
body: serialized_body
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helpers/cache_helper'
|
4
|
+
|
5
|
+
require_relative 'fake_asset_service'
|
6
|
+
require_relative 'fake_contact_service'
|
7
|
+
require_relative 'fake_notification_service'
|
8
|
+
require_relative 'fake_consent_service'
|
9
|
+
require_relative 'fake_subscription_service'
|
10
|
+
require_relative 'fake_double_opt_in'
|
11
|
+
require_relative 'fake_mailing_service'
|
12
|
+
require_relative 'fake_survey_service'
|
13
|
+
|
14
|
+
require_relative 'helpers/fixtures'
|
15
|
+
require_relative 'helpers/response'
|
16
|
+
require_relative 'helpers/form_service_helper'
|
17
|
+
|
18
|
+
module Shark
|
19
|
+
module RSpec
|
20
|
+
module Helpers
|
21
|
+
include Helpers::Fixtures
|
22
|
+
include Helpers::Response
|
23
|
+
include Helpers::FormServiceHelper
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Shark
|
4
|
+
class Subscription < Base
|
5
|
+
extend SubscriptionService::Resource
|
6
|
+
|
7
|
+
custom_endpoint :bulk_creation, on: :collection, request_method: :post
|
8
|
+
custom_endpoint :bulk_deletion, on: :collection, request_method: :post
|
9
|
+
|
10
|
+
def self.create_multiple(attributes)
|
11
|
+
bulk_creation(subscriptions_attributes(attributes))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.destroy_multiple(attributes)
|
15
|
+
bulk_deletion(subscriptions_attributes(attributes))
|
16
|
+
end
|
17
|
+
|
18
|
+
def save
|
19
|
+
if self['id'].present?
|
20
|
+
raise Shark::ActionNotSupportedError,
|
21
|
+
'Shark::Subscription#save is not supported for persisted subscriptions'
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def update_attributes(_attributes = {})
|
28
|
+
raise Shark::ActionNotSupportedError,
|
29
|
+
'Shark::Subscription#update_attributes is not supported'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.subscriptions_attributes(attributes)
|
33
|
+
{
|
34
|
+
data: {
|
35
|
+
type: 'bulk-subscriptions',
|
36
|
+
attributes: {
|
37
|
+
subscriptions: attributes
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|