workarea-listrak 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.eslintrc.json +36 -0
- data/.esvmrc +5 -0
- data/.gitignore +32 -0
- data/CHANGELOG.md +322 -0
- data/Gemfile +14 -0
- data/README.md +130 -0
- data/Rakefile +53 -0
- data/app/assets/javascripts/workarea/admin/modules/listrak/list_events_select.js +83 -0
- data/app/assets/javascripts/workarea/storefront/listrak/adapters/listrak_adapter.js +110 -0
- data/app/assets/javascripts/workarea/storefront/listrak/listrak_config.js.erb +13 -0
- data/app/assets/javascripts/workarea/storefront/listrak/modules/listrak.js +64 -0
- data/app/controllers/workarea/admin/listrak/configurations_controller.rb +30 -0
- data/app/controllers/workarea/admin/listrak/events_controller.rb +17 -0
- data/app/helpers/workarea/listrak/analytics/helper.rb +44 -0
- data/app/models/workarea/listrak/configuration.rb +19 -0
- data/app/queries/workarea/categorization.decorator +7 -0
- data/app/services/workarea/listrak/data_api/customers.rb +26 -0
- data/app/services/workarea/listrak/data_api/orders.rb +26 -0
- data/app/services/workarea/listrak/data_api/products.rb +26 -0
- data/app/services/workarea/listrak/data_api.rb +63 -0
- data/app/services/workarea/listrak/email_api/contacts.rb +73 -0
- data/app/services/workarea/listrak/email_api/events.rb +44 -0
- data/app/services/workarea/listrak/email_api/lists.rb +21 -0
- data/app/services/workarea/listrak/email_api/messages.rb +50 -0
- data/app/services/workarea/listrak/email_api/transactional_messages.rb +32 -0
- data/app/services/workarea/listrak/email_api.rb +71 -0
- data/app/services/workarea/listrak/models/address.rb +83 -0
- data/app/services/workarea/listrak/models/contact.rb +67 -0
- data/app/services/workarea/listrak/models/contact_form.rb +24 -0
- data/app/services/workarea/listrak/models/customer_form.rb +209 -0
- data/app/services/workarea/listrak/models/event.rb +45 -0
- data/app/services/workarea/listrak/models/event_form.rb +25 -0
- data/app/services/workarea/listrak/models/list.rb +204 -0
- data/app/services/workarea/listrak/models/message_form.rb +147 -0
- data/app/services/workarea/listrak/models/order_form.rb +352 -0
- data/app/services/workarea/listrak/models/order_item.rb +197 -0
- data/app/services/workarea/listrak/models/product_form.rb +369 -0
- data/app/services/workarea/listrak/models/transactional_message_form.rb +21 -0
- data/app/services/workarea/listrak/oauth.rb +45 -0
- data/app/services/workarea/listrak/transactional_message.rb +83 -0
- data/app/view_models/workarea/admin/listrak_configuration_view_model.rb +17 -0
- data/app/views/workarea/admin/listrak/configurations/edit.html.haml +28 -0
- data/app/views/workarea/admin/listrak/events/index.json.jbuilder +4 -0
- data/app/views/workarea/admin/shared/_listrak_configuration_link.html.haml +1 -0
- data/app/views/workarea/storefront/checkouts/_listrak.html.haml +2 -0
- data/app/workers/workarea/listrak/customer_exporter.rb +22 -0
- data/app/workers/workarea/listrak/order_exporter.rb +22 -0
- data/app/workers/workarea/listrak/product_exporter.rb +50 -0
- data/app/workers/workarea/listrak/subscribe_email_signup.rb +34 -0
- data/app/workers/workarea/listrak/unsubscribe_email_signup.rb +27 -0
- data/bin/rails +18 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/rubocop +16 -0
- data/config/initializers/append_points.rb +28 -0
- data/config/initializers/configuration.rb +8 -0
- data/config/locales/en.yml +17 -0
- data/config/routes.rb +10 -0
- data/docs/Listrak Technical Integration Guide.docx +0 -0
- data/lib/generators/workarea/listrak/message/USAGE +9 -0
- data/lib/generators/workarea/listrak/message/message_generator.rb +15 -0
- data/lib/generators/workarea/listrak/message/templates/message.rb.erb +24 -0
- data/lib/workarea/listrak/analytics.rb +17 -0
- data/lib/workarea/listrak/bogus_data_api/customers.rb +9 -0
- data/lib/workarea/listrak/bogus_data_api/orders.rb +9 -0
- data/lib/workarea/listrak/bogus_data_api/products.rb +9 -0
- data/lib/workarea/listrak/bogus_data_api/proxy_client.rb +29 -0
- data/lib/workarea/listrak/bogus_data_api.rb +46 -0
- data/lib/workarea/listrak/bogus_email_api/contacts.rb +8 -0
- data/lib/workarea/listrak/bogus_email_api/events.rb +23 -0
- data/lib/workarea/listrak/bogus_email_api/lists.rb +63 -0
- data/lib/workarea/listrak/bogus_email_api/proxy_client.rb +29 -0
- data/lib/workarea/listrak/bogus_email_api/transactional_messages.rb +9 -0
- data/lib/workarea/listrak/bogus_email_api.rb +51 -0
- data/lib/workarea/listrak/engine.rb +12 -0
- data/lib/workarea/listrak/error.rb +39 -0
- data/lib/workarea/listrak/version.rb +5 -0
- data/lib/workarea/listrak.rb +57 -0
- data/readme/listrak-admin.png +0 -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/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/application.rb +18 -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 +54 -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 +38 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/factories/workarea/factories/listrak.rb +15 -0
- data/test/helpers/workarea/listrak/analytics/helper_test.rb +38 -0
- data/test/integration/workarea/admin/listrak/configuration_integration_test.rb +26 -0
- data/test/integration/workarea/admin/listrak/events_integration_test.rb +21 -0
- data/test/lib/generators/workarea/listrak/message_generator_test.rb +26 -0
- data/test/queries/workarea/categorization_test.decorator +15 -0
- data/test/services/workarea/listrak/data_api/customers_test.rb +35 -0
- data/test/services/workarea/listrak/data_api/orders_test.rb +24 -0
- data/test/services/workarea/listrak/data_api/products_test.rb +27 -0
- data/test/services/workarea/listrak/email_api/contacts_test.rb +55 -0
- data/test/services/workarea/listrak/email_api/events_test.rb +51 -0
- data/test/services/workarea/listrak/email_api/lists_test.rb +45 -0
- data/test/services/workarea/listrak/email_api/messages_test.rb +28 -0
- data/test/services/workarea/listrak/email_api/transactional_messages_test.rb +50 -0
- data/test/services/workarea/listrak/oauth_test.rb +27 -0
- data/test/services/workarea/listrak/transactional_message_test.rb +48 -0
- data/test/support/workarea/listrak/test_order_confirmation_email.rb +116 -0
- data/test/support/workarea/listrak/vcr_config.rb +31 -0
- data/test/system/workarea/listrak_system_test.rb +75 -0
- data/test/test_helper.rb +16 -0
- data/test/vcr_cassettes/listrak/data_api/customers_import-successful.yml +88 -0
- data/test/vcr_cassettes/listrak/data_api/orders_import-successful.yml +90 -0
- data/test/vcr_cassettes/listrak/data_api/products_import-successful.yml +88 -0
- data/test/vcr_cassettes/listrak/email_api/contacts_get-successful.yml +87 -0
- data/test/vcr_cassettes/listrak/email_api/contacts_upsert-already_unsubscribed.yml +90 -0
- data/test/vcr_cassettes/listrak/email_api/contacts_upsert-successful.yml +87 -0
- data/test/vcr_cassettes/listrak/email_api/events_create-invalid_parameter.yml +90 -0
- data/test/vcr_cassettes/listrak/email_api/events_create-successful.yml +87 -0
- data/test/vcr_cassettes/listrak/email_api/events_get-successful.yml +88 -0
- data/test/vcr_cassettes/listrak/email_api/lists_all-successful.yml +88 -0
- data/test/vcr_cassettes/listrak/email_api/messages_create-successful.yml +88 -0
- data/test/vcr_cassettes/listrak/email_api/transactional_messages_create-successful.yml +89 -0
- data/test/vcr_cassettes/listrak/oauth-successful.yml +44 -0
- data/test/vcr_cassettes/listrak/oauth-unsuccessful.yml +46 -0
- data/test/vcr_cassettes/listrak/system_tests/footer_email_signup-successful.yml +171 -0
- data/test/vcr_cassettes/listrak/system_tests/footer_email_signup_overrides_unsubscribe.yml +255 -0
- data/test/vcr_cassettes/listrak/system_tests/unsubscribing.yml +593 -0
- data/test/workers/workarea/listrak/order_exporter_test.rb +31 -0
- data/test/workers/workarea/listrak/product_exporter_test.rb +62 -0
- data/workarea-listrak.gemspec +16 -0
- metadata +223 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Listrak
|
5
|
+
class EmailApi::EventsTest < TestCase
|
6
|
+
def test_create
|
7
|
+
VCR.use_cassette 'listrak/email_api/events_create-successful' do
|
8
|
+
event = Listrak::Models::EventForm.new(
|
9
|
+
name: "footer signup"
|
10
|
+
)
|
11
|
+
|
12
|
+
response = email_api.events.create(349984, event)
|
13
|
+
assert response.present?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_invalid_parameter
|
18
|
+
VCR.use_cassette 'listrak/email_api/events_create-invalid_parameter' do
|
19
|
+
event = Listrak::Models::EventForm.new(
|
20
|
+
name: "footer signup"
|
21
|
+
)
|
22
|
+
|
23
|
+
error = assert_raises Workarea::Listrak::HttpError do
|
24
|
+
email_api.events.create(349984, event)
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal "ERROR_INVALID_PARAMETER", error.error_code
|
28
|
+
assert_equal "An invalid value was supplied for eventName.", error.api_message
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_all
|
33
|
+
VCR.use_cassette 'listrak/email_api/events_get-successful' do
|
34
|
+
events = email_api.events.all(349984)
|
35
|
+
|
36
|
+
assert_equal [12714, 12715], events.map(&:id)
|
37
|
+
assert_equal ["Test", "footer signup"], events.map(&:name)
|
38
|
+
assert_equal [0, 0], events.map(&:group_id)
|
39
|
+
assert_equal ["Active", "Active"], events.map(&:status)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def email_api
|
46
|
+
@email_api ||= Listrak::EmailApi.new client_id: 'doyfni0aw64ogd84ld6t',
|
47
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Listrak
|
5
|
+
class EmailApi::ListsTest < TestCase
|
6
|
+
def test_all
|
7
|
+
VCR.use_cassette 'listrak/email_api/lists_all-successful' do
|
8
|
+
lists = email_api.lists.all
|
9
|
+
assert_equal 2, lists.size
|
10
|
+
assert_equal [349956, 349984], lists.map(&:id)
|
11
|
+
assert_equal ["My First List", "gem-testing"], lists.map(&:name)
|
12
|
+
assert_equal [0, 0], lists.map(&:folder_id)
|
13
|
+
assert_equal [11, 11], lists.map(&:ip_pool_id)
|
14
|
+
assert_equal ["", ""], lists.map(&:bounce_domain_alias)
|
15
|
+
assert_equal ["Standard", "Standard"], lists.map(&:bounce_handling)
|
16
|
+
assert_equal [5, 5], lists.map(&:bounce_unsubscribe_count)
|
17
|
+
assert_equal [DateTime.strptime("2015-08-31T16:02:41.65", "%FT%T"), DateTime.strptime("2015-09-02T14:42:38.91", "%FT%T")], lists.map(&:create_date)
|
18
|
+
assert_equal [false, false], lists.map(&:enable_browser_link)
|
19
|
+
assert_equal [false, false], lists.map(&:enable_double_opt_in)
|
20
|
+
assert_equal [false, false], lists.map(&:enable_dynamic_content)
|
21
|
+
assert_equal [false, false], lists.map(&:enable_google_analytics)
|
22
|
+
assert_equal [false, false], lists.map(&:enable_internationalization)
|
23
|
+
assert_equal [true, true], lists.map(&:enable_list_hygiene)
|
24
|
+
assert_equal [true, true], lists.map(&:enable_list_removal_header)
|
25
|
+
assert_equal [true, true], lists.map(&:enable_list_removal_link)
|
26
|
+
assert_equal [false, false], lists.map(&:enable_listrak_analytics)
|
27
|
+
assert_equal [false, false], lists.map(&:enable_spam_score_personalization)
|
28
|
+
assert_equal [false, false], lists.map(&:enable_to_name_personalization)
|
29
|
+
assert_equal ["", "mac@weblinc.com"], lists.map(&:from_email)
|
30
|
+
assert_equal ["", "WebLinc Developer"], lists.map(&:from_name)
|
31
|
+
assert_equal [[], []], lists.map(&:google_tracking_domains)
|
32
|
+
assert_equal ["", ""], lists.map(&:link_domain_alias)
|
33
|
+
assert_equal ["", ""], lists.map(&:media_domain_alias)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def email_api
|
40
|
+
@email_api ||= Listrak::EmailApi.new client_id: 'doyfni0aw64ogd84ld6t',
|
41
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Listrak
|
5
|
+
class EmailApi::MessagesTest < TestCase
|
6
|
+
def test_create
|
7
|
+
VCR.use_cassette 'listrak/email_api/messages_create-successful' do
|
8
|
+
message = Listrak::Models::MessageForm.new(
|
9
|
+
from_email: "plugins@workarea.com",
|
10
|
+
from_name: "Plugins @ Workarea.com",
|
11
|
+
subject: "Testing creating a message",
|
12
|
+
body_html: "This is the body"
|
13
|
+
)
|
14
|
+
|
15
|
+
response = email_api.messages.create(349984, message)
|
16
|
+
assert response.present?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def email_api
|
23
|
+
@email_api ||= Listrak::EmailApi.new client_id: 'doyfni0aw64ogd84ld6t',
|
24
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Listrak
|
5
|
+
class EmailApi::TransactionalMessagesTest < TestCase
|
6
|
+
def test_create
|
7
|
+
VCR.use_cassette 'listrak/email_api/transactional_messages_create-successful' do
|
8
|
+
transactional_message_form = Listrak::Models::TransactionalMessageForm.new(
|
9
|
+
email_address: 'plugins@workarea.com',
|
10
|
+
segmentation_field_values: [
|
11
|
+
{ segmentationFieldId: 2446151, value: 'Ben' },
|
12
|
+
{ segmentationFieldId: 2446152, value: 'Crouse' },
|
13
|
+
{ segmentationFieldId: 2446153, value: '22 S. 3rd St.' },
|
14
|
+
{ segmentationFieldId: 2446154, value: 'Second Floor' },
|
15
|
+
{ segmentationFieldId: 2446155, value: 'Philadelphia' },
|
16
|
+
{ segmentationFieldId: 2446156, value: 'PA' },
|
17
|
+
{ segmentationFieldId: 2446157, value: '19106' },
|
18
|
+
{ segmentationFieldId: 2446158, value: 'US' },
|
19
|
+
{ segmentationFieldId: 2446159, value: "" },
|
20
|
+
{ segmentationFieldId: 2446169, value: "1234" },
|
21
|
+
{ segmentationFieldId: 2446174, value: "" },
|
22
|
+
{ segmentationFieldId: 2446175, value: Time.current.to_s },
|
23
|
+
{ segmentationFieldId: 2446179, value: "10.00" },
|
24
|
+
{ segmentationFieldId: 2446180, value: "0.00" },
|
25
|
+
{ segmentationFieldId: 2446181, value: "1.00" },
|
26
|
+
{ segmentationFieldId: 2446182, value: "0.00" },
|
27
|
+
{ segmentationFieldId: 2446183, value: "11.00" },
|
28
|
+
{ segmentationFieldId: 2446184, value: "1" }
|
29
|
+
]
|
30
|
+
)
|
31
|
+
|
32
|
+
response = email_api.transactional_messages.create(
|
33
|
+
349984,
|
34
|
+
11838256,
|
35
|
+
transactional_message_form
|
36
|
+
)
|
37
|
+
|
38
|
+
assert response.present?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def email_api
|
45
|
+
@email_api ||= Listrak::EmailApi.new client_id: 'doyfni0aw64ogd84ld6t',
|
46
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Listrak
|
5
|
+
class OauthTest < TestCase
|
6
|
+
def test_token_with_valid_credentials
|
7
|
+
VCR.use_cassette "listrak/oauth-successful" do
|
8
|
+
token = Oauth.token client_id: 'doyfni0aw64ogd84ld6t',
|
9
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
10
|
+
|
11
|
+
assert token.present?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_token_with_invalid_credentials
|
16
|
+
VCR.use_cassette "listrak/oauth-unsuccessful" do
|
17
|
+
error = assert_raises Listrak::OauthError do
|
18
|
+
Oauth.token client_id: 'doyfni0aw64ogd84ld6t',
|
19
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5J'
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal({ error: "Invalid Credentials" }.to_json, error.message)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
module Listrak
|
5
|
+
class TransactionalMessageTest < TestCase
|
6
|
+
def test_deliver
|
7
|
+
Listrak::BogusEmailApi.reset_requests!
|
8
|
+
Listrak::BogusEmailApi.store_requests = true
|
9
|
+
order = create_placed_order
|
10
|
+
create_listrak_configuration(default_list_id: '349984')
|
11
|
+
|
12
|
+
message = TestOrderConfirmationEmail.new order
|
13
|
+
|
14
|
+
message.deliver
|
15
|
+
|
16
|
+
messages = Listrak::BogusEmailApi.requests.dig :transactional_messages, :create
|
17
|
+
list_id, message_id, message_form = messages.first
|
18
|
+
|
19
|
+
assert_equal('349984', list_id)
|
20
|
+
assert_equal(11838256, message_id)
|
21
|
+
expected_form_json = {
|
22
|
+
emailAddress: "bcrouse-new@workarea.com",
|
23
|
+
segmentationFieldValues: [
|
24
|
+
{ segmentationFieldId: 2446151, value: 'Ben' },
|
25
|
+
{ segmentationFieldId: 2446152, value: 'Crouse' },
|
26
|
+
{ segmentationFieldId: 2446153, value: '22 S. 3rd St.' },
|
27
|
+
{ segmentationFieldId: 2446154, value: 'Second Floor' },
|
28
|
+
{ segmentationFieldId: 2446155, value: 'Philadelphia' },
|
29
|
+
{ segmentationFieldId: 2446156, value: 'PA' },
|
30
|
+
{ segmentationFieldId: 2446157, value: '19106' },
|
31
|
+
{ segmentationFieldId: 2446158, value: 'US' },
|
32
|
+
{ segmentationFieldId: 2446159, value: "" },
|
33
|
+
{ segmentationFieldId: 2446169, value: "1234" },
|
34
|
+
{ segmentationFieldId: 2446174, value: "" },
|
35
|
+
{ segmentationFieldId: 2446175, value: order.placed_at.to_s },
|
36
|
+
{ segmentationFieldId: 2446179, value: "10.00" },
|
37
|
+
{ segmentationFieldId: 2446180, value: "0.00" },
|
38
|
+
{ segmentationFieldId: 2446181, value: "1.00" },
|
39
|
+
{ segmentationFieldId: 2446182, value: "0.00" },
|
40
|
+
{ segmentationFieldId: 2446183, value: "11.00" },
|
41
|
+
{ segmentationFieldId: 2446184, value: "1" }
|
42
|
+
]
|
43
|
+
}.to_json
|
44
|
+
assert_equal(expected_form_json, message_form.to_json)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Listrak
|
3
|
+
class TestOrderConfirmationEmail
|
4
|
+
include Listrak::TransactionalMessage
|
5
|
+
|
6
|
+
attr_reader :order
|
7
|
+
|
8
|
+
message_id 11838256
|
9
|
+
message_attributes(
|
10
|
+
shipping_first_name: 2446151,
|
11
|
+
shipping_last_name: 2446152,
|
12
|
+
shipping_street_address1: 2446153,
|
13
|
+
shipping_street_address2: 2446154,
|
14
|
+
shipping_city: 2446155,
|
15
|
+
shipping_state: 2446156,
|
16
|
+
shipping_zip: 2446157,
|
17
|
+
shipping_country: 2446158,
|
18
|
+
shipping_phone: 2446159,
|
19
|
+
order_number: 2446169,
|
20
|
+
shipping_method: 2446174,
|
21
|
+
order_date: 2446175,
|
22
|
+
sub_total: 2446179,
|
23
|
+
tax: 2446180,
|
24
|
+
shipping_cost: 2446181,
|
25
|
+
discount: 2446182,
|
26
|
+
grand_total: 2446183,
|
27
|
+
purchased_item_count: 2446184,
|
28
|
+
)
|
29
|
+
|
30
|
+
def initialize(order)
|
31
|
+
@order = order
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def email_address
|
37
|
+
order.email
|
38
|
+
end
|
39
|
+
|
40
|
+
def shipping
|
41
|
+
@shipping ||= Shipping.find_by order_id: order.id
|
42
|
+
end
|
43
|
+
|
44
|
+
def shipping_first_name
|
45
|
+
shipping.address.first_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def shipping_last_name
|
49
|
+
shipping.address.last_name
|
50
|
+
end
|
51
|
+
|
52
|
+
def shipping_street_address1
|
53
|
+
shipping.address.street
|
54
|
+
end
|
55
|
+
|
56
|
+
def shipping_street_address2
|
57
|
+
shipping.address.street_2
|
58
|
+
end
|
59
|
+
|
60
|
+
def shipping_city
|
61
|
+
shipping.address.city
|
62
|
+
end
|
63
|
+
|
64
|
+
def shipping_state
|
65
|
+
shipping.address.region
|
66
|
+
end
|
67
|
+
|
68
|
+
def shipping_zip
|
69
|
+
shipping.address.postal_code
|
70
|
+
end
|
71
|
+
|
72
|
+
def shipping_country
|
73
|
+
shipping.address.country.alpha2
|
74
|
+
end
|
75
|
+
|
76
|
+
def shipping_phone
|
77
|
+
shipping.address.phone_number
|
78
|
+
end
|
79
|
+
|
80
|
+
def order_number
|
81
|
+
order.id
|
82
|
+
end
|
83
|
+
|
84
|
+
def shipping_method
|
85
|
+
end
|
86
|
+
|
87
|
+
def order_date
|
88
|
+
order.placed_at.to_s
|
89
|
+
end
|
90
|
+
|
91
|
+
def sub_total
|
92
|
+
order.subtotal_price.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
def tax
|
96
|
+
order.tax_total.to_s
|
97
|
+
end
|
98
|
+
|
99
|
+
def shipping_cost
|
100
|
+
order.shipping_total.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
def discount
|
104
|
+
0.to_m.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
def grand_total
|
108
|
+
order.total_price.to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
def purchased_item_count
|
112
|
+
order.items.size
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Listrak
|
3
|
+
module VcrConfig
|
4
|
+
def self.included(test)
|
5
|
+
super
|
6
|
+
test.setup :setup_listrak_secrets
|
7
|
+
test.teardown :restore_listrak_secrets
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def setup_listrak_secrets
|
13
|
+
@_old_secrets = Rails.application.secrets.listrak
|
14
|
+
Rails.application.secrets.listrak = {
|
15
|
+
data_api: {
|
16
|
+
client_id: 'a',
|
17
|
+
client_secret: 'ZMOhwRN2MhkP0xicWzcu1rtEY9sjDUq/reVovZOY41U'
|
18
|
+
},
|
19
|
+
email_api: {
|
20
|
+
client_id: 'doyfni0aw64ogd84ld6t',
|
21
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def restore_listrak_secrets
|
27
|
+
Rails.application.secrets.listrak = @_old_secrets
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Workarea
|
4
|
+
class ListrakSystemTest < SystemTest
|
5
|
+
include Listrak::VcrConfig
|
6
|
+
|
7
|
+
def test_signing_up_in_footer_adds_to_default_list
|
8
|
+
VCR.use_cassette 'listrak/system_tests/footer_email_signup-successful' do
|
9
|
+
create_listrak_configuration(default_list_id: '349984', external_event_ids: [12714])
|
10
|
+
|
11
|
+
visit storefront.root_path
|
12
|
+
|
13
|
+
fill_in :footer_email_signup_field, with: 'epigeon@weblinc.com'
|
14
|
+
click_button t('workarea.storefront.users.join')
|
15
|
+
|
16
|
+
contact = email_api.contacts.get('349984', 'epigeon@weblinc.com')
|
17
|
+
assert_equal 'Subscribed', contact.subscription_state
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_signing_up_in_footer_overrides_unsubscribe
|
22
|
+
VCR.use_cassette 'listrak/system_tests/footer_email_signup_overrides_unsubscribe' do
|
23
|
+
create_listrak_configuration(default_list_id: '349984')
|
24
|
+
contact = Listrak::Models::ContactForm.new(
|
25
|
+
email: 'customer@workarea.com',
|
26
|
+
subscription_state: 'Unsubscribed'
|
27
|
+
)
|
28
|
+
|
29
|
+
email_api.contacts.upsert(349984, contact)
|
30
|
+
|
31
|
+
visit storefront.root_path
|
32
|
+
|
33
|
+
fill_in :footer_email_signup_field, with: 'customer@weblinc.com'
|
34
|
+
click_button t('workarea.storefront.users.join')
|
35
|
+
|
36
|
+
contact = email_api.contacts.get('349984', 'customer@weblinc.com')
|
37
|
+
assert_equal 'Subscribed', contact.subscription_state
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_unsubscribbing_from_account
|
42
|
+
VCR.use_cassette 'listrak/system_tests/unsubscribing' do
|
43
|
+
create_listrak_configuration(default_list_id: '349984')
|
44
|
+
visit storefront.login_path
|
45
|
+
|
46
|
+
fill_in :create_account_email, with: 'employee+2@weblinc.com'
|
47
|
+
fill_in :create_account_password, with: 'W3bl1nc!'
|
48
|
+
check :email_signup
|
49
|
+
|
50
|
+
click_button :create_account
|
51
|
+
|
52
|
+
assert_current_path(storefront.users_account_path)
|
53
|
+
|
54
|
+
contact = email_api.contacts.get('349984', 'employee+2@weblinc.com')
|
55
|
+
assert_equal 'Subscribed', contact.subscription_state
|
56
|
+
|
57
|
+
visit storefront.edit_users_account_path
|
58
|
+
|
59
|
+
uncheck :email_signup
|
60
|
+
|
61
|
+
click_button :save_info
|
62
|
+
|
63
|
+
contact = email_api.contacts.get('349984', 'employee+2@weblinc.com')
|
64
|
+
assert_equal 'Unsubscribed', contact.subscription_state
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def email_api
|
71
|
+
@email_api ||= Listrak::EmailApi.new client_id: 'doyfni0aw64ogd84ld6t',
|
72
|
+
client_secret: 'LxdEE4Gu4aSJv5tS9osd8WudjGbJ+EIPYvZBS7bc5JU'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
|
3
|
+
SimpleCov.start "rails" do
|
4
|
+
add_filter "/workarea/listrak/version.rb"
|
5
|
+
add_filter %r{lib/workarea/listrak/bogus*}
|
6
|
+
add_group "View Models", "app/view_models"
|
7
|
+
add_group "Queries", "app/queries"
|
8
|
+
add_group "Email Api", %r{app.*email_api}
|
9
|
+
add_group "Data Api", %r{app.*data_api}
|
10
|
+
end
|
11
|
+
|
12
|
+
ENV["RAILS_ENV"] ||= "test"
|
13
|
+
|
14
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
15
|
+
require "rails/test_help"
|
16
|
+
require "workarea/test_help"
|
@@ -0,0 +1,88 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://auth.listrak.com/OAuth2/Token
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: grant_type=client_credentials&client_id=a&client_secret=b
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Cache-Control:
|
24
|
+
- no-cache
|
25
|
+
Pragma:
|
26
|
+
- no-cache
|
27
|
+
Content-Type:
|
28
|
+
- application/json;charset=UTF-8
|
29
|
+
Expires:
|
30
|
+
- "-1"
|
31
|
+
Server:
|
32
|
+
- Microsoft-IIS/8.5
|
33
|
+
X-Powered-By:
|
34
|
+
- ASP.NET
|
35
|
+
Date:
|
36
|
+
- Fri, 11 Jan 2019 20:11:51 GMT
|
37
|
+
Content-Length:
|
38
|
+
- '465'
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"access_token":"c2gMJxk6E1Z8oRkQVu9rYwAADDMCmA45JlrY8CZjVhG2GKzyYSFvgd9TTrESgAbSs-xCu5UwZ6tUVludWg8GQfro_S1RDJ5Gs0bhneQBnCIYya3adUdEEp4ByCTHPjIr1wp2ydWXaK-OMUqZwezZEAVaMRsIwtYPSkA84SdbKhPcRxXtbSXpb4ZrkS5V4GQNNmUm8wVFRP9RSrnivw1LuFGZ1OwyIYBW1az6CXNq7eLHJrHA3UgnviMnpQpfy3sfa67R2wQUduEb2ikFMV53EVmdtZ9KhCRinhtuAjT2dtLa0jGbfLfTvd480XJqC3v9lFMkspXNT3LNHUEoY43HzPql7cV1O8JU6NhiP1nE41iQozLP9YNZcp-feqgRCPqEKSXeVyRTmvyfcMPFvDMvTQ","token_type":"bearer","expires_in":3599}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Fri, 11 Jan 2019 20:11:52 GMT
|
44
|
+
- request:
|
45
|
+
method: post
|
46
|
+
uri: https://api.listrak.com/data/v1/Customer
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: '[{"address":{"address1":"22 S. 3rd St.","address2":"Second Floor","city":"Philadelphia","country":"United
|
50
|
+
States of America","state":"PA"},"customerNumber":"5c38f88787c68bbe993a","email":"user0@workarea.com","firstName":"Ben","lastName":"Crouse","registered":true,"zipCode":"19106"}]'
|
51
|
+
headers:
|
52
|
+
Accept-Encoding:
|
53
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
54
|
+
Accept:
|
55
|
+
- application/json
|
56
|
+
User-Agent:
|
57
|
+
- Ruby
|
58
|
+
Authorization:
|
59
|
+
- Bearer c2gMJxk6E1Z8oRkQVu9rYwAADDMCmA45JlrY8CZjVhG2GKzyYSFvgd9TTrESgAbSs-xCu5UwZ6tUVludWg8GQfro_S1RDJ5Gs0bhneQBnCIYya3adUdEEp4ByCTHPjIr1wp2ydWXaK-OMUqZwezZEAVaMRsIwtYPSkA84SdbKhPcRxXtbSXpb4ZrkS5V4GQNNmUm8wVFRP9RSrnivw1LuFGZ1OwyIYBW1az6CXNq7eLHJrHA3UgnviMnpQpfy3sfa67R2wQUduEb2ikFMV53EVmdtZ9KhCRinhtuAjT2dtLa0jGbfLfTvd480XJqC3v9lFMkspXNT3LNHUEoY43HzPql7cV1O8JU6NhiP1nE41iQozLP9YNZcp-feqgRCPqEKSXeVyRTmvyfcMPFvDMvTQ
|
60
|
+
Content-Type:
|
61
|
+
- application/json
|
62
|
+
response:
|
63
|
+
status:
|
64
|
+
code: 201
|
65
|
+
message: Created
|
66
|
+
headers:
|
67
|
+
Cache-Control:
|
68
|
+
- no-cache
|
69
|
+
Pragma:
|
70
|
+
- no-cache
|
71
|
+
Content-Length:
|
72
|
+
- '32'
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Expires:
|
76
|
+
- "-1"
|
77
|
+
Server:
|
78
|
+
- Microsoft-IIS/8.5
|
79
|
+
X-Powered-By:
|
80
|
+
- ASP.NET
|
81
|
+
Date:
|
82
|
+
- Fri, 11 Jan 2019 20:11:51 GMT
|
83
|
+
body:
|
84
|
+
encoding: UTF-8
|
85
|
+
string: '{"status":201,"resourceId":null}'
|
86
|
+
http_version:
|
87
|
+
recorded_at: Fri, 11 Jan 2019 20:11:52 GMT
|
88
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,90 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://auth.listrak.com/OAuth2/Token
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: grant_type=client_credentials&client_id=a&client_secret=b
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Cache-Control:
|
24
|
+
- no-cache
|
25
|
+
Pragma:
|
26
|
+
- no-cache
|
27
|
+
Content-Type:
|
28
|
+
- application/json;charset=UTF-8
|
29
|
+
Expires:
|
30
|
+
- "-1"
|
31
|
+
Server:
|
32
|
+
- Microsoft-IIS/8.5
|
33
|
+
X-Powered-By:
|
34
|
+
- ASP.NET
|
35
|
+
Date:
|
36
|
+
- Mon, 14 Jan 2019 14:15:18 GMT
|
37
|
+
Content-Length:
|
38
|
+
- '465'
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: '{"access_token":"q7loCkft2Ux4T5vjiWsjBLRmzC1waR4Ww4n11nvYE-ZJYHNwnMgfqV-NMywZpRj_jSsgKetRNFuNfBQyYmgGfm-Lq5uNsL-nhXi3mUK0Je-T6XnbOK-FZ4GZ9EgwgHymK5mTcELrlseu4K0_0yCglfAcuLFmGBDBMimcrxNfyWbdMYoXjNww8GcuCq4Cf5P2T975fxSsv2ZHDGSAZ1WcvQcuyhbut__ZUcWkAhaWbMsikgYxJiunZr_U4NU4F5jGkRrsPKf58NR3JU29hS4chd6BOfL68SvcP_KOpPBz58DAETuQyyQp1R-Clq9ttY35G3eip_v0Wlj30ONWKt_oDksHh_UE9T8-JK_8UstX76WDFjEUhVbyiQpitctYx5CVFSMwMzaYXeD6voqTjlNZMA","token_type":"bearer","expires_in":3599}'
|
42
|
+
http_version:
|
43
|
+
recorded_at: Mon, 14 Jan 2019 14:15:20 GMT
|
44
|
+
- request:
|
45
|
+
method: post
|
46
|
+
uri: https://api.listrak.com/data/v1/Order
|
47
|
+
body:
|
48
|
+
encoding: UTF-8
|
49
|
+
string: '[{"associateID":null,"billingAddress":{"address1":"22 S. 3rd St.","address2":"Second
|
50
|
+
Floor","city":"Philadelphia","country":"United States of America","state":"PA"},"couponCode":null,"customerNumber":"","dateEntered":"2019-01-14T14:15:19Z","discountTotal":0.0,"email":"bcrouse-new@workarea.com","handlingTotal":1.0,"items":[{"discountDescription":null,"discountType":null,"discountedPrice":0,"itemTotal":10.0,"itemDiscountTotal":0,"meta1":null,"meta2":null,"meta3":null,"meta4":null,"meta5":null,"orderNumber":"1234","price":5.0,"quantity":2,"shipDate":null,"shippingMethod":null,"sku":"SKU","status":null,"trackingNumber":null}],"itemTotal":10.0,"merchandiseDiscount":0.0,"merchandiseDiscountDescription":null,"merchandiseDiscountType":null,"meta1":null,"meta2":null,"meta3":null,"meta4":null,"meta5":null,"nonMerchandiseDiscount":null,"nonMerchandiseDiscountDescription":null,"nonMerchandiseDiscountType":null,"orderNumber":"1234","orderTotal":10.0,"shipDate":null,"shippingAddress":{"address1":"22
|
51
|
+
S. 3rd St.","address2":"Second Floor","city":"Philadelphia","country":"United
|
52
|
+
States of America","state":"PA"},"shippingMethod":"Test 0","shippingTotal":1.0,"source":"web","status":"placed","storeNumber":null,"taxTotal":0.0,"trackingNumber":null}]'
|
53
|
+
headers:
|
54
|
+
Accept-Encoding:
|
55
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
56
|
+
Accept:
|
57
|
+
- application/json
|
58
|
+
User-Agent:
|
59
|
+
- Ruby
|
60
|
+
Authorization:
|
61
|
+
- Bearer q7loCkft2Ux4T5vjiWsjBLRmzC1waR4Ww4n11nvYE-ZJYHNwnMgfqV-NMywZpRj_jSsgKetRNFuNfBQyYmgGfm-Lq5uNsL-nhXi3mUK0Je-T6XnbOK-FZ4GZ9EgwgHymK5mTcELrlseu4K0_0yCglfAcuLFmGBDBMimcrxNfyWbdMYoXjNww8GcuCq4Cf5P2T975fxSsv2ZHDGSAZ1WcvQcuyhbut__ZUcWkAhaWbMsikgYxJiunZr_U4NU4F5jGkRrsPKf58NR3JU29hS4chd6BOfL68SvcP_KOpPBz58DAETuQyyQp1R-Clq9ttY35G3eip_v0Wlj30ONWKt_oDksHh_UE9T8-JK_8UstX76WDFjEUhVbyiQpitctYx5CVFSMwMzaYXeD6voqTjlNZMA
|
62
|
+
Content-Type:
|
63
|
+
- application/json
|
64
|
+
response:
|
65
|
+
status:
|
66
|
+
code: 201
|
67
|
+
message: Created
|
68
|
+
headers:
|
69
|
+
Cache-Control:
|
70
|
+
- no-cache
|
71
|
+
Pragma:
|
72
|
+
- no-cache
|
73
|
+
Content-Length:
|
74
|
+
- '32'
|
75
|
+
Content-Type:
|
76
|
+
- application/json; charset=utf-8
|
77
|
+
Expires:
|
78
|
+
- "-1"
|
79
|
+
Server:
|
80
|
+
- Microsoft-IIS/8.5
|
81
|
+
X-Powered-By:
|
82
|
+
- ASP.NET
|
83
|
+
Date:
|
84
|
+
- Mon, 14 Jan 2019 14:15:20 GMT
|
85
|
+
body:
|
86
|
+
encoding: UTF-8
|
87
|
+
string: '{"status":201,"resourceId":null}'
|
88
|
+
http_version:
|
89
|
+
recorded_at: Mon, 14 Jan 2019 14:15:20 GMT
|
90
|
+
recorded_with: VCR 2.9.3
|