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
@@ -0,0 +1,97 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module GiftCards
5
+ class GatewayTest < TestCase
6
+ setup :gift_card
7
+
8
+ def gift_card
9
+ @gift_card ||= create_gift_card(amount: 10.to_m)
10
+ end
11
+
12
+ def tender
13
+ @tender ||= Payment::Tender::GiftCard.new(
14
+ number: gift_card.token,
15
+ amount: 5.to_m
16
+ )
17
+ end
18
+
19
+ def gateway
20
+ Gateway.new
21
+ end
22
+
23
+ def test_authorize
24
+ response = gateway.authorize(200, tender)
25
+
26
+ assert(response.success?)
27
+ assert(response.message.present?)
28
+
29
+ gift_card.reload
30
+ assert_equal(8.to_m, gift_card.balance)
31
+ assert_equal(2.to_m, gift_card.used)
32
+ end
33
+
34
+ def test_cancel
35
+ response = gateway.authorize(200, tender)
36
+ assert(response.success?)
37
+
38
+ response = gateway.cancel(200, tender)
39
+
40
+ assert(response.success?)
41
+ assert(response.message.present?)
42
+
43
+ gift_card.reload
44
+ assert_equal(10.to_m, gift_card.balance)
45
+ assert_equal(0.to_m, gift_card.used)
46
+ end
47
+
48
+ def test_capture
49
+ assert(gateway.capture(200, tender).success?)
50
+ assert_equal(10.to_m, gift_card.reload.balance)
51
+ end
52
+
53
+ def test_purchase
54
+ response = gateway.purchase(200, tender)
55
+
56
+ assert(response.success?)
57
+ assert(response.message.present?)
58
+
59
+ gift_card.reload
60
+ assert_equal(8.to_m, gift_card.balance)
61
+ assert_equal(2.to_m, gift_card.used)
62
+ end
63
+
64
+ def test_refund
65
+ response = gateway.authorize(200, tender)
66
+ assert(response.success?)
67
+
68
+ response = gateway.refund(200, tender)
69
+
70
+ assert(response.success?)
71
+ assert(response.message.present?)
72
+
73
+ gift_card.reload
74
+ assert_equal(10.to_m, gift_card.balance)
75
+ assert_equal(0.to_m, gift_card.used)
76
+ end
77
+
78
+ def test_balance
79
+ balance = gateway.balance(gift_card.number)
80
+ assert_equal(10.to_m, balance)
81
+
82
+ gateway.authorize(300, tender)
83
+
84
+ balance = gateway.balance(gift_card.number)
85
+ assert_equal(7.to_m, balance)
86
+ end
87
+
88
+ def test_lookup
89
+ lookup = gateway.lookup(email: gift_card.to, token: gift_card.token)
90
+ assert_equal(gift_card.id, lookup.id)
91
+
92
+ lookup = gateway.lookup(email: 'foo', token: gift_card.token)
93
+ assert_nil(lookup)
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Checkout
5
+ module Steps
6
+ class GiftCardTest < TestCase
7
+ setup :setup_checkout
8
+
9
+ def setup_checkout
10
+ create_shipping_service(name: 'Ground', rates: [{ price: 7.to_m }])
11
+
12
+ product = create_product(
13
+ name: 'Integration Product',
14
+ variants: [{ sku: 'SKU1', regular: 5.to_m }]
15
+ )
16
+
17
+ @order = create_order.tap do |order|
18
+ order.add_item(
19
+ product_id: product.id,
20
+ sku: product.skus.first,
21
+ quantity: 2
22
+ )
23
+ end
24
+
25
+ @checkout = Checkout.new(@order)
26
+ @checkout.update(
27
+ email: 'test@workarea.com',
28
+ billing_address: factory_defaults(:billing_address),
29
+ shipping_address: factory_defaults(:shipping_address),
30
+ shipping_service: 'Ground'
31
+ )
32
+
33
+ @payment = @checkout.payment
34
+ end
35
+
36
+ def test_update
37
+ card_one = create_gift_card(amount: 10.to_m)
38
+ card_two = create_gift_card(amount: 20.to_m)
39
+
40
+ step = Checkout::Steps::GiftCard.new(@checkout)
41
+ assert(step.update(gift_card_number: " #{card_one.number} "))
42
+
43
+ @payment.reload
44
+ assert_equal(1, @payment.gift_cards.count)
45
+
46
+ tender = @payment.gift_cards.first
47
+ assert_equal(card_one.token, tender.number)
48
+ assert_equal(10.to_m, tender.amount)
49
+
50
+ @order.reload
51
+ assert_equal(17.to_m, @order.total_price)
52
+
53
+ step = Checkout::Steps::GiftCard.new(@checkout)
54
+ assert(step.update(gift_card_number: card_two.number))
55
+
56
+ @payment.reload
57
+ assert_equal(2, @payment.gift_cards.count)
58
+
59
+ tender = @payment.gift_cards.first
60
+ assert_equal(card_one.token, tender.number)
61
+ assert_equal(10.to_m, tender.amount)
62
+
63
+ tender = @payment.gift_cards.last
64
+ assert_equal(card_two.token, tender.number)
65
+ assert_equal(7.to_m, tender.amount)
66
+ end
67
+
68
+ def test_remove
69
+ card_one = create_gift_card(amount: 10.to_m)
70
+ card_two = create_gift_card(amount: 20.to_m)
71
+
72
+ step = Checkout::Steps::GiftCard.new(@checkout)
73
+ step.update(gift_card_number: card_one.token)
74
+ step.update(gift_card_number: card_two.token)
75
+
76
+ assert_equal(2, @payment.reload.gift_cards.count)
77
+ assert_equal(10.to_m, @payment.gift_cards.first.amount)
78
+ assert_equal(7.to_m, @payment.gift_cards.last.amount)
79
+
80
+ step.remove(@payment.gift_cards.first)
81
+ assert_equal(1, @payment.reload.gift_cards.count)
82
+ assert_equal(card_two.token, @payment.gift_cards.first.number)
83
+ assert_equal(17.to_m, @payment.gift_cards.first.amount)
84
+ end
85
+
86
+ def test_complete?
87
+ card = create_gift_card(amount: 10.to_m)
88
+ step = Checkout::Steps::GiftCard.new(@checkout)
89
+
90
+ assert(step.complete?)
91
+
92
+ @payment.add_gift_card(number: card.number)
93
+ assert(step.complete?)
94
+
95
+ @payment.add_gift_card(number: '')
96
+ refute(step.complete?)
97
+
98
+ @payment.reload.add_gift_card(number: '1234')
99
+ refute(step.complete?)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class Fulfillment
5
+ module Policies
6
+ class CreateGiftCardTest < TestCase
7
+ def test_process
8
+ order = create_order
9
+ order.add_item(
10
+ product_id: 'PROD',
11
+ sku: 'SKU',
12
+ gift_card: true,
13
+ requires_shipping: false,
14
+ customizations: {
15
+ 'email' => 'bob@workarea.com',
16
+ 'from' => 'system@workarea.com',
17
+ 'message' => 'Hello'
18
+ },
19
+ price_adjustments: [{ amount: 10.to_m }]
20
+ )
21
+
22
+ fulfillment = Fulfillment.new(
23
+ id: order.id,
24
+ items: [{ order_item_id: order.items.first.id, quantity: 1 }]
25
+ )
26
+
27
+ sku = create_fulfillment_sku(id: 'SKU', policy: :create_gift_card)
28
+ policy = CreateGiftCard.new(sku)
29
+
30
+ policy.process(order_item: order.items.first, fulfillment: fulfillment)
31
+
32
+ card = Payment::GiftCard.first
33
+ assert(card.present?)
34
+ assert(card.notify)
35
+ assert(card.purchased)
36
+ assert_equal('bob@workarea.com', card.to)
37
+ assert_equal('system@workarea.com', card.from)
38
+ assert_equal('Hello', card.message)
39
+ assert_equal(order.id, card.order_id)
40
+ assert_equal(10.to_m, card.amount)
41
+
42
+ assert_equal(1, fulfillment.items.first.quantity_shipped)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -2,11 +2,23 @@ require 'test_helper'
2
2
 
3
3
  module Workarea
4
4
  class GiftCardPaymentTest < TestCase
5
- def test_set_gift_card
5
+ def test_add_gift_card
6
+ Workarea.config.max_gift_cards_per_order = 2
7
+
6
8
  payment = create_payment
7
9
 
8
- payment.set_gift_card(number: '1234')
9
- assert_equal('1234', payment.gift_card.number)
10
+ assert(payment.add_gift_card(number: '1234'))
11
+ assert_equal(1, payment.gift_cards.count)
12
+ assert_equal('1234', payment.gift_cards.first.number)
13
+
14
+ assert(payment.add_gift_card(number: '1234'))
15
+ assert_equal(1, payment.gift_cards.count)
16
+
17
+ assert(payment.add_gift_card(number: '3456'))
18
+ assert_equal(2, payment.gift_cards.count)
19
+
20
+ refute(payment.add_gift_card(number: '7890'))
21
+ assert_equal(2, payment.gift_cards.count)
10
22
  end
11
23
  end
12
24
  end
@@ -15,16 +15,17 @@ module Workarea
15
15
  end
16
16
 
17
17
  def test_complete!
18
- payment.set_gift_card(number: 'token')
18
+ payment.add_gift_card(number: 'token')
19
+ gift_card = payment.gift_cards.first
19
20
 
20
- transaction = payment.gift_card.build_transaction(amount: 10.to_m)
21
+ transaction = gift_card.build_transaction(amount: 10.to_m)
21
22
 
22
- GiftCard.new(payment.gift_card, transaction).complete!
23
+ GiftCard.new(gift_card, transaction).complete!
23
24
  refute(transaction.success?)
24
25
  assert(transaction.message.present?)
25
26
 
26
- transaction = payment.gift_card.build_transaction(amount: 3.to_m)
27
- purchase = GiftCard.new(payment.gift_card, transaction)
27
+ transaction = gift_card.build_transaction(amount: 3.to_m)
28
+ purchase = GiftCard.new(gift_card, transaction)
28
29
  purchase.complete!
29
30
 
30
31
  assert(transaction.success?)
@@ -32,10 +33,12 @@ module Workarea
32
33
  end
33
34
 
34
35
  def test_cancel!
35
- payment.set_gift_card(number: 'token')
36
- transaction = payment.gift_card.build_transaction(amount: 5.to_m)
36
+ payment.add_gift_card(number: 'token')
37
+ gift_card = payment.gift_cards.first
37
38
 
38
- purchase = GiftCard.new(payment.gift_card, transaction)
39
+ transaction = gift_card.build_transaction(amount: 5.to_m)
40
+
41
+ purchase = GiftCard.new(gift_card, transaction)
39
42
  purchase.cancel!
40
43
 
41
44
  refute(transaction.cancellation.present?)
@@ -3,50 +3,46 @@ require 'test_helper'
3
3
  module Workarea
4
4
  class AdminRedemptionsExportTest < IntegrationTest
5
5
  def test_total
6
- Workarea.with_config do |config|
7
- config.per_page = 5
8
- config.bulk_action_per_page = 5
6
+ Workarea.config.per_page = 5
7
+ Workarea.config.bulk_action_per_page = 5
9
8
 
9
+ card = create_gift_card(amount: 20)
10
+ create_gift_card_redemption(gift_card: card, amount: 10)
11
+ create_gift_card_redemption(gift_card: card, amount: 10)
12
+ query = Search::AdminGiftCards.new
13
+
14
+ export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
15
+ assert_equal(2, export.total)
16
+
17
+ 15.times do
10
18
  card = create_gift_card(amount: 20)
11
19
  create_gift_card_redemption(gift_card: card, amount: 10)
12
- create_gift_card_redemption(gift_card: card, amount: 10)
13
- query = Search::AdminGiftCards.new
20
+ end
14
21
 
15
- export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
16
- assert_equal(2, export.total)
22
+ export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
23
+ assert_equal(17, export.total)
24
+ end
17
25
 
18
- 15.times do
19
- card = create_gift_card(amount: 20)
20
- create_gift_card_redemption(gift_card: card, amount: 10)
21
- end
26
+ def test_scroll
27
+ Workarea.config.bulk_action_per_page = 2
22
28
 
23
- export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
24
- assert_equal(17, export.total)
29
+ 5.times do
30
+ card = create_gift_card(amount: 20)
31
+ create_gift_card_redemption(gift_card: card, amount: 10)
25
32
  end
26
- end
27
33
 
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)
34
+ query = Search::AdminGiftCards.new
35
+ export = AdminRedemptionsExport.new(gift_cards_query_id: query.to_gid_param)
36
+ count = 0
37
+ passes = 0
38
+
39
+ export.scroll do |results|
40
+ count += results.size
41
+ passes += 1
49
42
  end
43
+
44
+ assert_equal(5, count)
45
+ assert_equal(3, passes)
50
46
  end
51
47
  end
52
48
  end
@@ -9,7 +9,6 @@ module Workarea
9
9
  product = create_product(
10
10
  name: 'Gift Card',
11
11
  gift_card: true,
12
- digital: true,
13
12
  template: 'gift_card',
14
13
  customizations: 'gift_card',
15
14
  variants: [
@@ -19,6 +18,10 @@ module Workarea
19
18
  ]
20
19
  )
21
20
 
21
+ create_fulfillment_sku(id: 'SKU1', policy: :create_gift_card)
22
+ create_fulfillment_sku(id: 'SKU2', policy: :create_gift_card)
23
+ create_fulfillment_sku(id: 'SKU3', policy: :create_gift_card)
24
+
22
25
  visit storefront.product_path(product)
23
26
 
24
27
  assert(page.has_content?('Gift Card'))
@@ -50,7 +53,6 @@ module Workarea
50
53
  product = create_product(
51
54
  name: 'Gift Card',
52
55
  gift_card: true,
53
- digital: true,
54
56
  template: 'gift_card',
55
57
  customizations: 'gift_card',
56
58
  variants: [
@@ -60,6 +62,10 @@ module Workarea
60
62
  ]
61
63
  )
62
64
 
65
+ create_fulfillment_sku(id: 'SKU1', policy: :create_gift_card)
66
+ create_fulfillment_sku(id: 'SKU2', policy: :create_gift_card)
67
+ create_fulfillment_sku(id: 'SKU3', policy: :create_gift_card)
68
+
63
69
  visit storefront.product_path(product)
64
70
 
65
71
  within '.product-details__add-to-cart-form' do
@@ -0,0 +1,113 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class GiftCardOrderPricingTest < TestCase
6
+ class TestViewModel < ApplicationViewModel
7
+ include OrderPricing
8
+ include GiftCardOrderPricing
9
+
10
+ alias_method :order, :model
11
+
12
+ def payment
13
+ @payment ||= options[:payment]
14
+ end
15
+ end
16
+
17
+ setup :payment, :setup_gift_cards
18
+
19
+ def order
20
+ @order ||= create_order(total_price: 50.to_m)
21
+ end
22
+
23
+ def payment
24
+ @payment ||= create_payment(id: order.id)
25
+ end
26
+
27
+ def setup_gift_cards
28
+ Workarea.config.max_gift_cards_per_order = 5
29
+
30
+ create_gift_card(token: '123', amount: 10.to_m)
31
+ create_gift_card(token: '456', amount: 20.to_m)
32
+ create_gift_card(token: '789', amount: 30.to_m)
33
+ end
34
+
35
+ def view_model_instance
36
+ TestViewModel.new(order, payment: payment)
37
+ end
38
+
39
+ def test_gift_cards
40
+ assert(view_model_instance.gift_cards.blank?)
41
+
42
+ payment.gift_cards.build(number: '123')
43
+ assert(view_model_instance.gift_cards.blank?)
44
+
45
+ payment.reload
46
+ payment.add_gift_card(number: '123')
47
+ assert_equal(1, view_model_instance.gift_cards.count)
48
+ assert_equal('123', view_model_instance.gift_cards.first.number)
49
+ end
50
+
51
+ def test_gift_card?
52
+ refute(view_model_instance.gift_card?)
53
+
54
+ payment.add_gift_card(number: '123')
55
+ assert(view_model_instance.gift_card?)
56
+ end
57
+
58
+ def test_gift_card_amount
59
+ assert_equal(0.to_m, view_model_instance.gift_card_amount)
60
+
61
+ payment.add_gift_card(number: '123', amount: 10.to_m)
62
+ assert_equal(10.to_m, view_model_instance.gift_card_amount)
63
+
64
+ payment.add_gift_card(number: '456', amount: 5.to_m)
65
+ assert_equal(15.to_m, view_model_instance.gift_card_amount)
66
+ end
67
+
68
+ def test_gift_card_balance
69
+ assert_equal(0.to_m, view_model_instance.gift_card_balance)
70
+
71
+ payment.add_gift_card(number: '123')
72
+ assert_equal(10.to_m, view_model_instance.gift_card_balance)
73
+
74
+ payment.add_gift_card(number: '456')
75
+ assert_equal(30.to_m, view_model_instance.gift_card_balance)
76
+ end
77
+
78
+ def test_total_before_gift_cards
79
+ assert_equal(50.to_m, view_model_instance.total_before_gift_cards)
80
+
81
+ payment.add_gift_card(number: '123', amount: 10.to_m)
82
+ assert_equal(50.to_m, view_model_instance.total_before_gift_cards)
83
+
84
+ payment.add_gift_card(number: '456', amount: 20.to_m)
85
+ assert_equal(50.to_m, view_model_instance.total_before_gift_cards)
86
+ end
87
+
88
+ def test_advance_payment_amount
89
+ assert_equal(0.to_m, view_model_instance.advance_payment_amount)
90
+
91
+ payment.add_gift_card(number: '123', amount: 10.to_m)
92
+ assert_equal(10.to_m, view_model_instance.advance_payment_amount)
93
+
94
+ payment.add_gift_card(number: '456', amount: 20.to_m)
95
+ assert_equal(30.to_m, view_model_instance.advance_payment_amount)
96
+
97
+ payment.add_gift_card(number: '789', amount: 20.to_m)
98
+ assert_equal(50.to_m, view_model_instance.advance_payment_amount)
99
+ end
100
+
101
+ def test_failed_gift_card
102
+ assert_nil(view_model_instance.failed_gift_card)
103
+
104
+ payment.add_gift_card(number: '123')
105
+ assert_nil(view_model_instance.failed_gift_card)
106
+
107
+ Workarea.config.max_gift_cards_per_order = 1
108
+ payment.add_gift_card(number: '456')
109
+ assert_equal('456', view_model_instance.failed_gift_card.number)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -7,7 +7,7 @@ module Workarea
7
7
 
8
8
  order = Order.create!(placed_at: Time.now)
9
9
  payment = Payment.create!(id: order.id)
10
- payment.set_gift_card(number: '123456')
10
+ payment.add_gift_card(number: '123456')
11
11
 
12
12
  LogGiftCardRedemption.new.perform(order.id)
13
13
  LogGiftCardRedemption.new.perform(order.id)
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.name = 'workarea-gift_cards'
7
7
  s.version = Workarea::GiftCards::VERSION
8
8
  s.authors = ['bcrouse']
9
- s.email = ['bcrouse@weblinc.com']
9
+ s.email = ['bcrouse@workarea.com']
10
10
  s.homepage = 'https://github.com/workarea-commerce/workarea-gift-cards'
11
- s.summary = 'Gift Cards plugin for the Workarea commerce platform'
12
- s.description = 'Adds built-in gift cards to the Workarea commerce platform.'
11
+ s.summary = 'Gift Cards plugin for the Workarea Commerce Platform'
12
+ s.description = 'Adds built-in digital gift cards to the Workarea Commerce Platform.'
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
 
@@ -17,5 +17,5 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.required_ruby_version = '>= 2.3.0'
19
19
 
20
- s.add_dependency 'workarea', '~> 3.x', '>= 3.3.x', '< 3.5.x'
20
+ s.add_dependency 'workarea', '~> 3.x', '>= 3.5.x'
21
21
  end