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,14 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json]
|
9
|
+
end
|
10
|
+
|
11
|
+
# To enable root element in JSON for ActiveRecord objects.
|
12
|
+
# ActiveSupport.on_load(:active_record) do
|
13
|
+
# self.include_root_in_json = true
|
14
|
+
# end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Puma can serve each request in a thread from an internal thread pool.
|
2
|
+
# The `threads` method setting takes two numbers a minimum and maximum.
|
3
|
+
# Any libraries that use thread pools should be configured to match
|
4
|
+
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
5
|
+
# and maximum, this matches the default thread size of Active Record.
|
6
|
+
#
|
7
|
+
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
|
8
|
+
threads threads_count, threads_count
|
9
|
+
|
10
|
+
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
|
11
|
+
#
|
12
|
+
port ENV.fetch("PORT") { 3000 }
|
13
|
+
|
14
|
+
# Specifies the `environment` that Puma will run in.
|
15
|
+
#
|
16
|
+
environment ENV.fetch("RAILS_ENV") { "development" }
|
17
|
+
|
18
|
+
# Specifies the number of `workers` to boot in clustered mode.
|
19
|
+
# Workers are forked webserver processes. If using threads and workers together
|
20
|
+
# the concurrency of the application would be max `threads` * `workers`.
|
21
|
+
# Workers do not work on JRuby or Windows (both of which do not support
|
22
|
+
# processes).
|
23
|
+
#
|
24
|
+
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
25
|
+
|
26
|
+
# Use the `preload_app!` method when specifying a `workers` number.
|
27
|
+
# This directive tells Puma to first boot the application and load code
|
28
|
+
# before forking the application. This takes advantage of Copy On Write
|
29
|
+
# process behavior so workers use less memory. If you use this option
|
30
|
+
# you need to make sure to reconnect any threads in the `on_worker_boot`
|
31
|
+
# block.
|
32
|
+
#
|
33
|
+
# preload_app!
|
34
|
+
|
35
|
+
# The code in the `on_worker_boot` will be called if you are using
|
36
|
+
# clustered mode by specifying a number of `workers`. After each worker
|
37
|
+
# process is booted this block will be run, if you are using `preload_app!`
|
38
|
+
# option you will want to use this block to reconnect to any threads
|
39
|
+
# or connections that may have been created at application boot, Ruby
|
40
|
+
# cannot share connections between processes.
|
41
|
+
#
|
42
|
+
# on_worker_boot do
|
43
|
+
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
|
44
|
+
# end
|
45
|
+
|
46
|
+
# Allow puma to be restarted by `rails restart` command.
|
47
|
+
plugin :tmp_restart
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rails secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: e3136ca2a4ab2bb5ea181b14ff500ae40db8718fb990d590bfed3774247d430c805c45686322f93e8a746d034fa1fba9ef00a9ce7a35aee9339675ccb0426121
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 8183e0351525142fce68cf619e94c68caa017c9b90c03183d288ee4a32283d77838eb94bc252e5159eabf3e20a77f8df9466b5056e14b59631dfa592b67e9bbd
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Factories
|
3
|
+
module MailChimp
|
4
|
+
Factories.add(self)
|
5
|
+
|
6
|
+
DEFAULT_INTERESTS = {
|
7
|
+
"0eec3f3c22" => "Local Events",
|
8
|
+
"0ade920a8e" => "Restaurant News and Events"
|
9
|
+
}
|
10
|
+
|
11
|
+
def email_interest_hash
|
12
|
+
{ _id: "2df74daed4", name: "Email Interests", interests: { "b5358c7791" => "Specials and Promotions" } }
|
13
|
+
end
|
14
|
+
|
15
|
+
def email_interests_hash(interests = DEFAULT_INTERESTS)
|
16
|
+
{ _id: "2df74daed4", name: "Email Interests", interests: interests }
|
17
|
+
end
|
18
|
+
|
19
|
+
def email_all_interests_hash
|
20
|
+
{
|
21
|
+
_id: "443f5598e4",
|
22
|
+
name: "Email Interests",
|
23
|
+
interests: {
|
24
|
+
"7ca6cc1d86" => "Specials and Promotions",
|
25
|
+
"8911545594" => "Local Events",
|
26
|
+
"542a7ec7bb" => "Restaurant News and Events",
|
27
|
+
"6908d70674" => "Corporate Gifts and Awards"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_mail_chimp_store(overrides = {})
|
33
|
+
attributes = {
|
34
|
+
mail_chimp_id: "qa_dummy_store_9",
|
35
|
+
list_id: "fcd2925136",
|
36
|
+
name: "QA dummy store 9",
|
37
|
+
currency_code: "USD",
|
38
|
+
connected_site: {
|
39
|
+
site_foreign_id: "qa_dummy_store_9",
|
40
|
+
site_script: {
|
41
|
+
url: "https://chimpstatic.com/mcjs-connected/js/users/c40efe870eb1bc94745f06b1b/e89d077f314d14abffa7a031b.js",
|
42
|
+
fragment: "<script id=\"mcjs\">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,\"script\",\"https://chimpstatic.com/mcjs-connected/js/users/c40efe870eb1bc94745f06b1b/e89d077f314d14abffa7a031b.js\");</script>"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}.merge overrides
|
46
|
+
Workarea::MailChimp::Store.create attributes
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class MailChimp::SubscriptionTest < Workarea::IntegrationTest
|
5
|
+
setup :users
|
6
|
+
|
7
|
+
def users
|
8
|
+
@user ||= create_user
|
9
|
+
@user.update_attributes(email_signup: true)
|
10
|
+
@user
|
11
|
+
end
|
12
|
+
|
13
|
+
def updated_params
|
14
|
+
@updated_params ||= { groups: [email_interests_hash] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_groups_is_set_to_default_groups
|
18
|
+
assert_equal(User.default_groups, users.groups)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_groups_is_not_set_to_default_groups_when_groups_are_set
|
22
|
+
groups = [Workarea::MailChimp::Group.new(email_interests_hash)]
|
23
|
+
users.update_attributes(groups: groups)
|
24
|
+
|
25
|
+
assert_equal(groups, users.groups)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_group_updated_when_group_exists
|
29
|
+
params = { groups: [email_interests_hash] }
|
30
|
+
group = Workarea::MailChimp::Group.new(params[:groups].first)
|
31
|
+
updated_group = Workarea::MailChimp::Group.new(updated_params[:groups].first)
|
32
|
+
users.update_attributes(params)
|
33
|
+
|
34
|
+
assert_equal(users.groups[0], group)
|
35
|
+
users.update_attributes(updated_params)
|
36
|
+
assert_equal(users.groups[0], updated_group)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_user_email_signup_true_when_email_signup_exists_with_matching_email_address
|
40
|
+
user_email = "mailchimp-test@weblinc.com"
|
41
|
+
Email::Signup.new(email: user_email).save
|
42
|
+
|
43
|
+
post storefront.users_account_path,
|
44
|
+
params: {
|
45
|
+
email: user_email,
|
46
|
+
password: "W3bl1nc!"
|
47
|
+
}
|
48
|
+
|
49
|
+
assert(User.find_by(email: user_email).email_signup?)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class MailChimp::SubscriptionTest < Workarea::IntegrationTest
|
5
|
+
setup :set_inventory
|
6
|
+
setup :set_product
|
7
|
+
|
8
|
+
def set_inventory
|
9
|
+
@inventory = create_inventory(
|
10
|
+
id: 'SKU1',
|
11
|
+
policy: 'standard',
|
12
|
+
available: 2
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_product
|
17
|
+
@product = create_product(
|
18
|
+
name: 'Integration Product',
|
19
|
+
variants: [
|
20
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
21
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
22
|
+
]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def order
|
27
|
+
Order.first
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_campaign_id_saved_on_add_to_cart
|
31
|
+
campaign_id = 'campaign_id_1'
|
32
|
+
|
33
|
+
cookies['mc_cid'] = campaign_id
|
34
|
+
|
35
|
+
get storefront.root_path, params: { mc_cid: campaign_id }
|
36
|
+
|
37
|
+
post storefront.cart_items_path,
|
38
|
+
params: {
|
39
|
+
product_id: @product.id,
|
40
|
+
sku: @product.skus.first,
|
41
|
+
quantity: 1
|
42
|
+
}
|
43
|
+
|
44
|
+
assert(response.ok?)
|
45
|
+
|
46
|
+
order.reload
|
47
|
+
assert_equal(campaign_id, order.mail_chimp_campaign_id)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class MailChimp::SubscriptionTest < Workarea::IntegrationTest
|
5
|
+
def test_unsubscribe
|
6
|
+
set_current_user(
|
7
|
+
create_user(email: "bcrouse@workarea.com", password: "w3bl1nc", email_signup: true)
|
8
|
+
)
|
9
|
+
|
10
|
+
patch storefront.users_account_path, params: { email_signup: false }
|
11
|
+
refute(Email.signed_up?("bcrouse@workarea.com"))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class MailChimpOrderTest < Workarea::IntegrationTest
|
6
|
+
include Workarea::MailChimpApiConfig
|
7
|
+
|
8
|
+
def set_inventory
|
9
|
+
@inventory = create_inventory(
|
10
|
+
id: 'SKU1',
|
11
|
+
policy: 'standard',
|
12
|
+
available: 2
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_product
|
17
|
+
@product = create_product(
|
18
|
+
name: 'MC Integration Product',
|
19
|
+
id: 'mc_p_12345',
|
20
|
+
variants: [
|
21
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
22
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
23
|
+
]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_place_mc_order
|
28
|
+
attributes = {
|
29
|
+
id: 'mc_1234',
|
30
|
+
email: 'bcrouse-new@workarea.com',
|
31
|
+
placed_at: Time.current
|
32
|
+
}
|
33
|
+
|
34
|
+
shipping_service = create_shipping_service
|
35
|
+
|
36
|
+
order = Workarea::Order.new(attributes)
|
37
|
+
order.add_item(product_id: 'mc_p_12345', sku: 'SKU1', quantity: 2)
|
38
|
+
|
39
|
+
checkout = Workarea::Checkout.new(order)
|
40
|
+
checkout.update(
|
41
|
+
shipping_address: {
|
42
|
+
first_name: 'Ben',
|
43
|
+
last_name: 'Crouse',
|
44
|
+
street: '22 S. 3rd St.',
|
45
|
+
street_2: 'Second Floor',
|
46
|
+
city: 'Philadelphia',
|
47
|
+
region: 'PA',
|
48
|
+
postal_code: '19106',
|
49
|
+
country: 'US'
|
50
|
+
},
|
51
|
+
billing_address: {
|
52
|
+
first_name: 'Ben',
|
53
|
+
last_name: 'Crouse',
|
54
|
+
street: '22 S. 3rd St.',
|
55
|
+
street_2: 'Second Floor',
|
56
|
+
city: 'Philadelphia',
|
57
|
+
region: 'PA',
|
58
|
+
postal_code: '19106',
|
59
|
+
country: 'US'
|
60
|
+
},
|
61
|
+
shipping_service: shipping_service.name,
|
62
|
+
payment: 'new_card',
|
63
|
+
credit_card: {
|
64
|
+
number: '1',
|
65
|
+
month: '1',
|
66
|
+
year: Time.current.year + 1,
|
67
|
+
cvv: '999'
|
68
|
+
}
|
69
|
+
)
|
70
|
+
|
71
|
+
unless checkout.place_order
|
72
|
+
raise(
|
73
|
+
UnplacedOrderError,
|
74
|
+
'failed placing the order in the create_placed_order factory'
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
order
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_product_created_in_mailchimp
|
82
|
+
Workarea.with_config do |config|
|
83
|
+
config.mail_chimp.default_store = test_store_params
|
84
|
+
|
85
|
+
VCR.use_cassette("mc_order_test", vcr_args) do
|
86
|
+
Workarea::MailChimp.request.ecommerce.stores.create(body: test_store_params) rescue nil
|
87
|
+
|
88
|
+
set_inventory
|
89
|
+
set_product
|
90
|
+
order = create_place_mc_order
|
91
|
+
|
92
|
+
# check product was created
|
93
|
+
mc_order = Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).orders(order.id.to_s).retrieve
|
94
|
+
assert_equal(order.id, mc_order.body["id"])
|
95
|
+
|
96
|
+
# cleanup the order, proudct and store
|
97
|
+
Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).products(@product.id.to_s).delete
|
98
|
+
Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).orders(order.id.to_s).delete
|
99
|
+
Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).delete
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Storefront
|
5
|
+
class MailChimpProductTest < Workarea::IntegrationTest
|
6
|
+
include Workarea::MailChimpApiConfig
|
7
|
+
|
8
|
+
def set_inventory
|
9
|
+
@inventory = create_inventory(
|
10
|
+
id: 'SKU1',
|
11
|
+
policy: 'standard',
|
12
|
+
available: 2
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_product
|
17
|
+
@product = create_product(
|
18
|
+
name: 'MC Integration Product',
|
19
|
+
id: 'mc_p_12345',
|
20
|
+
variants: [
|
21
|
+
{ sku: 'SKU1', regular: 5.to_m },
|
22
|
+
{ sku: 'SKU2', regular: 6.to_m }
|
23
|
+
]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def test_product_created_in_mailchimp
|
29
|
+
Workarea.with_config do |config|
|
30
|
+
config.mail_chimp.default_store = test_store_params
|
31
|
+
|
32
|
+
VCR.use_cassette("mc_product_test", vcr_args) do
|
33
|
+
Workarea::MailChimp.request.ecommerce.stores.create(body: test_store_params) rescue nil
|
34
|
+
|
35
|
+
set_inventory
|
36
|
+
set_product
|
37
|
+
|
38
|
+
# check product was created
|
39
|
+
mc_product = Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).products(@product.id.to_s).retrieve
|
40
|
+
assert_equal(@product.id, mc_product.body["id"])
|
41
|
+
|
42
|
+
# cleanup the order and product
|
43
|
+
Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).products(@product.id.to_s).delete
|
44
|
+
Workarea::MailChimp.request.ecommerce.stores(test_store_params[:id]).delete
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|