workarea-mail_chimp 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +15 -0
- data/.gitignore +55 -0
- data/.markdownlint.json +10 -0
- data/.rails-rubocop.yml +119 -0
- data/.rubocop.yml +8 -0
- data/.scss-lint.yml +188 -0
- data/CHANGELOG.md +244 -0
- data/Gemfile +9 -0
- data/README.md +115 -0
- data/Rakefile +53 -0
- data/app/assets/javascripts/workarea/storefront/mail_chimp/mail_chimp_tracking.js +15 -0
- data/app/controllers/workarea/storefront/application_controller.decorator +11 -0
- data/app/controllers/workarea/storefront/cart_items_controller.decorator +18 -0
- data/app/controllers/workarea/storefront/checkout/addresses_controller.decorator +13 -0
- data/app/controllers/workarea/storefront/checkout/shipping_controller.decorator +13 -0
- data/app/controllers/workarea/storefront/users/accounts_controller.decorator +37 -0
- data/app/models/workarea/catalog/product.decorator +7 -0
- data/app/models/workarea/mail_chimp/group.rb +39 -0
- data/app/models/workarea/mail_chimp/store.rb +26 -0
- data/app/models/workarea/order.decorator +9 -0
- data/app/models/workarea/user.decorator +31 -0
- data/app/services/workarea/mail_chimp/address.rb +28 -0
- data/app/services/workarea/mail_chimp/cart.rb +78 -0
- data/app/services/workarea/mail_chimp/order.rb +97 -0
- data/app/services/workarea/mail_chimp/product.rb +43 -0
- data/app/services/workarea/mail_chimp/variant.rb +43 -0
- data/app/view_models/workarea/storefront/user_view_model.decorator +16 -0
- data/app/views/workarea/storefront/mail_chimp/_ecommerce_javascript.html.haml +2 -0
- data/app/views/workarea/storefront/users/accounts/_edit.html.haml +12 -0
- data/app/views/workarea/storefront/users/accounts/_email_interests.html.haml +13 -0
- data/app/workers/workarea/mail_chimp/ecommerce/save_cart.rb +40 -0
- data/app/workers/workarea/mail_chimp/ecommerce/save_order.rb +31 -0
- data/app/workers/workarea/mail_chimp/ecommerce/save_product.rb +31 -0
- data/app/workers/workarea/mail_chimp/list_subscriber.rb +30 -0
- data/app/workers/workarea/mail_chimp/list_unsubscriber.rb +22 -0
- data/app/workers/workarea/mail_chimp/subscription_edit.rb +28 -0
- data/bin/rails +19 -0
- data/config/initializers/appends.rb +21 -0
- data/config/initializers/workarea.rb +14 -0
- data/config/locales/en.yml +15 -0
- data/lib/gibbon/request_decorator.rb +10 -0
- data/lib/integrations/workarea/mail_chimp/bogus_api_request.rb +30 -0
- data/lib/integrations/workarea/mail_chimp/bogus_gateway.rb +35 -0
- data/lib/integrations/workarea/mail_chimp/bogus_request.rb +78 -0
- data/lib/integrations/workarea/mail_chimp/gateway.rb +86 -0
- data/lib/integrations/workarea/mail_chimp/gateway/list.rb +47 -0
- data/lib/integrations/workarea/mail_chimp/gateway/members.rb +61 -0
- data/lib/integrations/workarea/mail_chimp/gateway/subscribe_argument_builder.rb +101 -0
- data/lib/tasks/mail_chimp.rake +71 -0
- data/lib/workarea/mail_chimp.rb +72 -0
- data/lib/workarea/mail_chimp/engine.rb +14 -0
- data/lib/workarea/mail_chimp/errors.rb +2 -0
- data/lib/workarea/mail_chimp/tasks/ecommerce.rb +43 -0
- data/lib/workarea/mail_chimp/version.rb +5 -0
- data/script/admin_ci +9 -0
- data/script/ci +11 -0
- data/script/core_ci +9 -0
- data/script/plugins_ci +9 -0
- data/script/storefront_ci +9 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +56 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/factories/mail_chimp.rb +50 -0
- data/test/integration/workarea/mailchimp/subscription_test.rb +52 -0
- data/test/integration/workarea/mailchimp/tracking_params_test.rb +50 -0
- data/test/integration/workarea/mailchimp/unsubscribe_test.rb +14 -0
- data/test/integration/workarea/storefront/mail_chimp_order_test.rb +106 -0
- data/test/integration/workarea/storefront/mail_chimp_product_test.rb +51 -0
- data/test/integration/workarea/storefront/mail_chimp_site_javascript_test.rb +25 -0
- data/test/lib/workarea/mailchimp/gateway/list_test.rb +48 -0
- data/test/lib/workarea/mailchimp/gateway_test.rb +196 -0
- data/test/lib/workarea/mailchimp/tasks/ecommerce_test.rb +40 -0
- data/test/services/workarea/mail_chimp/cart_test.rb +44 -0
- data/test/services/workarea/mail_chimp/order_test.rb +50 -0
- data/test/services/workarea/mail_chimp/product_test.rb +29 -0
- data/test/support/workarea/mail_chimp_api_config.rb +33 -0
- data/test/system/workarea/storefront/campaign_tracking_test.rb +14 -0
- data/test/system/workarea/storefront/group_test.rb +33 -0
- data/test/system/workarea/storefront/mail_chimp_accounts_system_test.rb +79 -0
- data/test/test_helper.rb +17 -0
- data/test/vcr_cassettes/get_default_list_interests.yml +104 -0
- data/test/vcr_cassettes/get_member_details_no_match.yml +51 -0
- data/test/vcr_cassettes/get_member_details_unsubscribed.yml +51 -0
- data/test/vcr_cassettes/interest_categories_read.yml +104 -0
- data/test/vcr_cassettes/mail_chimp/tasks/create_store-successful.yml +97 -0
- data/test/vcr_cassettes/mc_order_test.yml +381 -0
- data/test/vcr_cassettes/mc_product_test.yml +234 -0
- data/test/vcr_cassettes/subscribe_to_default_list.yml +254 -0
- data/test/vcr_cassettes/subscribe_to_default_list_interest_groups.yml +254 -0
- data/test/vcr_cassettes/subscribe_to_default_list_with_groupings.yml +254 -0
- data/test/vcr_cassettes/subscribe_to_default_list_with_user_details.yml +254 -0
- data/test/vcr_cassettes/unsubscribe_from_default_list.yml +53 -0
- data/test/vcr_cassettes/update_member_on_default_list_change_email.yml +254 -0
- data/test/vcr_cassettes/update_member_on_default_list_change_groupings.yml +254 -0
- data/test/workers/workarea/mail_chimp/ecommerce/save_cart_test.rb +28 -0
- data/test/workers/workarea/mail_chimp/ecommerce/save_order_test.rb +15 -0
- data/test/workers/workarea/mail_chimp/ecommerce/save_product_test.rb +15 -0
- data/workarea-mail_chimp.gemspec +20 -0
- metadata +212 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class MailChimpSiteJavascriptTest < Workarea::IntegrationTest
|
6
|
+
def test_connected_site_javascript
|
7
|
+
Workarea.with_config do |config|
|
8
|
+
config.mail_chimp.default_store = {
|
9
|
+
id: "qa_dummy_store_9",
|
10
|
+
list_id: "dd8f83a09e",
|
11
|
+
name: "QA dummy store 4",
|
12
|
+
email_address: "jyucis@weblinc.com",
|
13
|
+
domain: 'https://plugins-qa.demo.workarea.com/',
|
14
|
+
currency_code: "USD"
|
15
|
+
}
|
16
|
+
store = create_mail_chimp_store.reload
|
17
|
+
|
18
|
+
get storefront.root_path
|
19
|
+
|
20
|
+
assert_includes response.body, store.site_script_fragment
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module MailChimp
|
5
|
+
class Gateway::ListTest < Workarea::SystemTest
|
6
|
+
include Workarea::MailChimpApiConfig
|
7
|
+
|
8
|
+
setup :gateway
|
9
|
+
|
10
|
+
def gateway
|
11
|
+
@gateway ||= Workarea::MailChimp.gateway
|
12
|
+
end
|
13
|
+
|
14
|
+
def vcr_args
|
15
|
+
@vcr_args ||= { record: :once, match_requests_on: [:method, :uri, :body] }
|
16
|
+
end
|
17
|
+
|
18
|
+
def user
|
19
|
+
@user ||= Workarea::User.new(
|
20
|
+
id: "1",
|
21
|
+
first_name: "Michael",
|
22
|
+
last_name: "Dalton",
|
23
|
+
groups: []
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_interests_when_looking_up_all_interest_groups
|
28
|
+
Workarea.with_config do |config|
|
29
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
30
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
31
|
+
|
32
|
+
response = VCR.use_cassette("interest_categories_read", vcr_args) do
|
33
|
+
@gateway.interests
|
34
|
+
end
|
35
|
+
|
36
|
+
# It behaves like a successful MailChimp API call
|
37
|
+
assert(response)
|
38
|
+
|
39
|
+
if response.is_a? Hash
|
40
|
+
refute(response.key?("error"))
|
41
|
+
end
|
42
|
+
|
43
|
+
assert(response.first.is_a?(Workarea::MailChimp::Group))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class Workarea::MailChimp::GatewayTest < Workarea::SystemTest
|
4
|
+
include Workarea::MailChimpApiConfig
|
5
|
+
|
6
|
+
setup :gateway
|
7
|
+
|
8
|
+
def gateway
|
9
|
+
@gateway ||= Workarea::MailChimp.gateway
|
10
|
+
end
|
11
|
+
|
12
|
+
def vcr_args
|
13
|
+
@vcr_args ||= { record: :once, match_requests_on: [:method, :uri, :body] }
|
14
|
+
end
|
15
|
+
|
16
|
+
def user
|
17
|
+
@user ||= Workarea::User.new(
|
18
|
+
id: "1",
|
19
|
+
first_name: "Michael",
|
20
|
+
last_name: "Dalton",
|
21
|
+
groups: []
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_new_subscriptions_when_subscribing_with_just_an_email_address
|
26
|
+
Workarea.with_config do |config|
|
27
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
28
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
29
|
+
|
30
|
+
email = "jyucis-mailchimp@workarea.com"
|
31
|
+
|
32
|
+
response = VCR.use_cassette("subscribe_to_default_list", vcr_args) do
|
33
|
+
@gateway.subscribe email
|
34
|
+
end
|
35
|
+
|
36
|
+
assert(response)
|
37
|
+
|
38
|
+
if response.is_a? Hash
|
39
|
+
refute(response.key?("error"))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_subscribing_with_just_an_email_address_adds_all_interest_groups
|
45
|
+
Workarea.with_config do |config|
|
46
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
47
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
48
|
+
|
49
|
+
email = "jyucis-mailchimp@workarea.com"
|
50
|
+
|
51
|
+
response = VCR.use_cassette("subscribe_to_default_list_interest_groups", vcr_args) do
|
52
|
+
@gateway.subscribe email
|
53
|
+
end
|
54
|
+
|
55
|
+
assert(response.body["interests"].present?)
|
56
|
+
assert(response.body["interests"].length == 4)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_new_subscriptions_when_subscribing_with_an_email_address_and_user_details
|
61
|
+
Workarea.with_config do |config|
|
62
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
63
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
64
|
+
|
65
|
+
email = "jyucis-mailchimp-2@workarea.com"
|
66
|
+
|
67
|
+
response = VCR.use_cassette("subscribe_to_default_list_with_user_details", vcr_args) do
|
68
|
+
@gateway.subscribe email, user: user
|
69
|
+
end
|
70
|
+
|
71
|
+
assert(response)
|
72
|
+
|
73
|
+
if response.is_a? Hash
|
74
|
+
refute(response.key?("error"))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_new_subscriptions_when_subscribing_with_an_email_address_and_groupings
|
80
|
+
Workarea.with_config do |config|
|
81
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
82
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
83
|
+
|
84
|
+
email = "jyucis-mailchimp-3@workarea.com"
|
85
|
+
|
86
|
+
response = VCR.use_cassette("subscribe_to_default_list_with_groupings", vcr_args) do
|
87
|
+
@gateway.subscribe email, user: user
|
88
|
+
end
|
89
|
+
|
90
|
+
assert(response)
|
91
|
+
|
92
|
+
if response.is_a? Hash
|
93
|
+
refute(response.key?("error"))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_udpates_to_subscriptions_when_updating_email_address
|
99
|
+
Workarea.with_config do |config|
|
100
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
101
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
102
|
+
|
103
|
+
current_email = "jyucis-mailchimp-2@workarea.com"
|
104
|
+
new_email = "jyucis-mailchimp-4@workarea.com"
|
105
|
+
|
106
|
+
response = VCR.use_cassette("update_member_on_default_list_change_email", vcr_args) do
|
107
|
+
@gateway.subscribe current_email, new_email: new_email
|
108
|
+
end
|
109
|
+
|
110
|
+
assert(response)
|
111
|
+
|
112
|
+
if response.is_a? Hash
|
113
|
+
refute(response.key?("error"))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_udpates_to_subscriptions_when_udpating_groupings
|
119
|
+
Workarea.with_config do |config|
|
120
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
121
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
122
|
+
|
123
|
+
email = "jyucis-mailchimp-3@workarea.com"
|
124
|
+
|
125
|
+
response = VCR.use_cassette("update_member_on_default_list_change_groupings", vcr_args) do
|
126
|
+
@gateway.subscribe email, user: user
|
127
|
+
end
|
128
|
+
|
129
|
+
assert(response)
|
130
|
+
|
131
|
+
if response.is_a? Hash
|
132
|
+
refute(response.key?("error"))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_unsubscribe_from_default_list
|
138
|
+
Workarea.with_config do |config|
|
139
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
140
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
141
|
+
|
142
|
+
email = "jyucis-mailchimp@workarea.com"
|
143
|
+
|
144
|
+
response = VCR.use_cassette("unsubscribe_from_default_list", vcr_args) do
|
145
|
+
@gateway.unsubscribe email
|
146
|
+
end
|
147
|
+
|
148
|
+
assert(response)
|
149
|
+
|
150
|
+
if response.is_a? Hash
|
151
|
+
refute(response.key?("error"))
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_list_returns_groups
|
157
|
+
Workarea.with_config do |config|
|
158
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
159
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
160
|
+
|
161
|
+
groups = [Workarea::MailChimp::Group.new(email_all_interests_hash)]
|
162
|
+
|
163
|
+
response = VCR.use_cassette("get_default_list_interests", vcr_args) do
|
164
|
+
@gateway.list.interests
|
165
|
+
end
|
166
|
+
|
167
|
+
assert_match(groups.first[:name], response.first[:name])
|
168
|
+
|
169
|
+
assert_match(groups.first[:interests]["7ca6cc1d86"], response.first[:interests]["7ca6cc1d86"])
|
170
|
+
assert_match(groups.first[:interests]["8911545594"], response.first[:interests]["8911545594"])
|
171
|
+
assert_match(groups.first[:interests]["542a7ec7bb"], response.first[:interests]["542a7ec7bb"])
|
172
|
+
assert_match(groups.first[:interests]["6908d70674"], response.first[:interests]["6908d70674"])
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_get_member_details_returns_nil_when_email_does_not_exist_in_mailchimp
|
177
|
+
Workarea.with_config do |config|
|
178
|
+
config.mail_chimp.default_list_id = 'fcd2925136'
|
179
|
+
config.mail_chimp.email_interests_id = '443f5598e4'
|
180
|
+
|
181
|
+
response = VCR.use_cassette("get_member_details_no_match", vcr_args) do
|
182
|
+
@gateway.members.details("mdalton-doesnotexist@workarea.com")
|
183
|
+
end
|
184
|
+
|
185
|
+
assert_nil(response)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_get_member_details_returns_nil_when_email_has_unsubscribed_in_mailchimp
|
190
|
+
response = VCR.use_cassette("get_member_details_unsubscribed", vcr_args) do
|
191
|
+
@gateway.members.details("test-unsubscribed@workarea.com")
|
192
|
+
end
|
193
|
+
|
194
|
+
assert_nil(response)
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'workarea/mail_chimp/tasks/ecommerce'
|
3
|
+
|
4
|
+
module Workarea
|
5
|
+
module MailChimp
|
6
|
+
module Tasks
|
7
|
+
class EcommerceTest < Workarea::TestCase
|
8
|
+
include Workarea::MailChimpApiConfig
|
9
|
+
|
10
|
+
setup :setup_mail_chimp_config
|
11
|
+
teardown :reset_mail_chimp_config
|
12
|
+
|
13
|
+
def test_create_store
|
14
|
+
_response = VCR.use_cassette("mail_chimp/tasks/create_store-successful", vcr_args) do
|
15
|
+
MailChimp::Tasks::Ecommerce.create_store
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def setup_mail_chimp_config
|
22
|
+
@_old_config = Workarea.config.mail_chimp
|
23
|
+
|
24
|
+
Workarea.config.mail_chimp.default_store = {
|
25
|
+
id: "qa_dummy_store_9",
|
26
|
+
list_id: "fcd2925136",
|
27
|
+
name: "QA dummy store 9",
|
28
|
+
email_address: "jyucis@weblinc.com",
|
29
|
+
domain: 'https://plugins-qa.demo.workarea.com',
|
30
|
+
currency_code: "USD"
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def reset_mail_chimp_config
|
35
|
+
Workarea.config.mail_chimp = @_old_config
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module MailChimp
|
5
|
+
class CartTest < Workarea::TestCase
|
6
|
+
def test_to_h
|
7
|
+
order = create_placed_order
|
8
|
+
hsh = Cart.new(order, send_full_customer: true).to_h
|
9
|
+
|
10
|
+
assert_equal(order.id, hsh[:id])
|
11
|
+
assert_equal("USD", hsh[:currency_code])
|
12
|
+
assert_equal("11.00", hsh[:order_total])
|
13
|
+
assert_equal("1.00", hsh[:shipping_total])
|
14
|
+
assert_equal(1, hsh[:lines].size)
|
15
|
+
assert_equal(2, hsh[:lines].first[:quantity])
|
16
|
+
assert_equal("SKU", hsh[:lines].first[:product_variant_id])
|
17
|
+
assert_equal(expected_new_customer_hash, hsh[:customer])
|
18
|
+
|
19
|
+
assert_equal("http://www.example.com/cart/resume/#{order.token}", hsh[:checkout_url])
|
20
|
+
|
21
|
+
hsh = Cart.new(order, send_full_customer: false).to_h
|
22
|
+
assert_equal(expected_existing_customer_hash, hsh[:customer])
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def expected_new_customer_hash
|
28
|
+
{
|
29
|
+
id: Digest::MD5.hexdigest("bcrouse-new@workarea.com"),
|
30
|
+
email_address: "bcrouse-new@workarea.com",
|
31
|
+
opt_in_status: false,
|
32
|
+
first_name: "Ben",
|
33
|
+
last_name: "Crouse"
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def expected_existing_customer_hash
|
38
|
+
{
|
39
|
+
id: Digest::MD5.hexdigest("bcrouse-new@workarea.com")
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module MailChimp
|
5
|
+
class OrderTest < Workarea::TestCase
|
6
|
+
def test_to_h
|
7
|
+
order = create_placed_order
|
8
|
+
hsh = Order.new(order).to_h
|
9
|
+
|
10
|
+
assert_equal(order.id, hsh[:id])
|
11
|
+
assert_equal("USD", hsh[:currency_code])
|
12
|
+
assert_equal("11.00", hsh[:order_total])
|
13
|
+
assert_equal("1.00", hsh[:shipping_total])
|
14
|
+
assert_equal(1, hsh[:lines].size)
|
15
|
+
assert_equal(2, hsh[:lines].first[:quantity])
|
16
|
+
assert_equal("SKU", hsh[:lines].first[:product_variant_id])
|
17
|
+
assert_equal(expected_address_hash, hsh[:shipping_address])
|
18
|
+
assert_equal(expected_address_hash, hsh[:billing_address])
|
19
|
+
assert_equal(expected_customer_hash, hsh[:customer])
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def expected_address_hash
|
24
|
+
{
|
25
|
+
name:"Ben Crouse",
|
26
|
+
address1:"22 S. 3rd St.",
|
27
|
+
address2:"Second Floor",
|
28
|
+
city:"Philadelphia",
|
29
|
+
province:"PA",
|
30
|
+
postal_code:"19106",
|
31
|
+
country:"US",
|
32
|
+
phone:"",
|
33
|
+
company:""
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def expected_customer_hash
|
38
|
+
{
|
39
|
+
id: Digest::MD5.hexdigest("bcrouse-new@workarea.com"),
|
40
|
+
email_address: "bcrouse-new@workarea.com",
|
41
|
+
opt_in_status: false,
|
42
|
+
orders_count: 1,
|
43
|
+
total_spent: "11.00",
|
44
|
+
first_name: "Ben",
|
45
|
+
last_name: "Crouse"
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module MailChimp
|
5
|
+
class ProductTest < Workarea::TestCase
|
6
|
+
def test_to_h
|
7
|
+
product = create_product(id: "32F5411045")
|
8
|
+
hsh = Product.new(product).to_h
|
9
|
+
|
10
|
+
assert_equal(product.id, hsh[:id])
|
11
|
+
assert_equal(product.name, hsh[:title])
|
12
|
+
assert_equal(1, hsh[:variants].size)
|
13
|
+
assert_equal(expected_variant_hash, hsh[:variants].first)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def expected_variant_hash
|
18
|
+
{
|
19
|
+
id: "SKU",
|
20
|
+
title: "SKU",
|
21
|
+
sku: "SKU",
|
22
|
+
price: "5.0",
|
23
|
+
inventory_quantity: 99999,
|
24
|
+
visibility: "true"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Workarea
|
2
|
+
module MailChimpApiConfig
|
3
|
+
def self.included(test)
|
4
|
+
super
|
5
|
+
test.setup :set_key
|
6
|
+
test.teardown :reset_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_key
|
10
|
+
Rails.application.secrets.mail_chimp = { api_key: 'a' }
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset_key
|
14
|
+
Rails.application.secrets.delete(:mail_chimp)
|
15
|
+
end
|
16
|
+
|
17
|
+
def vcr_args
|
18
|
+
@vcr_args ||= { record: :once, match_requests_on: [:method, :uri] }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def test_store_params
|
24
|
+
{
|
25
|
+
id: "test_store_1",
|
26
|
+
list_id: "fcd2925136",
|
27
|
+
name: "test_store_1",
|
28
|
+
email_address: "jyucis@weblinc.com",
|
29
|
+
currency_code: "USD"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|