campact_user_service 4.1.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +4 -4
- data/.ruby-version +1 -1
- data/VERSION +1 -1
- data/campact_user_service.gemspec +20 -36
- data/example.rb +17 -6
- data/lib/campact_user_service/account.rb +7 -2
- data/lib/campact_user_service/client.rb +6 -1
- data/lib/campact_user_service/prefill_forms.rb +24 -0
- data/lib/campact_user_service/session.rb +2 -2
- data/lib/campact_user_service.rb +8 -2
- data/spec/account_spec.rb +32 -9
- data/spec/campact_user_service_spec.rb +3 -3
- data/spec/client_spec.rb +44 -2
- data/spec/prefill_forms_spec.rb +76 -0
- data/spec/session_spec.rb +3 -3
- metadata +5 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b3c869e577689bc02693578a97970bb9ccf80fff5dd4a63e9eb5c3f74af88e42
|
|
4
|
+
data.tar.gz: d1ce8aeed9c071623e1dd4f7e73537e5da4d00e1cd3cc8c41ade91f9d2486ecd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac327c6be12ae6933ab108aaafec45768f7c9bcbb59c0cb49ee57ee68a9ddcb759c410c05dbd4e3156ca45999e632bf62bbbd77445521240864257e8f772593a
|
|
7
|
+
data.tar.gz: 7499d6b23a4f275997e1354d8716913891cf35760c73976b48dec7bdd0f842c63582702f89e6b9638cf9f23c49273c9d8eba1e1e47ede79b5fc4d746e951cc7c
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -6,9 +6,9 @@ jobs:
|
|
|
6
6
|
runs-on: ubuntu-latest
|
|
7
7
|
steps:
|
|
8
8
|
- uses: actions/checkout@v2
|
|
9
|
-
- uses: ruby/setup-ruby@
|
|
9
|
+
- uses: ruby/setup-ruby@v1
|
|
10
10
|
with:
|
|
11
|
-
ruby-version:
|
|
11
|
+
ruby-version: 3.4
|
|
12
12
|
bundler-cache: true
|
|
13
13
|
- run: bundle install
|
|
14
14
|
- run: bundle exec rspec
|
|
@@ -16,9 +16,9 @@ jobs:
|
|
|
16
16
|
runs-on: ubuntu-latest
|
|
17
17
|
steps:
|
|
18
18
|
- uses: actions/checkout@v2
|
|
19
|
-
- uses: ruby/setup-ruby@
|
|
19
|
+
- uses: ruby/setup-ruby@v1
|
|
20
20
|
with:
|
|
21
|
-
ruby-version:
|
|
21
|
+
ruby-version: 3.4
|
|
22
22
|
bundler-cache: true
|
|
23
23
|
- run: bundle install
|
|
24
24
|
- run: bundle exec rubocop
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.4.5
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
4.
|
|
1
|
+
4.2.0
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: campact_user_service 4.
|
|
5
|
+
# stub: campact_user_service 4.2.0 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "campact_user_service".freeze
|
|
9
|
-
s.version = "4.
|
|
9
|
+
s.version = "4.2.0".freeze
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib".freeze]
|
|
13
13
|
s.authors = ["ControlShift".freeze]
|
|
14
|
-
s.date = "
|
|
14
|
+
s.date = "1980-01-02"
|
|
15
15
|
s.description = "Ruby wrapper for Campact User Service".freeze
|
|
16
16
|
s.email = "hello@controlshiftlabs.com".freeze
|
|
17
17
|
s.extra_rdoc_files = [
|
|
@@ -33,51 +33,35 @@ Gem::Specification.new do |s|
|
|
|
33
33
|
"lib/campact_user_service.rb",
|
|
34
34
|
"lib/campact_user_service/account.rb",
|
|
35
35
|
"lib/campact_user_service/client.rb",
|
|
36
|
+
"lib/campact_user_service/prefill_forms.rb",
|
|
36
37
|
"lib/campact_user_service/response_error.rb",
|
|
37
38
|
"lib/campact_user_service/session.rb",
|
|
38
39
|
"spec/account_spec.rb",
|
|
39
40
|
"spec/campact_user_service_spec.rb",
|
|
40
41
|
"spec/client_spec.rb",
|
|
42
|
+
"spec/prefill_forms_spec.rb",
|
|
41
43
|
"spec/session_spec.rb",
|
|
42
44
|
"spec/spec_helper.rb"
|
|
43
45
|
]
|
|
44
46
|
s.homepage = "http://github.com/controlshift/campact_user_service".freeze
|
|
45
47
|
s.licenses = ["MIT".freeze]
|
|
46
|
-
s.rubygems_version = "3.
|
|
48
|
+
s.rubygems_version = "3.6.9".freeze
|
|
47
49
|
s.summary = "Ruby wrapper for Campact User Service".freeze
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
s.specification_version = 4
|
|
51
|
-
end
|
|
51
|
+
s.specification_version = 4
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
|
|
67
|
-
else
|
|
68
|
-
s.add_dependency(%q<rotp>.freeze, ["~> 6"])
|
|
69
|
-
s.add_dependency(%q<faraday>.freeze, ["~> 1.0"])
|
|
70
|
-
s.add_dependency(%q<json>.freeze, ["~> 2.1"])
|
|
71
|
-
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
|
72
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
|
73
|
-
s.add_dependency(%q<shoulda>.freeze, [">= 0"])
|
|
74
|
-
s.add_dependency(%q<webmock>.freeze, [">= 0"])
|
|
75
|
-
s.add_dependency(%q<rdoc>.freeze, ["~> 6.0", ">= 6.0.4"])
|
|
76
|
-
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
|
77
|
-
s.add_dependency(%q<simplecov>.freeze, ["= 0.16.1"])
|
|
78
|
-
s.add_dependency(%q<pry-byebug>.freeze, ["~> 3.6"])
|
|
79
|
-
s.add_dependency(%q<faraday-detailed_logger>.freeze, ["~> 2.1", ">= 2.1.2"])
|
|
80
|
-
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
|
|
81
|
-
end
|
|
53
|
+
s.add_runtime_dependency(%q<rotp>.freeze, ["~> 6".freeze])
|
|
54
|
+
s.add_runtime_dependency(%q<faraday>.freeze, ["~> 1.0".freeze])
|
|
55
|
+
s.add_runtime_dependency(%q<json>.freeze, ["~> 2.1".freeze])
|
|
56
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0".freeze])
|
|
57
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
|
|
58
|
+
s.add_development_dependency(%q<shoulda>.freeze, [">= 0".freeze])
|
|
59
|
+
s.add_development_dependency(%q<webmock>.freeze, [">= 0".freeze])
|
|
60
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.0".freeze, ">= 6.0.4".freeze])
|
|
61
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0".freeze])
|
|
62
|
+
s.add_development_dependency(%q<simplecov>.freeze, ["= 0.16.1".freeze])
|
|
63
|
+
s.add_development_dependency(%q<pry-byebug>.freeze, ["~> 3.6".freeze])
|
|
64
|
+
s.add_development_dependency(%q<faraday-detailed_logger>.freeze, ["~> 2.1".freeze, ">= 2.1.2".freeze])
|
|
65
|
+
s.add_development_dependency(%q<rubocop>.freeze, [">= 0".freeze])
|
|
82
66
|
end
|
|
83
67
|
|
data/example.rb
CHANGED
|
@@ -3,9 +3,11 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
|
|
3
3
|
require 'campact_user_service'
|
|
4
4
|
require 'faraday/detailed_logger'
|
|
5
5
|
|
|
6
|
+
service_host = ENV['SERVICE_HOST'] || 'weact-adapter.staging.campact.de'
|
|
7
|
+
|
|
6
8
|
def instrument_connection_with_extended_logging(client)
|
|
7
9
|
default_options = {
|
|
8
|
-
ssl: { verify:
|
|
10
|
+
ssl: { verify: false },
|
|
9
11
|
headers: {
|
|
10
12
|
'Accept' => "application/json;q=0.1",
|
|
11
13
|
'Accept-Charset' => "utf-8",
|
|
@@ -29,7 +31,8 @@ end
|
|
|
29
31
|
# Pick which API to connect to
|
|
30
32
|
# 1 for session
|
|
31
33
|
# 2 for user
|
|
32
|
-
|
|
34
|
+
# 3 for prefill forms
|
|
35
|
+
puts "Which user service are you going to use?\n\t1) session\n\t2) user\n\t3) prefill forms"
|
|
33
36
|
option = gets.chomp
|
|
34
37
|
|
|
35
38
|
# Get TOTP credentials
|
|
@@ -57,17 +60,25 @@ when '1'
|
|
|
57
60
|
token,
|
|
58
61
|
'campact-staging-session',
|
|
59
62
|
{
|
|
60
|
-
host:
|
|
63
|
+
host: service_host,
|
|
61
64
|
topt_authorization: {user: username, secret: secret}
|
|
62
65
|
}
|
|
63
66
|
)
|
|
64
67
|
when '2'
|
|
65
68
|
puts "I'll need a user account ID. In practice I won't need this here because it can be derived through the session token"
|
|
66
|
-
|
|
69
|
+
account_id = gets.chomp
|
|
67
70
|
account = CampactUserService.account(
|
|
68
|
-
|
|
71
|
+
account_id,
|
|
69
72
|
{
|
|
70
|
-
host:
|
|
73
|
+
host: service_host,
|
|
74
|
+
topt_authorization: {user: username, secret: secret}
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
when '3'
|
|
78
|
+
puts "I'll need a user account ID. In practice I won't need this here because it can be derived through the session token"
|
|
79
|
+
account_id = gets.chomp
|
|
80
|
+
prefill_forms = CampactUserService.prefill_forms(account_id, {
|
|
81
|
+
host: service_host,
|
|
71
82
|
topt_authorization: {user: username, secret: secret}
|
|
72
83
|
}
|
|
73
84
|
)
|
|
@@ -2,7 +2,7 @@ module CampactUserService
|
|
|
2
2
|
class Account
|
|
3
3
|
attr_reader :client, :user_id
|
|
4
4
|
|
|
5
|
-
# user_id can either be the user's
|
|
5
|
+
# user_id can either be the user's account_id or their email address
|
|
6
6
|
def initialize(client, user_id)
|
|
7
7
|
@client = client
|
|
8
8
|
@user_id = user_id
|
|
@@ -17,8 +17,13 @@ module CampactUserService
|
|
|
17
17
|
subscriptions.any? {|s| s['type'] == 'newsletter' }
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
def prefill_undecided?
|
|
21
|
+
prefill = account['prefill_forms_state']
|
|
22
|
+
prefill.to_s == 'undecided'
|
|
23
|
+
end
|
|
24
|
+
|
|
20
25
|
def allow_prefill?
|
|
21
|
-
prefill = account
|
|
26
|
+
prefill = account['prefill_forms_state']
|
|
22
27
|
prefill.to_s == 'allowed'
|
|
23
28
|
end
|
|
24
29
|
|
|
@@ -19,10 +19,11 @@ module CampactUserService
|
|
|
19
19
|
|
|
20
20
|
@connection = Faraday.new(endpoint, faraday_options) do |faraday|
|
|
21
21
|
faraday.adapter adapter
|
|
22
|
+
faraday.request :json
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
%i(get delete).each do |verb|
|
|
26
|
+
%i(get delete patch).each do |verb|
|
|
26
27
|
define_method("#{verb}_request") do |path, options={}|
|
|
27
28
|
request(verb, path, options)
|
|
28
29
|
end
|
|
@@ -39,6 +40,10 @@ module CampactUserService
|
|
|
39
40
|
req.headers['Cookie'] = format_cookies(options[:cookies])
|
|
40
41
|
end
|
|
41
42
|
|
|
43
|
+
if options.key?(:body)
|
|
44
|
+
req.body = options[:body]
|
|
45
|
+
end
|
|
46
|
+
|
|
42
47
|
if topt_authorization
|
|
43
48
|
req.headers['authorization'] = authorization(topt_authorization)
|
|
44
49
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'cgi'
|
|
2
|
+
|
|
3
|
+
module CampactUserService
|
|
4
|
+
class PrefillForms
|
|
5
|
+
attr_reader :client, :account_id
|
|
6
|
+
|
|
7
|
+
def initialize(client, account_id)
|
|
8
|
+
@client = client
|
|
9
|
+
@account_id = account_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update_prefill_forms(prefill_forms_state:, campaign_slug:, **additional_params)
|
|
13
|
+
params = {
|
|
14
|
+
prefill_forms: {
|
|
15
|
+
state: prefill_forms_state,
|
|
16
|
+
slug: campaign_slug
|
|
17
|
+
}.merge(additional_params)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
path = "/v1/prefill_forms?account_id=#{CGI.escape(account_id.to_s)}"
|
|
21
|
+
client.patch_request(path, body: params)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/campact_user_service.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'campact_user_service/client'
|
|
2
2
|
require 'campact_user_service/session'
|
|
3
3
|
require 'campact_user_service/account'
|
|
4
|
+
require 'campact_user_service/prefill_forms'
|
|
4
5
|
|
|
5
6
|
module CampactUserService
|
|
6
7
|
class << self
|
|
@@ -9,9 +10,14 @@ module CampactUserService
|
|
|
9
10
|
CampactUserService::Session.new(client, session_id, session_cookie_name)
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def account(
|
|
13
|
+
def account(account_id, options)
|
|
13
14
|
client = CampactUserService::Client.new(options)
|
|
14
|
-
CampactUserService::Account.new(client,
|
|
15
|
+
CampactUserService::Account.new(client, account_id)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def prefill_forms(account_id, options)
|
|
19
|
+
client = CampactUserService::Client.new(options)
|
|
20
|
+
CampactUserService::PrefillForms.new(client, account_id)
|
|
15
21
|
end
|
|
16
22
|
end
|
|
17
23
|
end
|
data/spec/account_spec.rb
CHANGED
|
@@ -165,9 +165,7 @@ describe CampactUserService::Account do
|
|
|
165
165
|
it 'should allow prefilling where the user has opted-in' do
|
|
166
166
|
stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
|
|
167
167
|
.to_return(body: {
|
|
168
|
-
"
|
|
169
|
-
"prefill_forms": "allowed"
|
|
170
|
-
}
|
|
168
|
+
"prefill_forms_state": "allowed"
|
|
171
169
|
}.to_json)
|
|
172
170
|
|
|
173
171
|
expect(subject.allow_prefill?).to be_truthy
|
|
@@ -176,9 +174,7 @@ describe CampactUserService::Account do
|
|
|
176
174
|
it 'should not allow prefilling where the user has not decided' do
|
|
177
175
|
stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
|
|
178
176
|
.to_return(body: {
|
|
179
|
-
"
|
|
180
|
-
"prefill_forms": "undecided"
|
|
181
|
-
}
|
|
177
|
+
"prefill_forms_state": "undecided"
|
|
182
178
|
}.to_json)
|
|
183
179
|
|
|
184
180
|
expect(subject.allow_prefill?).to be_falsey
|
|
@@ -187,12 +183,39 @@ describe CampactUserService::Account do
|
|
|
187
183
|
it 'should not allow prefilling where the user has opted out' do
|
|
188
184
|
stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
|
|
189
185
|
.to_return(body: {
|
|
190
|
-
"
|
|
191
|
-
"prefill_forms": "disallowed"
|
|
192
|
-
}
|
|
186
|
+
"prefill_forms_state": "forbidden"
|
|
193
187
|
}.to_json)
|
|
194
188
|
|
|
195
189
|
expect(subject.allow_prefill?).to be_falsey
|
|
196
190
|
end
|
|
197
191
|
end
|
|
192
|
+
|
|
193
|
+
describe "#prefill_undecided?" do
|
|
194
|
+
it 'should be true if the user has not decided' do
|
|
195
|
+
stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
|
|
196
|
+
.to_return(body: {
|
|
197
|
+
"prefill_forms_state": "undecided"
|
|
198
|
+
}.to_json)
|
|
199
|
+
|
|
200
|
+
expect(subject.prefill_undecided?).to be_truthy
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'should be false if the user has opted-in' do
|
|
204
|
+
stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
|
|
205
|
+
.to_return(body: {
|
|
206
|
+
"prefill_forms_state": "allowed"
|
|
207
|
+
}.to_json)
|
|
208
|
+
|
|
209
|
+
expect(subject.prefill_undecided?).to be_falsey
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
it 'should be false if the user has opted out' do
|
|
213
|
+
stub_request(:get, "https://test.com/v1/accounts/#{user_id}")
|
|
214
|
+
.to_return(body: {
|
|
215
|
+
"prefill_forms_state": "forbidden"
|
|
216
|
+
}.to_json)
|
|
217
|
+
|
|
218
|
+
expect(subject.prefill_undecided?).to be_falsey
|
|
219
|
+
end
|
|
220
|
+
end
|
|
198
221
|
end
|
|
@@ -24,11 +24,11 @@ describe CampactUserService do
|
|
|
24
24
|
options = { foo: 'bar', foo2: 'bar2' }
|
|
25
25
|
client = double
|
|
26
26
|
expect(CampactUserService::Client).to receive(:new).with(options).and_return(client)
|
|
27
|
-
|
|
27
|
+
account_id = '189b6864-d58a-4f49-8370-4ae0b854a40e'
|
|
28
28
|
account_api = double
|
|
29
|
-
expect(CampactUserService::Account).to receive(:new).with(client,
|
|
29
|
+
expect(CampactUserService::Account).to receive(:new).with(client, account_id).and_return(account_api)
|
|
30
30
|
|
|
31
|
-
account = subject.account(
|
|
31
|
+
account = subject.account(account_id, options)
|
|
32
32
|
|
|
33
33
|
expect(account).to be(account_api)
|
|
34
34
|
end
|
data/spec/client_spec.rb
CHANGED
|
@@ -11,6 +11,10 @@ describe CampactUserService::Client do
|
|
|
11
11
|
}
|
|
12
12
|
let(:faraday_builder) { double(adapter: true) }
|
|
13
13
|
|
|
14
|
+
before :each do
|
|
15
|
+
allow(faraday_builder).to receive(:request).with(:json)
|
|
16
|
+
end
|
|
17
|
+
|
|
14
18
|
it 'should initialize connection from options' do
|
|
15
19
|
expect(faraday_builder).to receive(:adapter).with(:an_adapter)
|
|
16
20
|
|
|
@@ -87,7 +91,7 @@ describe CampactUserService::Client do
|
|
|
87
91
|
subject { CampactUserService::Client.new(host: 'demo.campact.de') }
|
|
88
92
|
|
|
89
93
|
before :each do
|
|
90
|
-
expect(Faraday).to receive(:new).and_yield(double(adapter: true)).and_return(connection)
|
|
94
|
+
expect(Faraday).to receive(:new).and_yield(double(adapter: true, request: true)).and_return(connection)
|
|
91
95
|
expect(request_builder).to receive(:options).at_least(:once).and_return(request_builder_options)
|
|
92
96
|
expect(connection).to receive(:get).and_yield(request_builder).and_return(response)
|
|
93
97
|
end
|
|
@@ -167,11 +171,49 @@ describe CampactUserService::Client do
|
|
|
167
171
|
subject { CampactUserService::Client.new(host: 'demo.campact.de') }
|
|
168
172
|
|
|
169
173
|
before :each do
|
|
170
|
-
expect(Faraday).to receive(:new).and_yield(double(adapter: true)).and_return(connection)
|
|
174
|
+
expect(Faraday).to receive(:new).and_yield(double(adapter: true, request: true)).and_return(connection)
|
|
171
175
|
expect(request_builder).to receive(:options).at_least(:once).and_return(request_builder_options)
|
|
172
176
|
expect(connection).to receive(:delete).and_yield(request_builder).and_return(response)
|
|
173
177
|
end
|
|
174
178
|
|
|
175
179
|
include_examples 'error handling'
|
|
176
180
|
end
|
|
181
|
+
|
|
182
|
+
describe '#patch_request' do
|
|
183
|
+
let(:connection) { double }
|
|
184
|
+
let(:request_builder) { double }
|
|
185
|
+
let(:request_builder_options) { double }
|
|
186
|
+
let(:response) { double(body: '') }
|
|
187
|
+
let(:method_under_test) { :patch_request }
|
|
188
|
+
|
|
189
|
+
subject { CampactUserService::Client.new(host: 'demo.campact.de') }
|
|
190
|
+
|
|
191
|
+
context 'with faraday stubbed' do
|
|
192
|
+
before :each do
|
|
193
|
+
expect(Faraday).to receive(:new).and_yield(double(adapter: true, request: true)).and_return(connection)
|
|
194
|
+
expect(request_builder).to receive(:options).at_least(:once).and_return(request_builder_options)
|
|
195
|
+
expect(connection).to receive(:patch).and_yield(request_builder).and_return(response)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
include_examples 'error handling'
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
context 'with HTTP connection stubbed' do
|
|
202
|
+
before(:each) do
|
|
203
|
+
WebMock.disable_net_connect!
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
it 'should send the body included in options' do
|
|
207
|
+
stub_patch =
|
|
208
|
+
stub_request(:patch, 'https://demo.campact.de/foo/bar')
|
|
209
|
+
.with(body: { a_field: 'foo', another_field: 'bar' }.to_json,
|
|
210
|
+
headers: { 'Content-Type'=>'application/json' })
|
|
211
|
+
.to_return(status: 204)
|
|
212
|
+
|
|
213
|
+
subject.patch_request('/foo/bar', body: { a_field: 'foo', another_field: 'bar' })
|
|
214
|
+
|
|
215
|
+
assert_requested(stub_patch)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
177
219
|
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CampactUserService::PrefillForms do
|
|
4
|
+
let(:client) { CampactUserService::Client.new(host: 'test.com') }
|
|
5
|
+
let(:account_id) { 'abcdef123456fedcba' }
|
|
6
|
+
|
|
7
|
+
subject do
|
|
8
|
+
CampactUserService::PrefillForms.new(client, account_id)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
before(:each) do
|
|
12
|
+
WebMock.disable_net_connect!
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe '#update_prefill_forms' do
|
|
16
|
+
it 'should update the prefill forms state with just the state and petition slug' do
|
|
17
|
+
stub_patch_prefill_forms = stub_request(:patch, "https://test.com/v1/prefill_forms?account_id=#{account_id}")
|
|
18
|
+
.with(body: {
|
|
19
|
+
prefill_forms: {
|
|
20
|
+
state: 'allowed',
|
|
21
|
+
slug: 'save-the-forest'
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
.to_return(status: 204)
|
|
25
|
+
|
|
26
|
+
result = subject.update_prefill_forms(prefill_forms_state: 'allowed', campaign_slug: 'save-the-forest')
|
|
27
|
+
|
|
28
|
+
assert_requested(stub_patch_prefill_forms)
|
|
29
|
+
expect(result).to be_truthy
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should update the prefill forms state including UTM parameters' do
|
|
33
|
+
utm_params = {
|
|
34
|
+
utm_campaign: 'a campaign',
|
|
35
|
+
utm_content: 'a content',
|
|
36
|
+
utm_medium: 'a medium',
|
|
37
|
+
utm_source: 'a source',
|
|
38
|
+
utm_term: 'a term',
|
|
39
|
+
utm_placement: 'a placement',
|
|
40
|
+
utm_target: 'a target'
|
|
41
|
+
}
|
|
42
|
+
stub_patch_prefill_forms = stub_request(:patch, "https://test.com/v1/prefill_forms?account_id=#{account_id}")
|
|
43
|
+
.with(body: {
|
|
44
|
+
prefill_forms: {
|
|
45
|
+
state: 'allowed',
|
|
46
|
+
slug: 'save-the-forest'
|
|
47
|
+
}.merge(utm_params)
|
|
48
|
+
})
|
|
49
|
+
.to_return(status: 204)
|
|
50
|
+
|
|
51
|
+
subject.update_prefill_forms(prefill_forms_state: 'allowed', campaign_slug: 'save-the-forest', **utm_params)
|
|
52
|
+
|
|
53
|
+
assert_requested(stub_patch_prefill_forms)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should escape special characters in account_id' do
|
|
57
|
+
unescaped_account_id = 'user@example.com'
|
|
58
|
+
escaped_account_id = 'user%40example.com'
|
|
59
|
+
|
|
60
|
+
prefill_forms = CampactUserService::PrefillForms.new(client, unescaped_account_id)
|
|
61
|
+
|
|
62
|
+
stub_patch_prefill_forms = stub_request(:patch, "https://test.com/v1/prefill_forms?account_id=#{escaped_account_id}")
|
|
63
|
+
.with(body: {
|
|
64
|
+
prefill_forms: {
|
|
65
|
+
state: 'allowed',
|
|
66
|
+
slug: 'save-the-forest'
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.to_return(status: 204)
|
|
70
|
+
|
|
71
|
+
prefill_forms.update_prefill_forms(prefill_forms_state: 'allowed', campaign_slug: 'save-the-forest')
|
|
72
|
+
|
|
73
|
+
assert_requested(stub_patch_prefill_forms)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
data/spec/session_spec.rb
CHANGED
|
@@ -7,13 +7,13 @@ describe CampactUserService::Session do
|
|
|
7
7
|
|
|
8
8
|
subject { CampactUserService::Session.new(client, session_id, session_cookie_name) }
|
|
9
9
|
|
|
10
|
-
describe '#
|
|
10
|
+
describe '#account_id' do
|
|
11
11
|
it 'should be present' do
|
|
12
12
|
stub_request(:get, 'https://test.com/v1/sessions')
|
|
13
13
|
.with(headers: {'Cookie' => "cus-session=#{session_id};"})
|
|
14
|
-
.to_return(body: {
|
|
14
|
+
.to_return(body: {account_id: '189b6864-d58a-4f49-8370-4ae0b854a40e'}.to_json)
|
|
15
15
|
|
|
16
|
-
expect(subject.
|
|
16
|
+
expect(subject.account_id).to eq('189b6864-d58a-4f49-8370-4ae0b854a40e')
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: campact_user_service
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ControlShift
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: rotp
|
|
@@ -226,18 +225,19 @@ files:
|
|
|
226
225
|
- lib/campact_user_service.rb
|
|
227
226
|
- lib/campact_user_service/account.rb
|
|
228
227
|
- lib/campact_user_service/client.rb
|
|
228
|
+
- lib/campact_user_service/prefill_forms.rb
|
|
229
229
|
- lib/campact_user_service/response_error.rb
|
|
230
230
|
- lib/campact_user_service/session.rb
|
|
231
231
|
- spec/account_spec.rb
|
|
232
232
|
- spec/campact_user_service_spec.rb
|
|
233
233
|
- spec/client_spec.rb
|
|
234
|
+
- spec/prefill_forms_spec.rb
|
|
234
235
|
- spec/session_spec.rb
|
|
235
236
|
- spec/spec_helper.rb
|
|
236
237
|
homepage: http://github.com/controlshift/campact_user_service
|
|
237
238
|
licenses:
|
|
238
239
|
- MIT
|
|
239
240
|
metadata: {}
|
|
240
|
-
post_install_message:
|
|
241
241
|
rdoc_options: []
|
|
242
242
|
require_paths:
|
|
243
243
|
- lib
|
|
@@ -252,8 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
252
252
|
- !ruby/object:Gem::Version
|
|
253
253
|
version: '0'
|
|
254
254
|
requirements: []
|
|
255
|
-
rubygems_version: 3.
|
|
256
|
-
signing_key:
|
|
255
|
+
rubygems_version: 3.6.9
|
|
257
256
|
specification_version: 4
|
|
258
257
|
summary: Ruby wrapper for Campact User Service
|
|
259
258
|
test_files: []
|