workarea-gift_cards 3.4.11 → 4.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/{.eslintrc → .eslintrc.json} +12 -1
  3. data/.github/workflows/ci.yml +10 -8
  4. data/.rubocop.yml +2 -197
  5. data/.stylelintrc.json +8 -0
  6. data/CHANGELOG.md +0 -71
  7. data/Gemfile +3 -5
  8. data/Rakefile +5 -4
  9. data/app/controllers/workarea/api/admin/gift_cards_controller.rb +309 -0
  10. data/app/controllers/workarea/api/storefront/checkouts_controller.decorator +6 -0
  11. data/app/controllers/workarea/api/storefront/gift_cards_controller.rb +2 -8
  12. data/app/controllers/workarea/storefront/checkout/gift_cards_controller.rb +32 -0
  13. data/app/controllers/workarea/storefront/gift_cards_controller.rb +15 -16
  14. data/app/models/workarea/checkout/steps/gift_card.rb +71 -0
  15. data/app/models/workarea/fulfillment/policies/create_gift_card.rb +30 -0
  16. data/app/models/workarea/payment/authorize/gift_card.rb +7 -20
  17. data/app/models/workarea/payment/capture/gift_card.rb +5 -7
  18. data/app/models/workarea/payment/gift_card.rb +1 -1
  19. data/app/models/workarea/payment/gift_card_operation.rb +9 -0
  20. data/app/models/workarea/payment/purchase/gift_card.rb +24 -1
  21. data/app/models/workarea/payment/refund/gift_card.rb +9 -14
  22. data/app/models/workarea/payment/tender/gift_card.rb +3 -10
  23. data/app/models/workarea/payment.decorator +25 -7
  24. data/app/models/workarea/search/admin/order.decorator +2 -4
  25. data/app/seeds/workarea/gift_card_seeds.rb +7 -7
  26. data/app/view_models/workarea/storefront/gift_card_order_pricing.rb +19 -20
  27. data/app/view_models/workarea/storefront/order_view_model.decorator +2 -22
  28. data/app/views/workarea/admin/payment_gift_cards/_menu.html.haml +2 -1
  29. data/app/views/workarea/storefront/checkouts/_gift_card_error.html.haml +8 -6
  30. data/app/views/workarea/storefront/checkouts/_gift_card_payment.html.haml +20 -12
  31. data/app/views/workarea/storefront/gift_card_mailer/created.html.haml +1 -1
  32. data/app/views/workarea/storefront/order_mailer/_gift_card_summary.html.haml +6 -5
  33. data/app/views/workarea/storefront/orders/_gift_card_summary.html.haml +2 -2
  34. data/app/views/workarea/storefront/products/templates/_gift_card.html.haml +5 -5
  35. data/app/workers/workarea/log_gift_card_redemption.rb +16 -9
  36. data/config/initializers/configuration.rb +7 -4
  37. data/config/initializers/fields.rb +14 -0
  38. data/config/locales/en.yml +14 -4
  39. data/config/routes.rb +9 -2
  40. data/lib/workarea/gift_cards/gateway.rb +128 -0
  41. data/lib/workarea/gift_cards/version.rb +1 -1
  42. data/lib/workarea/gift_cards.rb +9 -0
  43. data/test/documentation/workarea/api/admin/gift_cards_documentation_test.rb +24 -10
  44. data/test/documentation/workarea/api/storefront/gift_cards_documentation_test.rb +57 -50
  45. data/test/dummy/config/initializers/session_store.rb +1 -1
  46. data/test/integration/workarea/api/admin/gift_card_integration_test.rb +13 -5
  47. data/test/integration/workarea/api/storefront/checkout_gift_cards_integration_test.rb +120 -0
  48. data/test/integration/workarea/api/storefront/{balance_integration_test.rb → gift_cards_integration_test.rb} +1 -1
  49. data/test/integration/workarea/storefront/checkout_gift_cards_integration_test.rb +116 -0
  50. data/test/integration/workarea/storefront/gift_cards_integration_test.rb +48 -0
  51. data/test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb +55 -0
  52. data/test/lib/workarea/gift_cards/gateway_test.rb +97 -0
  53. data/test/models/workarea/checkout/steps/gift_card_test.rb +104 -0
  54. data/test/models/workarea/fulfillment/policies/create_gift_card_test.rb +47 -0
  55. data/test/models/workarea/gift_card_payment_test.rb +15 -3
  56. data/test/models/workarea/payment/purchase/gift_card_test.rb +11 -8
  57. data/test/queries/workarea/admin_redemptions_export_test.rb +31 -35
  58. data/test/system/workarea/storefront/gift_cards_system_test.rb +8 -2
  59. data/test/view_models/workarea/storefront/gift_card_order_pricing_test.rb +113 -0
  60. data/test/workers/workarea/log_gift_card_redemption_test.rb +1 -1
  61. data/workarea-gift_cards.gemspec +4 -4
  62. metadata +26 -30
  63. data/.eslintignore +0 -2
  64. data/.scss-lint.yml +0 -188
  65. data/app/controllers/workarea/api/admin/payment_gift_cards_controller.rb +0 -49
  66. data/app/controllers/workarea/storefront/checkouts_controller.decorator +0 -24
  67. data/app/services/workarea/checkout/steps/gift_card.rb +0 -49
  68. data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +0 -32
  69. data/app/view_models/workarea/storefront/checkout/summary_view_model.decorator +0 -11
  70. data/app/workers/workarea/create_ordered_gift_cards.rb +0 -47
  71. data/config/initializers/jump_to_navigation.rb +0 -3
  72. data/test/integration/workarea/api/storefront/checkout_integration_test.rb +0 -161
  73. data/test/integration/workarea/storefront/gift_card_integration_test.rb +0 -226
  74. data/test/services/workarea/checkout/steps/gift_card_test.rb +0 -87
  75. data/test/view_models/workarea/storefront/checkout/gift_card_payment_view_model_test.rb +0 -65
  76. data/test/workers/workarea/create_ordered_gift_cards_test.rb +0 -39
@@ -16,14 +16,14 @@ module Workarea
16
16
 
17
17
  def test_and_document_index
18
18
  description 'Listing payment gift cards'
19
- route admin.payment_gift_cards_path
19
+ route admin_api.gift_cards_path
20
20
  parameter :page, 'Current page'
21
21
  parameter :sort_by, 'Field on which to sort (see responses for possible values)'
22
22
  parameter :sort_direction, 'Direction to sort (asc or desc)'
23
23
  2.times { |i| create_gift_card(to: "#{i}@weblinc.com") }
24
24
 
25
25
  record_request do
26
- get admin_api.payment_gift_cards_path,
26
+ get admin_api.gift_cards_path,
27
27
  params: { page: 1, sort_by: 'created_at', sort_direction: 'desc' }
28
28
 
29
29
  assert_equal(200, response.status)
@@ -32,10 +32,10 @@ module Workarea
32
32
 
33
33
  def test_and_document_create
34
34
  description 'Creating a gift card'
35
- route admin_api.payment_gift_cards_path
35
+ route admin_api.gift_cards_path
36
36
 
37
37
  record_request do
38
- post admin_api.payment_gift_cards_path,
38
+ post admin_api.gift_cards_path,
39
39
  params: { gift_card: sample_attributes.merge('token' => 'foobar') },
40
40
  as: :json
41
41
 
@@ -45,20 +45,20 @@ module Workarea
45
45
 
46
46
  def test_and_document_show
47
47
  description 'Showing a gift card'
48
- route admin_api.payment_gift_card_path(':id')
48
+ route admin_api.gift_card_path(':id')
49
49
 
50
50
  record_request do
51
- get admin_api.payment_gift_card_path(create_gift_card.id)
51
+ get admin_api.gift_card_path(create_gift_card.id)
52
52
  assert_equal(200, response.status)
53
53
  end
54
54
  end
55
55
 
56
56
  def test_and_document_update
57
57
  description 'Updating a gift card'
58
- route admin_api.payment_gift_card_path(':id')
58
+ route admin_api.gift_card_path(':id')
59
59
 
60
60
  record_request do
61
- patch admin_api.payment_gift_card_path(create_gift_card.id),
61
+ patch admin_api.gift_card_path(create_gift_card.id),
62
62
  params: { gift_card: { to: 'test@weblinc.com' } },
63
63
  as: :json
64
64
 
@@ -68,10 +68,24 @@ module Workarea
68
68
 
69
69
  def test_and_document_destroy
70
70
  description 'Removing a gift card'
71
- route admin_api.payment_gift_card_path(':id')
71
+ route admin_api.gift_card_path(':id')
72
72
 
73
73
  record_request do
74
- delete admin_api.payment_gift_card_path(create_gift_card.id)
74
+ delete admin_api.gift_card_path(create_gift_card.id)
75
+ assert_equal(204, response.status)
76
+ end
77
+ end
78
+
79
+ def test_and_document_bulk_upsert
80
+ description 'Bulk upserting gift cards'
81
+ route admin_api.bulk_gift_cards_path
82
+
83
+ data = Array.new(3) do |i|
84
+ sample_attributes.merge('token' => "GC#{i}")
85
+ end
86
+
87
+ record_request do
88
+ patch admin_api.bulk_gift_cards_path, params: { gift_cards: data }, as: :json
75
89
  assert_equal(204, response.status)
76
90
  end
77
91
  end
@@ -8,6 +8,42 @@ module Workarea
8
8
  class GiftCardsDocumentationTest < DocumentationTest
9
9
  resource 'Gift Cards'
10
10
 
11
+ def setup_checkout
12
+ product = create_product(
13
+ name: 'Integration Product',
14
+ variants: [
15
+ { sku: 'SKU1',
16
+ regular: 6.to_m,
17
+ tax_code: '001',
18
+ on_sale: true,
19
+ sale: 5.to_m }
20
+ ]
21
+ )
22
+
23
+ create_shipping_service(
24
+ name: 'Ground',
25
+ tax_code: '001',
26
+ rates: [{ price: 7.to_m }]
27
+ )
28
+
29
+ @gift_card = create_gift_card(amount: 5.to_m)
30
+ @order = Order.create!
31
+
32
+ post storefront_api.cart_items_path(@order),
33
+ params: {
34
+ product_id: product.id,
35
+ sku: product.skus.first,
36
+ quantity: 2
37
+ }
38
+
39
+ patch storefront_api.checkout_path(@order),
40
+ params: {
41
+ email: 'bcrouse@workarea.com',
42
+ billing_address: factory_defaults(:billing_address),
43
+ shipping_address: factory_defaults(:shipping_address)
44
+ }
45
+ end
46
+
11
47
  def test_checking_gift_card_balance
12
48
  description 'Checking gift card balance'
13
49
  route storefront_api.gift_cards_balance_path
@@ -40,63 +76,34 @@ module Workarea
40
76
  checkout completion.
41
77
  EOS
42
78
 
43
- product = create_product(
44
- name: 'Integration Product',
45
- variants: [
46
- { sku: 'SKU1',
47
- regular: 6.to_m,
48
- tax_code: '001',
49
- on_sale: true,
50
- sale: 5.to_m }
51
- ]
52
- )
79
+ setup_checkout
53
80
 
54
- create_shipping_service(
55
- name: 'Ground',
56
- tax_code: '001',
57
- rates: [{ price: 7.to_m }]
58
- )
81
+ record_request do
82
+ patch storefront_api.add_gift_card_checkout_path(@order),
83
+ params: { gift_card_number: @gift_card.token }
59
84
 
60
- gift_card = create_gift_card(amount: 5.to_m)
85
+ assert_equal(200, response.status)
86
+ end
87
+ end
61
88
 
62
- order = Order.create!
89
+ def test_removing_gift_card_from_checkout
90
+ description 'Removing a gift card from checkout'
91
+ route storefront_api.remove_gift_card_checkout_path(':order_id')
92
+ explanation <<-EOS
93
+ This endpoint removes a gift card from an order during the
94
+ checkout process.
95
+ EOS
63
96
 
64
- post storefront_api.cart_items_path(order),
65
- params: {
66
- product_id: product.id,
67
- sku: product.skus.first,
68
- quantity: 2
69
- }
97
+ setup_checkout
70
98
 
71
- patch storefront_api.checkout_path(order),
72
- params: {
73
- email: 'bcrouse@workarea.com',
74
- billing_address: {
75
- first_name: 'Ben',
76
- last_name: 'Crouse',
77
- street: '12 N. 3rd St.',
78
- city: 'Philadelphia',
79
- region: 'PA',
80
- postal_code: '19106',
81
- country: 'US',
82
- phone_number: '2159251800'
83
- },
84
- shipping_address: {
85
- first_name: 'Ben',
86
- last_name: 'Crouse',
87
- street: '22 S. 3rd St.',
88
- city: 'Philadelphia',
89
- region: 'PA',
90
- postal_code: '19106',
91
- country: 'US',
92
- phone_number: '2159251800'
93
- }
94
- }
99
+ patch storefront_api.add_gift_card_checkout_path(@order),
100
+ params: { gift_card_number: @gift_card.token }
95
101
 
96
- record_request do
97
- patch storefront_api.add_gift_card_checkout_path(order),
98
- params: { gift_card_number: gift_card.token }
102
+ payment = Payment.find(@order.id)
99
103
 
104
+ record_request do
105
+ delete storefront_api.remove_gift_card_checkout_path(@order),
106
+ params: { gift_card_id: payment.gift_cards.first.id }
100
107
  assert_equal(200, response.status)
101
108
  end
102
109
  end
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Rails.application.config.session_store :cookie_store, key: '_dummy_session', expire_after: 2.weeks
3
+ Rails.application.config.session_store :cookie_store, key: '_dummy_session', expire_after: 30.minutes
@@ -14,7 +14,7 @@ module Workarea
14
14
 
15
15
  def test_lists_gift_cards
16
16
  gift_cards = [create_gift_card(to: 'test@email.com'), create_gift_card(to: 'foo@weblinc.com')]
17
- get admin_api.payment_gift_cards_path
17
+ get admin_api.gift_cards_path
18
18
  result = JSON.parse(response.body)['gift_cards']
19
19
 
20
20
  assert_equal(3, result.length)
@@ -24,21 +24,21 @@ module Workarea
24
24
 
25
25
  def test_creates_gift_cards
26
26
  assert_difference 'Payment::GiftCard.count', 1 do
27
- post admin_api.payment_gift_cards_path,
27
+ post admin_api.gift_cards_path,
28
28
  params: { gift_card: @sample_attributes.merge('to' => 'test@email.com').except('token') }
29
29
  end
30
30
  end
31
31
 
32
32
  def test_shows_gift_cards
33
33
  gift_card = create_gift_card(to: 'foo@weblinc.com')
34
- get admin_api.payment_gift_card_path(gift_card.id)
34
+ get admin_api.gift_card_path(gift_card.id)
35
35
  result = JSON.parse(response.body)['gift_card']
36
36
  assert_equal(gift_card, Payment::GiftCard.new(result))
37
37
  end
38
38
 
39
39
  def test_updates_gift_cards
40
40
  gift_card = create_gift_card(to: 'foo@weblinc.com')
41
- patch admin_api.payment_gift_card_path(gift_card.id),
41
+ patch admin_api.gift_card_path(gift_card.id),
42
42
  params: { gift_card: { to: 'bar@weblinc.com' } }
43
43
 
44
44
  assert_equal('bar@weblinc.com', gift_card.reload.to)
@@ -47,7 +47,15 @@ module Workarea
47
47
  def test_destroys_gift_cards
48
48
  gift_card = create_gift_card(to: 'foo@weblinc.com')
49
49
  assert_difference 'Payment::GiftCard.count', -1 do
50
- delete admin_api.payment_gift_card_path(gift_card.id)
50
+ delete admin_api.gift_card_path(gift_card.id)
51
+ end
52
+ end
53
+
54
+ def test_bulk_upserts_gift_cards
55
+ data = Array.new(10) { |i| @sample_attributes.merge('token' => "GC#{i}") }
56
+
57
+ assert_difference 'Payment::GiftCard.count', 10 do
58
+ patch admin_api.bulk_gift_cards_path, params: { gift_cards: data }
51
59
  end
52
60
  end
53
61
  end
@@ -0,0 +1,120 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ if Plugin.installed?(:api)
5
+ module Api
6
+ module Storefront
7
+ class CheckoutGiftCardsIntegrationTest < Workarea::IntegrationTest
8
+ setup :setup_checkout
9
+
10
+ def setup_checkout
11
+ create_tax_category(
12
+ name: 'Sales Tax',
13
+ code: '001',
14
+ rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
15
+ )
16
+ create_shipping_service(
17
+ name: 'Ground',
18
+ tax_code: '001',
19
+ rates: [{ price: 7.to_m }]
20
+ )
21
+
22
+ product = create_product(
23
+ name: 'Integration Product',
24
+ variants: [{ sku: 'SKU1', regular: 5.to_m, tax_code: '001' }]
25
+ )
26
+
27
+ post storefront_api.carts_path
28
+ @order_id = JSON.parse(response.body)['id']
29
+
30
+ post storefront_api.cart_items_path(@order_id),
31
+ params: {
32
+ product_id: product.id,
33
+ sku: product.skus.first,
34
+ quantity: 2
35
+ }
36
+
37
+ patch storefront_api.checkout_path(@order_id),
38
+ params: {
39
+ email: 'bcrouse@workarea.com',
40
+ billing_address: factory_defaults(:billing_address),
41
+ shipping_address: factory_defaults(:shipping_address)
42
+ }
43
+ end
44
+
45
+ def test_paying_with_gift_card
46
+ card_one = create_gift_card(token: '123', amount: 10.to_m)
47
+ card_two = create_gift_card(token: '456', amount: 20.to_m)
48
+
49
+ patch storefront_api.add_gift_card_checkout_path(@order_id),
50
+ params: { gift_card_number: card_one.token }
51
+
52
+ order = Order.find(@order_id)
53
+ payment = Payment.find(order.id)
54
+
55
+ assert_equal(1, payment.gift_cards.count)
56
+
57
+ gift_card = payment.gift_cards.first
58
+ assert_equal(card_one.token, gift_card.number)
59
+ assert_equal(10.to_m, gift_card.amount)
60
+
61
+ patch storefront_api.add_gift_card_checkout_path(@order_id),
62
+ params: { gift_card_number: card_two.token }
63
+
64
+ payment.reload
65
+
66
+ assert_equal(2, payment.gift_cards.count)
67
+
68
+ gift_card = payment.gift_cards.last
69
+ assert_equal(card_two.token, gift_card.number)
70
+ assert_equal(8.19.to_m, gift_card.amount)
71
+
72
+ delete storefront_api.remove_gift_card_checkout_path(@order_id),
73
+ params: { gift_card_id: payment.gift_cards.first.id }
74
+
75
+ payment.reload
76
+
77
+ assert_equal(1, payment.gift_cards.count)
78
+
79
+ gift_card = payment.gift_cards.first
80
+ assert_equal(card_two.token, gift_card.number)
81
+ assert_equal(18.19.to_m, gift_card.amount)
82
+
83
+ post storefront_api.complete_checkout_path(@order_id)
84
+ assert(order.reload.placed?)
85
+ end
86
+
87
+ def test_reduces_balance_on_gift_card
88
+ pass && (return) unless Workarea::GiftCards.uses_system_cards?
89
+
90
+ gift_card = create_gift_card(amount: 5.to_m)
91
+
92
+ patch storefront_api.add_gift_card_checkout_path(@order_id),
93
+ params: { gift_card_number: gift_card.token }
94
+
95
+ post storefront_api.complete_checkout_path(@order_id),
96
+ params: {
97
+ payment: 'new_card',
98
+ credit_card: {
99
+ number: '1',
100
+ month: '1',
101
+ year: Time.now.year + 1,
102
+ cvv: '999'
103
+ }
104
+ }
105
+
106
+ gift_card.reload
107
+ assert_equal(0.to_m, gift_card.balance)
108
+ assert_equal(5.to_m, gift_card.amount)
109
+ assert_equal(5.to_m, gift_card.used)
110
+
111
+ order = Order.find(@order_id)
112
+ redemption = gift_card.redemptions.first
113
+ assert_equal(order.placed_at, redemption.redeemed_at)
114
+ assert_equal(5.to_m, redemption.amount)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -4,7 +4,7 @@ module Workarea
4
4
  if Plugin.installed?(:api)
5
5
  module Api
6
6
  module Storefront
7
- class BalanceIntegrationTest < Workarea::IntegrationTest
7
+ class GiftCardsIntegrationTest < Workarea::IntegrationTest
8
8
  def test_balance_lookup
9
9
  gift_card = create_gift_card(
10
10
  to: 'bcrouse@weblinc.com',
@@ -0,0 +1,116 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class CheckoutGiftCardsIntegrationTest < Workarea::IntegrationTest
6
+ setup :setup_checkout
7
+
8
+ def setup_checkout
9
+ create_tax_category(
10
+ name: 'Sales Tax',
11
+ code: '001',
12
+ rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
13
+ )
14
+
15
+ create_shipping_service(
16
+ name: 'Ground',
17
+ tax_code: '001',
18
+ rates: [{ price: 7.to_m }]
19
+ )
20
+
21
+ product = create_product(
22
+ name: 'Integration Product',
23
+ variants: [{ sku: 'SKU1', regular: 5.to_m, tax_code: '001' }]
24
+ )
25
+
26
+ post storefront.cart_items_path,
27
+ params: {
28
+ product_id: product.id,
29
+ sku: product.skus.first,
30
+ quantity: 2
31
+ }
32
+
33
+ patch storefront.checkout_addresses_path,
34
+ params: {
35
+ email: 'bcrouse@workarea.com',
36
+ shipping_address: factory_defaults(:shipping_address),
37
+ billing_address: factory_defaults(:billing_address)
38
+ }
39
+ end
40
+
41
+ def test_paying_with_gift_cards
42
+ card_one = create_gift_card(token: '123', amount: 10.to_m)
43
+ card_two = create_gift_card(token: '456', amount: 20.to_m)
44
+
45
+ patch storefront.checkout_gift_cards_path,
46
+ params: { gift_card_number: '123' }
47
+
48
+ order = Order.first
49
+ payment = Payment.find(order.id)
50
+
51
+ assert_equal(1, payment.gift_cards.count)
52
+
53
+ gift_card = payment.gift_cards.first
54
+ assert_equal(card_one.token, gift_card.number)
55
+ assert_equal(10.to_m, gift_card.amount)
56
+
57
+ patch storefront.checkout_gift_cards_path,
58
+ params: { gift_card_number: '456' }
59
+
60
+ payment.reload
61
+
62
+ assert_equal(2, payment.gift_cards.count)
63
+
64
+ gift_card = payment.gift_cards.last
65
+ assert_equal(card_two.token, gift_card.number)
66
+ assert_equal(8.19.to_m, gift_card.amount)
67
+
68
+ delete storefront.checkout_gift_cards_path,
69
+ params: { gift_card_id: payment.gift_cards.first.id }
70
+
71
+ payment.reload
72
+
73
+ assert_equal(1, payment.gift_cards.count)
74
+
75
+ gift_card = payment.gift_cards.first
76
+ assert_equal(card_two.token, gift_card.number)
77
+ assert_equal(18.19.to_m, gift_card.amount)
78
+
79
+ patch storefront.checkout_place_order_path
80
+ assert_redirected_to(storefront.checkout_confirmation_path)
81
+ end
82
+
83
+ def test_reduces_balance_on_gift_card
84
+ pass && (return) unless Workarea::GiftCards.uses_system_cards?
85
+
86
+ gift_card = create_gift_card(token: '123', amount: 5.to_m)
87
+
88
+ patch storefront.checkout_gift_cards_path,
89
+ params: { gift_card_number: '123' }
90
+
91
+ patch storefront.checkout_place_order_path,
92
+ params: {
93
+ payment: 'new_card',
94
+ credit_card: {
95
+ number: '1',
96
+ month: 1,
97
+ year: 2020,
98
+ cvv: '999'
99
+ }
100
+ }
101
+
102
+ assert_redirected_to(storefront.checkout_confirmation_path)
103
+
104
+ gift_card.reload
105
+ assert_equal(0.to_m, gift_card.balance)
106
+ assert_equal(5.to_m, gift_card.amount)
107
+ assert_equal(5.to_m, gift_card.used)
108
+
109
+ order = Order.first
110
+ redemption = gift_card.redemptions.first
111
+ assert_equal(order.placed_at, redemption.redeemed_at)
112
+ assert_equal(5.to_m, redemption.amount)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class GiftCardsIntegrationTest < Workarea::IntegrationTest
6
+ def test_balance_lookup
7
+ gift_card = create_gift_card(to: 'test@workarea.com', amount: 12.to_m)
8
+
9
+ get storefront.gift_cards_lookup_path,
10
+ params: {
11
+ email: gift_card.to,
12
+ token: gift_card.token
13
+ }
14
+
15
+ assert_redirected_to(storefront.gift_cards_balance_path)
16
+ assert_equal(
17
+ t(
18
+ 'workarea.storefront.flash_messages.gift_card_balance',
19
+ balance: gift_card.balance.format
20
+ ),
21
+ flash[:success]
22
+ )
23
+
24
+ get storefront.gift_cards_lookup_path,
25
+ params: {
26
+ email: 'foo@workarea.com',
27
+ token: gift_card.token
28
+ }
29
+
30
+ assert_equal(
31
+ t('workarea.storefront.flash_messages.gift_card_not_found'),
32
+ flash[:error]
33
+ )
34
+
35
+ get storefront.gift_cards_lookup_path,
36
+ params: {
37
+ email: gift_card.to,
38
+ token: '125'
39
+ }
40
+
41
+ assert_equal(
42
+ t('workarea.storefront.flash_messages.gift_card_not_found'),
43
+ flash[:error]
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class PurchaseGiftCardIntegrationTest < Workarea::IntegrationTest
6
+ include Storefront::IntegrationTest
7
+
8
+ def test_generates_gift_card
9
+ pass && (return) unless Workarea::GiftCards.uses_system_cards?
10
+
11
+ product = create_product(
12
+ name: 'Gift Card',
13
+ gift_card: true,
14
+ customizations: 'gift_card',
15
+ variants: [{ sku: 'GIFTCARD', regular: 10.to_m }]
16
+ )
17
+
18
+ create_fulfillment_sku(id: 'GIFTCARD', policy: :create_gift_card)
19
+
20
+ post storefront.cart_items_path,
21
+ params: {
22
+ product_id: product.id,
23
+ sku: product.skus.first,
24
+ email: 'recipient@workarea.com',
25
+ from: 'from@workarea.com',
26
+ message: 'this is a message',
27
+ quantity: 1
28
+ }
29
+
30
+ complete_checkout
31
+
32
+ assert_equal(1, Payment::GiftCard.count)
33
+
34
+ card = Payment::GiftCard.first
35
+ assert_equal(10.to_m, card.amount)
36
+ assert_equal(0.to_m, card.used)
37
+ assert_equal(10.to_m, card.balance)
38
+ assert(card.order_id.present?)
39
+ assert(card.purchased?)
40
+
41
+ assert_equal(2, ActionMailer::Base.deliveries.length)
42
+
43
+ gift_card_email = ActionMailer::Base.deliveries.detect do |email|
44
+ assert_includes(email.to, 'recipient@workarea.com')
45
+ end
46
+
47
+ gift_card_email.parts.each do |part|
48
+ assert_includes(part.body, card.token)
49
+ assert_includes(part.body, 'from@workarea.com')
50
+ assert_includes(part.body, 'this is a message')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end