workarea-gift_cards 3.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +24 -0
  5. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  6. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.gitignore +15 -0
  9. data/.scss-lint.yml +188 -0
  10. data/.yardopts +1 -0
  11. data/CHANGELOG.md +485 -0
  12. data/CODE_OF_CONDUCT.md +3 -0
  13. data/CONTRIBUTING.md +3 -0
  14. data/Gemfile +7 -0
  15. data/LICENSE +52 -0
  16. data/README.md +119 -0
  17. data/Rakefile +53 -0
  18. data/app/assets/images/workarea/admin/payment_icons/gift_card.svg +1 -0
  19. data/app/assets/images/workarea/storefront/payment_icons/gift_card.svg +1 -0
  20. data/app/controllers/workarea/admin/data_file_exports_controller.decorator +28 -0
  21. data/app/controllers/workarea/admin/payment_gift_cards_controller.rb +78 -0
  22. data/app/controllers/workarea/api/admin/payment_gift_cards_controller.rb +49 -0
  23. data/app/controllers/workarea/api/storefront/checkouts_controller.decorator +10 -0
  24. data/app/controllers/workarea/api/storefront/gift_cards_controller.rb +26 -0
  25. data/app/controllers/workarea/storefront/checkouts_controller.decorator +24 -0
  26. data/app/controllers/workarea/storefront/gift_cards_controller.rb +24 -0
  27. data/app/mailers/workarea/storefront/gift_card_mailer.rb +28 -0
  28. data/app/models/workarea/catalog/customizations/gift_card.rb +9 -0
  29. data/app/models/workarea/catalog/product.decorator +11 -0
  30. data/app/models/workarea/order/item.decorator +7 -0
  31. data/app/models/workarea/payment/authorize/gift_card.rb +43 -0
  32. data/app/models/workarea/payment/capture/gift_card.rb +25 -0
  33. data/app/models/workarea/payment/gift_card/redemption.rb +23 -0
  34. data/app/models/workarea/payment/gift_card.rb +186 -0
  35. data/app/models/workarea/payment/purchase/gift_card.rb +7 -0
  36. data/app/models/workarea/payment/refund/gift_card.rb +35 -0
  37. data/app/models/workarea/payment/tender/gift_card.rb +30 -0
  38. data/app/models/workarea/payment.decorator +19 -0
  39. data/app/models/workarea/search/admin/order.decorator +9 -0
  40. data/app/models/workarea/search/admin/payment_gift_card.rb +46 -0
  41. data/app/queries/workarea/admin_redemptions_export.rb +84 -0
  42. data/app/queries/workarea/order_item_details.decorator +11 -0
  43. data/app/queries/workarea/search/admin_gift_cards.rb +20 -0
  44. data/app/seeds/workarea/gift_card_seeds.rb +44 -0
  45. data/app/services/workarea/checkout/steps/gift_card.rb +49 -0
  46. data/app/view_models/workarea/admin/payment_gift_card_view_model.rb +11 -0
  47. data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +32 -0
  48. data/app/view_models/workarea/storefront/checkout/summary_view_model.decorator +11 -0
  49. data/app/view_models/workarea/storefront/gift_card_order_pricing.rb +36 -0
  50. data/app/view_models/workarea/storefront/order_view_model.decorator +27 -0
  51. data/app/view_models/workarea/storefront/product_templates/gift_card_view_model.rb +4 -0
  52. data/app/views/workarea/admin/activities/_payment_gift_card_create.html.haml +12 -0
  53. data/app/views/workarea/admin/activities/_payment_gift_card_destroy.html.haml +10 -0
  54. data/app/views/workarea/admin/activities/_payment_gift_card_update.html.haml +14 -0
  55. data/app/views/workarea/admin/orders/tenders/_gift_card.html.haml +5 -0
  56. data/app/views/workarea/admin/payment_gift_cards/_aux_navigation.html.haml +4 -0
  57. data/app/views/workarea/admin/payment_gift_cards/_cards.html.haml +74 -0
  58. data/app/views/workarea/admin/payment_gift_cards/_menu.html.haml +1 -0
  59. data/app/views/workarea/admin/payment_gift_cards/_summary.html.haml +11 -0
  60. data/app/views/workarea/admin/payment_gift_cards/edit.html.haml +37 -0
  61. data/app/views/workarea/admin/payment_gift_cards/index.html.haml +95 -0
  62. data/app/views/workarea/admin/payment_gift_cards/new.html.haml +43 -0
  63. data/app/views/workarea/admin/payment_gift_cards/redemptions.html.haml +29 -0
  64. data/app/views/workarea/admin/payment_gift_cards/show.html.haml +19 -0
  65. data/app/views/workarea/api/storefront/checkouts/steps/_gift_card.json.jbuilder +6 -0
  66. data/app/views/workarea/api/storefront/gift_cards/balance.json.jbuilder +3 -0
  67. data/app/views/workarea/api/storefront/orders/tenders/_gift_card.json.jbuilder +3 -0
  68. data/app/views/workarea/storefront/checkouts/_gift_card_error.html.haml +6 -0
  69. data/app/views/workarea/storefront/checkouts/_gift_card_payment.html.haml +28 -0
  70. data/app/views/workarea/storefront/checkouts/_gift_card_summary.html.haml +6 -0
  71. data/app/views/workarea/storefront/gift_card_mailer/created.html.haml +15 -0
  72. data/app/views/workarea/storefront/gift_cards/index.html.haml +17 -0
  73. data/app/views/workarea/storefront/order_mailer/_gift_card_summary.html.haml +5 -0
  74. data/app/views/workarea/storefront/order_mailer/tenders/_gift_card.html.haml +5 -0
  75. data/app/views/workarea/storefront/orders/_gift_card_summary.html.haml +6 -0
  76. data/app/views/workarea/storefront/orders/tenders/_gift_card.html.haml +9 -0
  77. data/app/views/workarea/storefront/products/templates/_gift_card.html.haml +77 -0
  78. data/app/workers/workarea/create_ordered_gift_cards.rb +47 -0
  79. data/app/workers/workarea/log_gift_card_redemption.rb +32 -0
  80. data/app/workers/workarea/send_gift_card_notifications.rb +20 -0
  81. data/bin/rails +18 -0
  82. data/config/initializers/append_points.rb +37 -0
  83. data/config/initializers/configuration.rb +8 -0
  84. data/config/initializers/jump_to_navigation.rb +3 -0
  85. data/config/locales/en.yml +82 -0
  86. data/config/routes.rb +31 -0
  87. data/lib/workarea/gift_cards/engine.rb +19 -0
  88. data/lib/workarea/gift_cards/version.rb +5 -0
  89. data/lib/workarea/gift_cards.rb +11 -0
  90. data/lib/workarea/mailer_previews/storefront/gift_card_mailer_preview.rb +18 -0
  91. data/test/documentation/workarea/api/admin/gift_cards_documentation_test.rb +82 -0
  92. data/test/documentation/workarea/api/storefront/gift_cards_documentation_test.rb +107 -0
  93. data/test/dummy/Rakefile +6 -0
  94. data/test/dummy/app/assets/config/manifest.js +4 -0
  95. data/test/dummy/app/assets/images/.keep +0 -0
  96. data/test/dummy/app/assets/javascripts/application.js +13 -0
  97. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  98. data/test/dummy/app/controllers/application_controller.rb +3 -0
  99. data/test/dummy/app/controllers/concerns/.keep +0 -0
  100. data/test/dummy/app/helpers/application_helper.rb +2 -0
  101. data/test/dummy/app/jobs/application_job.rb +2 -0
  102. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  103. data/test/dummy/app/models/concerns/.keep +0 -0
  104. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  105. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  106. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  107. data/test/dummy/bin/bundle +3 -0
  108. data/test/dummy/bin/rails +4 -0
  109. data/test/dummy/bin/rake +4 -0
  110. data/test/dummy/bin/setup +34 -0
  111. data/test/dummy/bin/update +29 -0
  112. data/test/dummy/config/application.rb +24 -0
  113. data/test/dummy/config/boot.rb +5 -0
  114. data/test/dummy/config/cable.yml +9 -0
  115. data/test/dummy/config/environment.rb +5 -0
  116. data/test/dummy/config/environments/development.rb +54 -0
  117. data/test/dummy/config/environments/production.rb +86 -0
  118. data/test/dummy/config/environments/test.rb +43 -0
  119. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  120. data/test/dummy/config/initializers/assets.rb +11 -0
  121. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  122. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  123. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  124. data/test/dummy/config/initializers/inflections.rb +16 -0
  125. data/test/dummy/config/initializers/mime_types.rb +4 -0
  126. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  127. data/test/dummy/config/initializers/session_store.rb +3 -0
  128. data/test/dummy/config/initializers/workarea.rb +5 -0
  129. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  130. data/test/dummy/config/locales/en.yml +23 -0
  131. data/test/dummy/config/puma.rb +47 -0
  132. data/test/dummy/config/routes.rb +6 -0
  133. data/test/dummy/config/secrets.yml +22 -0
  134. data/test/dummy/config/spring.rb +6 -0
  135. data/test/dummy/config.ru +5 -0
  136. data/test/dummy/lib/assets/.keep +0 -0
  137. data/test/dummy/log/.keep +0 -0
  138. data/test/dummy/public/404.html +67 -0
  139. data/test/dummy/public/422.html +67 -0
  140. data/test/dummy/public/500.html +66 -0
  141. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  142. data/test/dummy/public/apple-touch-icon.png +0 -0
  143. data/test/dummy/public/favicon.ico +0 -0
  144. data/test/factories/gift_cards.rb +27 -0
  145. data/test/integration/workarea/admin/gift_card_integration_test.rb +53 -0
  146. data/test/integration/workarea/admin/gift_card_redemptions_export_integration_test.rb +104 -0
  147. data/test/integration/workarea/api/admin/gift_card_integration_test.rb +57 -0
  148. data/test/integration/workarea/api/storefront/balance_integration_test.rb +40 -0
  149. data/test/integration/workarea/api/storefront/checkout_integration_test.rb +161 -0
  150. data/test/integration/workarea/storefront/gift_card_integration_test.rb +222 -0
  151. data/test/models/workarea/catalog/gift_card_product_test.rb +15 -0
  152. data/test/models/workarea/gift_card_payment_test.rb +12 -0
  153. data/test/models/workarea/payment/gift_card_test.rb +127 -0
  154. data/test/models/workarea/payment/purchase/gift_card_test.rb +52 -0
  155. data/test/models/workarea/payment/refund/gift_card_test.rb +19 -0
  156. data/test/queries/workarea/admin_redemptions_export_test.rb +52 -0
  157. data/test/queries/workarea/gift_card_order_item_details_test.rb +11 -0
  158. data/test/services/workarea/checkout/steps/gift_card_test.rb +87 -0
  159. data/test/system/workarea/admin/gift_cards_system_test.rb +89 -0
  160. data/test/system/workarea/storefront/gift_cards_system_test.rb +400 -0
  161. data/test/test_helper.rb +10 -0
  162. data/test/view_models/workarea/storefront/checkout/gift_card_payment_view_model_test.rb +65 -0
  163. data/test/workers/workarea/create_ordered_gift_cards_test.rb +39 -0
  164. data/test/workers/workarea/log_gift_card_redemption_test.rb +19 -0
  165. data/workarea-gift_cards.gemspec +21 -0
  166. metadata +227 -0
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Payment
5
+ class Refund
6
+ class GiftCardTest < TestCase
7
+ def test_complete!
8
+ tender = Workarea::Payment::Tender::GiftCard.new(number: 'token', amount: 5.to_m)
9
+ transaction = tender.build_transaction(action: 'refund', amount: 5.to_m)
10
+
11
+ Workarea::Payment::GiftCard.stubs(refund: true)
12
+ Workarea::Payment::Refund::GiftCard.new(tender, transaction).complete!
13
+
14
+ assert(transaction.response.present?)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class AdminRedemptionsExportTest < IntegrationTest
5
+ def test_total
6
+ Workarea.with_config do |config|
7
+ config.per_page = 5
8
+ config.bulk_action_per_page = 5
9
+
10
+ card = create_gift_card(amount: 20)
11
+ create_gift_card_redemption(gift_card: card, amount: 10)
12
+ create_gift_card_redemption(gift_card: card, amount: 10)
13
+ query = Search::AdminGiftCards.new
14
+
15
+ export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
16
+ assert_equal(2, export.total)
17
+
18
+ 15.times do
19
+ card = create_gift_card(amount: 20)
20
+ create_gift_card_redemption(gift_card: card, amount: 10)
21
+ end
22
+
23
+ export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
24
+ assert_equal(17, export.total)
25
+ end
26
+ end
27
+
28
+ def test_scroll
29
+ Workarea.with_config do |config|
30
+ config.bulk_action_per_page = 2
31
+
32
+ 5.times do
33
+ card = create_gift_card(amount: 20)
34
+ create_gift_card_redemption(gift_card: card, amount: 10)
35
+ end
36
+
37
+ query = Search::AdminGiftCards.new
38
+ export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
39
+ count = 0
40
+ passes = 0
41
+
42
+ export.scroll do |results|
43
+ count += results.size
44
+ passes += 1
45
+ end
46
+
47
+ assert_equal(5, count)
48
+ assert_equal(3, passes)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class GiftCardOrderItemDetailsTest < TestCase
5
+ def test_to_hash
6
+ product = create_product(gift_card: true)
7
+ details = OrderItemDetails.new(product, product.skus.first)
8
+ assert(details.to_h[:gift_card])
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,87 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Checkout
5
+ module Steps
6
+ class GiftCardTest < TestCase
7
+ def user
8
+ @user ||= create_user
9
+ end
10
+
11
+ def order
12
+ @order ||= create_order
13
+ end
14
+
15
+ def checkout
16
+ @checkout ||= Checkout.new(order, user)
17
+ end
18
+
19
+ def payment
20
+ @payment ||= checkout.payment.tap(&:save!)
21
+ end
22
+
23
+ def step
24
+ @step ||= Checkout::Steps::GiftCard.new(checkout)
25
+ end
26
+
27
+ def card
28
+ @card ||= create_gift_card
29
+ end
30
+
31
+ def test_user
32
+ assert_equal(user, step.user)
33
+ end
34
+
35
+ def test_update
36
+ product = create_product
37
+ create_shipping_sku(id: product.skus.first)
38
+ shipping = create_shipping(order_id: order.id)
39
+ shipping.set_shipping_service(
40
+ id: 'GROUND',
41
+ name: 'Ground',
42
+ tax_code: '001',
43
+ base_price: 1.to_m
44
+ )
45
+ shipping.set_address(
46
+ first_name: 'Ben',
47
+ last_name: 'Crouse',
48
+ street: '22 S. 3rd St.',
49
+ street_2: 'Second Floor',
50
+ city: 'Philadelphia',
51
+ region: 'PA',
52
+ postal_code: '19106',
53
+ country: 'US',
54
+ phone_number: '2159251800'
55
+ )
56
+ order.add_item(
57
+ product_id: product.id,
58
+ sku: product.skus.first,
59
+ quantity: 1
60
+ )
61
+ params = { gift_card_number: " #{card.number} " }
62
+
63
+ refute_empty(order.items)
64
+ assert(payment.set_gift_card(number: card.number))
65
+ assert(step.update(params))
66
+
67
+ assert_equal(1.to_m, order.shipping_total)
68
+ assert_equal(5.to_m, order.subtotal_price)
69
+ assert_equal(6.to_m, payment.gift_card.amount)
70
+ end
71
+
72
+ def test_complete?
73
+ assert(step.complete?)
74
+
75
+ payment.set_gift_card(number: card.number)
76
+ assert(step.complete?)
77
+
78
+ payment.set_gift_card(number: '')
79
+ refute(step.complete?)
80
+
81
+ payment.set_gift_card(number: '1234')
82
+ refute(step.complete?)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,89 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Admin
5
+ class GiftCardSystemTest < Workarea::SystemTest
6
+ include Admin::IntegrationTest
7
+
8
+ def test_managing_gift_cards
9
+ visit admin.payment_gift_cards_path
10
+ click_link 'add_payment_gift_card'
11
+
12
+ fill_in 'gift_card[amount]', with: 75
13
+ fill_in 'gift_card[to]', with: 'user@workarea.com'
14
+ click_button 'create_gift_card'
15
+
16
+ gift_card = Payment::GiftCard.first
17
+
18
+ assert_current_path(admin.payment_gift_card_path(gift_card))
19
+ assert(page.has_content?('Success'))
20
+ assert(page.has_content?('$75.00'))
21
+
22
+ click_link t('workarea.admin.actions.delete')
23
+
24
+ assert_current_path(admin.payment_gift_cards_path)
25
+ assert(page.has_no_content?(gift_card.name))
26
+ end
27
+
28
+ def test_filtering_gift_cards
29
+ create_gift_card(token: '123', to: 'zac@workarea.com')
30
+ create_gift_card(token: '456', to: 'owen@workarea.com')
31
+
32
+ visit admin.payment_gift_cards_path(q: 'zac@workarea.com')
33
+ assert(page.has_content?('123'))
34
+ assert(page.has_no_content?('456'))
35
+
36
+ visit admin.payment_gift_cards_path(q: '456')
37
+ assert(page.has_content?('456'))
38
+ assert(page.has_no_content?('123'))
39
+ end
40
+
41
+ def test_viewing_gift_card_redemptions
42
+ gift_card = create_gift_card
43
+ order = create_placed_order
44
+
45
+ gift_card.redemptions.create!(
46
+ order_id: order.id,
47
+ amount: 1.to_m,
48
+ redeemed_at: Time.now
49
+ )
50
+
51
+ visit admin.payment_gift_card_path(gift_card)
52
+
53
+ click_link t('workarea.admin.payment_gift_cards.cards.redemptions.title')
54
+
55
+ assert(page.has_content?(order.id))
56
+ assert(page.has_content?(gift_card.token))
57
+ assert(page.has_content?('$1.00'))
58
+ end
59
+
60
+ def test_exporting_gift_cards
61
+ 2.times { create_gift_card }
62
+
63
+ visit admin.payment_gift_cards_path
64
+
65
+ check 'select_all'
66
+ click_button t('workarea.admin.shared.bulk_actions.export')
67
+
68
+ fill_in 'export[emails_list]', with: 'bcrouse@workarea.com'
69
+ click_button 'create_export'
70
+
71
+ assert_current_path(admin.payment_gift_cards_path)
72
+ assert(page.has_content?('Success'))
73
+ assert(File.read(DataFile::Export.desc(:created_at).first.file.path).present?)
74
+
75
+ visit admin.payment_gift_cards_path
76
+
77
+ check 'select_all'
78
+ click_button t('workarea.admin.payment_gift_cards.index.export_redemptions')
79
+
80
+ fill_in 'export[emails_list]', with: 'bcrouse@workarea.com'
81
+ click_button 'create_export'
82
+
83
+ assert_current_path(admin.payment_gift_cards_path)
84
+ assert(page.has_content?('Success'))
85
+ assert(File.read(DataFile::Export.desc(:created_at).first.file.path).present?)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,400 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class GiftCardSystemTest < Workarea::SystemTest
6
+ include Storefront::SystemTest
7
+
8
+ def test_putting_a_gift_card_in_your_cart
9
+ product = create_product(
10
+ name: 'Gift Card',
11
+ gift_card: true,
12
+ digital: true,
13
+ template: 'gift_card',
14
+ customizations: 'gift_card',
15
+ variants: [
16
+ { sku: 'SKU1', regular: 10.to_m },
17
+ { sku: 'SKU2', regular: 15.to_m },
18
+ { sku: 'SKU3', regular: 25.to_m }
19
+ ]
20
+ )
21
+
22
+ visit storefront.product_path(product)
23
+
24
+ assert(page.has_content?('Gift Card'))
25
+
26
+ within '.product-details__add-to-cart-form' do
27
+ select product.skus.first, from: 'sku'
28
+ wait_for_xhr
29
+
30
+ fill_in 'email', with: 'bcrouse@workarea.com'
31
+ fill_in 'from', with: 'Ben Crouse'
32
+ fill_in 'message', with: 'this is a message'
33
+
34
+ click_button 'add_to_cart'
35
+ wait_for_xhr
36
+ end
37
+
38
+ visit storefront.cart_path
39
+
40
+ assert(page.has_content?('Gift Card'))
41
+ assert(page.has_content?('bcrouse@workarea.com'))
42
+ assert(page.has_content?('Ben Crouse'))
43
+ assert(page.has_content?('this is a message'))
44
+ end
45
+
46
+ def test_purchasing_digital_gift_cards
47
+ setup_checkout_specs
48
+ Workarea::Order.first.items.delete_all
49
+
50
+ product = create_product(
51
+ name: 'Gift Card',
52
+ gift_card: true,
53
+ digital: true,
54
+ template: 'gift_card',
55
+ customizations: 'gift_card',
56
+ variants: [
57
+ { sku: 'SKU1', regular: 10.to_m },
58
+ { sku: 'SKU2', regular: 15.to_m },
59
+ { sku: 'SKU3', regular: 25.to_m }
60
+ ]
61
+ )
62
+
63
+ visit storefront.product_path(product)
64
+
65
+ within '.product-details__add-to-cart-form' do
66
+ select product.skus.first, from: 'sku'
67
+ wait_for_xhr
68
+
69
+ fill_in 'email', with: 'recipient@workarea.com'
70
+ fill_in 'from', with: 'sender@workarea.com'
71
+ fill_in 'message', with: 'this is a message'
72
+
73
+ click_button 'add_to_cart'
74
+ wait_for_xhr
75
+ end
76
+
77
+ start_guest_checkout
78
+
79
+ assert_current_path(storefront.checkout_addresses_path)
80
+
81
+ refute(page.has_selector?('#shipping_address_first_name'))
82
+ refute(page.has_selector?('#shipping_address_last_name'))
83
+
84
+ fill_in_email
85
+ fill_in_billing_address
86
+ click_button 'continue'
87
+
88
+ assert_current_path(storefront.checkout_payment_path)
89
+ assert(page.has_content?('Success'))
90
+
91
+ fill_in_credit_card
92
+ click_button 'place_order'
93
+
94
+ assert(page.has_content?('Success'))
95
+ assert(page.has_content?('Thanks'))
96
+ assert(page.has_content?(Workarea::Order.first.id))
97
+
98
+ assert(page.has_content?('1019 S. 47th St.'))
99
+ assert(page.has_content?('Philadelphia'))
100
+ assert(page.has_content?('PA'))
101
+ assert(page.has_content?('19143'))
102
+
103
+ assert(page.has_content?('Test Card'))
104
+ assert(page.has_content?('XX-1'))
105
+
106
+ assert(page.has_content?('Gift Card'))
107
+ assert(page.has_content?('recipient@workarea.com'))
108
+ assert(page.has_content?('Ben Crouse'))
109
+ assert(page.has_content?('this is a message'))
110
+ assert(page.has_content?('$10.00'))
111
+ end
112
+
113
+ def test_guest_purchasing_with_a_gift_card
114
+ gift_card = create_gift_card(amount: 100.to_m)
115
+
116
+ setup_checkout_specs
117
+ start_guest_checkout
118
+
119
+ assert_current_path(storefront.checkout_addresses_path)
120
+ fill_in_email
121
+ fill_in_shipping_address
122
+ uncheck 'same_as_shipping'
123
+ fill_in_billing_address
124
+ click_button 'continue'
125
+
126
+ assert_current_path(storefront.checkout_shipping_path)
127
+ assert(page.has_content?('Success'))
128
+ click_button 'continue'
129
+
130
+ assert_current_path(storefront.checkout_payment_path)
131
+ assert(page.has_content?('Success'))
132
+ click_button t('workarea.storefront.gift_cards.enter_gift_card_prompt')
133
+ fill_in 'gift_card_number', with: gift_card.token
134
+ click_button 'apply_gift_card'
135
+
136
+ assert_current_path(storefront.checkout_payment_path)
137
+
138
+ assert(page.has_content?('Success'))
139
+ assert(page.has_content?('22 S. 3rd St.'))
140
+ assert(page.has_content?('Philadelphia'))
141
+ assert(page.has_content?('PA'))
142
+ assert(page.has_content?('19106'))
143
+ assert(page.has_content?('Ground'))
144
+
145
+ assert(page.has_content?('1019 S. 47th St.'))
146
+ assert(page.has_content?('Philadelphia'))
147
+ assert(page.has_content?('PA'))
148
+ assert(page.has_content?('19143'))
149
+
150
+ assert(page.has_content?('Gift Card'))
151
+
152
+ assert(page.has_content?('Integration Product'))
153
+ assert(page.has_content?('SKU'))
154
+
155
+ assert(page.has_content?('$5.00'))
156
+ assert(page.has_content?('$7.00'))
157
+ assert(page.has_content?('$0.84'))
158
+ assert(page.has_content?('$12.84'))
159
+
160
+ click_button 'place_order'
161
+
162
+ assert(page.has_content?('Success'))
163
+ assert(page.has_content?('Thanks'))
164
+ assert(page.has_content?(Workarea::Order.first.id))
165
+
166
+ assert(page.has_content?('22 S. 3rd St.'))
167
+ assert(page.has_content?('Philadelphia'))
168
+ assert(page.has_content?('PA'))
169
+ assert(page.has_content?('19106'))
170
+ assert(page.has_content?('Ground'))
171
+
172
+ assert(page.has_content?('1019 S. 47th St.'))
173
+ assert(page.has_content?('Philadelphia'))
174
+ assert(page.has_content?('PA'))
175
+ assert(page.has_content?('19143'))
176
+
177
+ assert(page.has_content?('Gift Card'))
178
+ assert(page.has_content?("XXXX#{gift_card.token.last(4)}"))
179
+
180
+ assert(page.has_content?('Integration Product'))
181
+ assert(page.has_content?('SKU'))
182
+
183
+ assert(page.has_content?('$5.00'))
184
+ assert(page.has_content?('$7.00'))
185
+ assert(page.has_content?('$0.84'))
186
+ assert(page.has_content?('$12.84'))
187
+ end
188
+
189
+ def test_logged_in_user_purchasing_with_a_gift_card
190
+ gift_card = create_gift_card(amount: 100.to_m)
191
+
192
+ setup_checkout_specs
193
+ add_user_data
194
+ start_user_checkout
195
+
196
+ assert_current_path(storefront.checkout_payment_path)
197
+
198
+ click_button t('workarea.storefront.gift_cards.enter_gift_card_prompt')
199
+ fill_in 'gift_card_number', with: gift_card.token
200
+ click_button 'apply_gift_card'
201
+
202
+ assert_current_path(storefront.checkout_payment_path)
203
+
204
+ assert(page.has_content?('Success'))
205
+ assert(page.has_content?('22 S. 3rd St.'))
206
+ assert(page.has_content?('Philadelphia'))
207
+ assert(page.has_content?('PA'))
208
+ assert(page.has_content?('19106'))
209
+ assert(page.has_content?('Ground'))
210
+
211
+ assert(page.has_content?('1019 S. 47th St.'))
212
+ assert(page.has_content?('Philadelphia'))
213
+ assert(page.has_content?('PA'))
214
+ assert(page.has_content?('19143'))
215
+
216
+ assert(page.has_content?('Gift Card'))
217
+
218
+ assert(page.has_content?('Integration Product'))
219
+ assert(page.has_content?('SKU'))
220
+
221
+ assert(page.has_content?('$5.00'))
222
+ assert(page.has_content?('$7.00'))
223
+ assert(page.has_content?('$0.84'))
224
+ assert(page.has_content?('$12.84'))
225
+
226
+ click_button 'place_order'
227
+
228
+ assert(page.has_content?('Success'))
229
+ assert(page.has_content?('Thanks'))
230
+ assert(page.has_content?(Workarea::Order.first.id))
231
+
232
+ assert(page.has_content?('22 S. 3rd St.'))
233
+ assert(page.has_content?('Philadelphia'))
234
+ assert(page.has_content?('PA'))
235
+ assert(page.has_content?('19106'))
236
+ assert(page.has_content?('Ground'))
237
+
238
+ assert(page.has_content?('1019 S. 47th St.'))
239
+ assert(page.has_content?('Philadelphia'))
240
+ assert(page.has_content?('PA'))
241
+ assert(page.has_content?('19143'))
242
+
243
+ assert(page.has_no_content?('Test Card'))
244
+ assert(page.has_no_content?('XX-1'))
245
+ assert(page.has_content?('Gift Card'))
246
+ assert(page.has_content?("XXXX#{gift_card.token.last(4)}"))
247
+
248
+ assert(page.has_content?('Integration Product'))
249
+ assert(page.has_content?('SKU'))
250
+
251
+ assert(page.has_content?('$5.00'))
252
+ assert(page.has_content?('$7.00'))
253
+ assert(page.has_content?('$0.84'))
254
+ assert(page.has_content?('$12.84'))
255
+ end
256
+
257
+ def test_purchasing_with_a_gift_card_and_a_credit_card
258
+ gift_card = create_gift_card(amount: 5.to_m, token: 'MixEdCaSe')
259
+
260
+ setup_checkout_specs
261
+ start_guest_checkout
262
+
263
+ assert_current_path(storefront.checkout_addresses_path)
264
+ fill_in_email
265
+ uncheck 'same_as_shipping'
266
+ fill_in_billing_address
267
+ fill_in_shipping_address
268
+ click_button 'continue'
269
+
270
+ assert_current_path(storefront.checkout_shipping_path)
271
+ assert(page.has_content?('Success'))
272
+ click_button 'continue'
273
+
274
+ assert_current_path(storefront.checkout_payment_path)
275
+ assert(page.has_content?('Success'))
276
+ click_button t('workarea.storefront.gift_cards.enter_gift_card_prompt')
277
+ fill_in 'gift_card_number', with: gift_card.token
278
+ click_button 'apply_gift_card'
279
+
280
+ assert_current_path(storefront.checkout_payment_path)
281
+ assert(page.has_content?('Success'))
282
+ assert(page.has_content?('22 S. 3rd St.'))
283
+ assert(page.has_content?('Philadelphia'))
284
+ assert(page.has_content?('PA'))
285
+ assert(page.has_content?('19106'))
286
+ assert(page.has_content?('Ground'))
287
+
288
+ assert(page.has_content?('1019 S. 47th St.'))
289
+ assert(page.has_content?('Philadelphia'))
290
+ assert(page.has_content?('PA'))
291
+ assert(page.has_content?('19143'))
292
+
293
+ assert(page.has_content?('Gift Card'))
294
+
295
+ assert(page.has_content?('Integration Product'))
296
+ assert(page.has_content?('SKU'))
297
+
298
+ assert(page.has_content?('$5.00'))
299
+ assert(page.has_content?('$7.00'))
300
+ assert(page.has_content?('$0.84'))
301
+ assert(page.has_content?('$5.00'))
302
+ assert(page.has_content?('$7.84'))
303
+
304
+ fill_in_credit_card
305
+ click_button 'place_order'
306
+
307
+ assert_current_path(storefront.checkout_confirmation_path)
308
+ assert(page.has_content?('Success'))
309
+ assert(page.has_content?('Thanks'))
310
+ assert(page.has_content?(Workarea::Order.first.id))
311
+
312
+ assert(page.has_content?('22 S. 3rd St.'))
313
+ assert(page.has_content?('Philadelphia'))
314
+ assert(page.has_content?('PA'))
315
+ assert(page.has_content?('19106'))
316
+ assert(page.has_content?('Ground'))
317
+
318
+ assert(page.has_content?('1019 S. 47th St.'))
319
+ assert(page.has_content?('Philadelphia'))
320
+ assert(page.has_content?('PA'))
321
+ assert(page.has_content?('19143'))
322
+
323
+ assert(page.has_content?('Test Card'))
324
+ assert(page.has_content?('XX-1'))
325
+ assert(page.has_content?('Gift Card'))
326
+ assert(page.has_content?("XXXX#{gift_card.token.last(4)}"))
327
+
328
+ assert(page.has_content?('Integration Product'))
329
+ assert(page.has_content?('SKU'))
330
+
331
+ assert(page.has_content?('$5.00'))
332
+ assert(page.has_content?('$7.00'))
333
+ assert(page.has_content?('$0.84'))
334
+ assert(page.has_content?('$5.00'))
335
+ assert(page.has_content?('$7.84'))
336
+ end
337
+
338
+ def test_trying_to_pay_with_an_insufficient_gift_card_amount
339
+ gift_card = create_gift_card(amount: 1.to_m)
340
+
341
+ setup_checkout_specs
342
+ start_guest_checkout
343
+
344
+ assert_current_path(storefront.checkout_addresses_path)
345
+ fill_in_email
346
+ fill_in_shipping_address
347
+ uncheck 'same_as_shipping'
348
+ fill_in_billing_address
349
+ click_button 'continue'
350
+
351
+ assert_current_path(storefront.checkout_shipping_path)
352
+ assert(page.has_content?('Success'))
353
+ click_button 'continue'
354
+
355
+ assert_current_path(storefront.checkout_payment_path)
356
+ assert(page.has_content?('Success'))
357
+ click_button t('workarea.storefront.gift_cards.enter_gift_card_prompt')
358
+ fill_in 'gift_card_number', with: gift_card.token
359
+ click_button 'apply_gift_card'
360
+
361
+ assert_current_path(storefront.checkout_payment_path)
362
+ assert(page.has_content?('Success'))
363
+ assert(page.has_content?('$1.00'))
364
+ assert(page.has_content?('$11.84'))
365
+
366
+ click_button 'place_order'
367
+
368
+ # js prevents submit and focuses on credit card
369
+ assert_current_path(storefront.checkout_payment_path)
370
+
371
+ fill_in_credit_card
372
+ click_button 'place_order'
373
+ assert(page.has_content?('Success'))
374
+ assert_current_path(storefront.checkout_confirmation_path)
375
+ end
376
+
377
+ def test_check_a_gift_card_balance
378
+ gift_card = create_gift_card(amount: 5.to_m)
379
+
380
+ visit storefront.gift_cards_balance_path
381
+ fill_in 'gift_card_number', with: gift_card.token
382
+ fill_in 'gift_card_email', with: gift_card.to
383
+ click_button 'submit'
384
+
385
+ assert(page.has_content?('$5.00'))
386
+ end
387
+
388
+ def test_check_a_gift_card_balance_with_a_mis_cased_email
389
+ gift_card = create_gift_card(amount: 5.to_m)
390
+
391
+ visit storefront.gift_cards_balance_path
392
+ fill_in 'gift_card_number', with: gift_card.token
393
+ fill_in 'gift_card_email', with: gift_card.to.upcase
394
+ click_button 'submit'
395
+
396
+ assert(page.has_content?('$5.00'))
397
+ end
398
+ end
399
+ end
400
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
4
+ require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
5
+ require 'rails/test_help'
6
+ require 'workarea/test_help'
7
+
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new