workarea-gift_cards 3.4.10 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{.eslintrc → .eslintrc.json} +12 -1
- data/.github/workflows/ci.yml +10 -8
- data/.rubocop.yml +2 -197
- data/.stylelintrc.json +8 -0
- data/CHANGELOG.md +40 -20
- data/Gemfile +3 -5
- data/README.md +25 -1
- data/app/controllers/workarea/api/admin/gift_cards_controller.rb +309 -0
- data/app/controllers/workarea/api/storefront/checkouts_controller.decorator +6 -0
- data/app/controllers/workarea/api/storefront/gift_cards_controller.rb +2 -8
- data/app/controllers/workarea/storefront/checkout/gift_cards_controller.rb +32 -0
- data/app/controllers/workarea/storefront/gift_cards_controller.rb +15 -16
- data/app/models/workarea/checkout/steps/gift_card.rb +72 -0
- data/app/models/workarea/fulfillment/policies/create_gift_card.rb +30 -0
- data/app/models/workarea/payment.decorator +25 -7
- data/app/models/workarea/payment/authorize/gift_card.rb +7 -20
- data/app/models/workarea/payment/capture/gift_card.rb +5 -7
- data/app/models/workarea/payment/gift_card.rb +1 -1
- data/app/models/workarea/payment/gift_card_operation.rb +9 -0
- data/app/models/workarea/payment/purchase/gift_card.rb +24 -1
- data/app/models/workarea/payment/refund/gift_card.rb +9 -14
- data/app/models/workarea/payment/tender/gift_card.rb +3 -10
- data/app/models/workarea/search/admin/order.decorator +2 -4
- data/app/seeds/workarea/gift_card_seeds.rb +7 -7
- data/app/view_models/workarea/storefront/gift_card_order_pricing.rb +19 -20
- data/app/view_models/workarea/storefront/order_view_model.decorator +2 -22
- data/app/views/workarea/admin/payment_gift_cards/_menu.html.haml +2 -1
- data/app/views/workarea/storefront/checkouts/_gift_card_error.html.haml +8 -6
- data/app/views/workarea/storefront/checkouts/_gift_card_payment.html.haml +20 -12
- data/app/views/workarea/storefront/gift_card_mailer/created.html.haml +1 -1
- data/app/views/workarea/storefront/order_mailer/_gift_card_summary.html.haml +6 -5
- data/app/views/workarea/storefront/orders/_gift_card_summary.html.haml +2 -2
- data/app/views/workarea/storefront/products/templates/_gift_card.html.haml +5 -5
- data/app/workers/workarea/log_gift_card_redemption.rb +16 -9
- data/config/initializers/configuration.rb +7 -4
- data/config/initializers/fields.rb +14 -0
- data/config/locales/en.yml +14 -4
- data/config/routes.rb +9 -2
- data/lib/workarea/gift_cards.rb +9 -0
- data/lib/workarea/gift_cards/gateway.rb +128 -0
- data/lib/workarea/gift_cards/version.rb +1 -1
- data/test/documentation/workarea/api/admin/gift_cards_documentation_test.rb +24 -10
- data/test/documentation/workarea/api/storefront/gift_cards_documentation_test.rb +57 -50
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/integration/workarea/api/admin/gift_card_integration_test.rb +13 -5
- data/test/integration/workarea/api/storefront/checkout_gift_cards_integration_test.rb +120 -0
- data/test/integration/workarea/api/storefront/{balance_integration_test.rb → gift_cards_integration_test.rb} +1 -1
- data/test/integration/workarea/storefront/checkout_gift_cards_integration_test.rb +116 -0
- data/test/integration/workarea/storefront/gift_cards_integration_test.rb +48 -0
- data/test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb +55 -0
- data/test/lib/workarea/gift_cards/gateway_test.rb +131 -0
- data/test/models/workarea/checkout/steps/gift_card_test.rb +104 -0
- data/test/models/workarea/fulfillment/policies/create_gift_card_test.rb +47 -0
- data/test/models/workarea/gift_card_payment_test.rb +15 -3
- data/test/models/workarea/payment/purchase/gift_card_test.rb +11 -8
- data/test/queries/workarea/admin_redemptions_export_test.rb +31 -35
- data/test/system/workarea/storefront/gift_cards_system_test.rb +8 -2
- data/test/view_models/workarea/storefront/gift_card_order_pricing_test.rb +113 -0
- data/test/workers/workarea/log_gift_card_redemption_test.rb +1 -1
- data/workarea-gift_cards.gemspec +4 -4
- metadata +32 -25
- data/.eslintignore +0 -2
- data/.scss-lint.yml +0 -188
- data/app/controllers/workarea/api/admin/payment_gift_cards_controller.rb +0 -49
- data/app/controllers/workarea/storefront/checkouts_controller.decorator +0 -24
- data/app/services/workarea/checkout/steps/gift_card.rb +0 -49
- data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +0 -32
- data/app/view_models/workarea/storefront/checkout/summary_view_model.decorator +0 -11
- data/app/workers/workarea/create_ordered_gift_cards.rb +0 -47
- data/config/initializers/jump_to_navigation.rb +0 -3
- data/test/integration/workarea/api/storefront/checkout_integration_test.rb +0 -161
- data/test/integration/workarea/storefront/gift_card_integration_test.rb +0 -226
- data/test/services/workarea/checkout/steps/gift_card_test.rb +0 -87
- data/test/view_models/workarea/storefront/checkout/gift_card_payment_view_model_test.rb +0 -65
- data/test/workers/workarea/create_ordered_gift_cards_test.rb +0 -39
@@ -1,87 +0,0 @@
|
|
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
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Workarea
|
4
|
-
module Storefront
|
5
|
-
module Checkout
|
6
|
-
class GiftCardPaymentViewModelTest < TestCase
|
7
|
-
def test_order_covered_by_gift_card_when_amounts_match
|
8
|
-
product = create_product
|
9
|
-
order = create_order
|
10
|
-
order.add_item(sku: product.skus.first, quantity: 1, product_id: product.id)
|
11
|
-
Pricing.perform(order)
|
12
|
-
order.reload
|
13
|
-
gift_card = create_gift_card(amount: order.total_price, token: 'foo')
|
14
|
-
payment = create_payment(id: order.id)
|
15
|
-
payment.set_gift_card(number: gift_card.token)
|
16
|
-
checkout = Workarea::Checkout.new(order)
|
17
|
-
step = Workarea::Checkout::Steps::Payment.new(checkout)
|
18
|
-
step.update(gift_card: { number: gift_card.token })
|
19
|
-
view_model = Storefront::Checkout::PaymentViewModel.new(step)
|
20
|
-
|
21
|
-
assert(view_model.show_gift_card?)
|
22
|
-
assert(view_model.order_covered_by_gift_card?)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_order_covered_by_gift_card_when_balance_exceeds_total
|
26
|
-
product = create_product
|
27
|
-
order = create_order
|
28
|
-
order.add_item(sku: product.skus.first, quantity: 1, product_id: product.id)
|
29
|
-
Pricing.perform(order)
|
30
|
-
order.reload
|
31
|
-
gift_card = create_gift_card(amount: order.total_price + 1.to_m, token: 'foo')
|
32
|
-
payment = create_payment(id: order.id)
|
33
|
-
payment.set_gift_card(number: gift_card.token)
|
34
|
-
checkout = Workarea::Checkout.new(order)
|
35
|
-
step = Workarea::Checkout::Steps::Payment.new(checkout)
|
36
|
-
step.update(gift_card: { number: gift_card.token })
|
37
|
-
view_model = Storefront::Checkout::PaymentViewModel.new(step)
|
38
|
-
|
39
|
-
assert(view_model.show_gift_card?)
|
40
|
-
assert(view_model.order_covered_by_gift_card?)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_order_not_covered_by_gift_card_when_total_exceeds_balance
|
44
|
-
product = create_product
|
45
|
-
order = create_order
|
46
|
-
order.add_item(sku: product.skus.first, quantity: 1, product_id: product.id)
|
47
|
-
Pricing.perform(order)
|
48
|
-
order.reload
|
49
|
-
gift_card = create_gift_card(amount: 1.to_m, token: 'foo')
|
50
|
-
payment = create_payment(id: order.id)
|
51
|
-
payment.set_gift_card(number: gift_card.token)
|
52
|
-
checkout = Workarea::Checkout.new(order)
|
53
|
-
step = Workarea::Checkout::Steps::Payment.new(checkout)
|
54
|
-
step.update(gift_card: { number: gift_card.token })
|
55
|
-
view_model = Storefront::Checkout::PaymentViewModel.new(step)
|
56
|
-
|
57
|
-
assert(view_model.show_gift_card?)
|
58
|
-
assert_equal(5.to_m, order.total_price)
|
59
|
-
assert_equal(1.to_m, view_model.gift_card_balance)
|
60
|
-
refute(view_model.order_covered_by_gift_card?)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Workarea
|
4
|
-
class CreateOrderedGiftCardsTest < TestCase
|
5
|
-
def test_perform
|
6
|
-
order = create_order(id: 123)
|
7
|
-
order.add_item(
|
8
|
-
product_id: 'PROD',
|
9
|
-
sku: 'SKU',
|
10
|
-
product_attributes: { digital: true },
|
11
|
-
gift_card: true,
|
12
|
-
customizations: {
|
13
|
-
'email' => 'bob@workarea.com',
|
14
|
-
'from' => 'system@workarea.com',
|
15
|
-
'message' => 'Hello'
|
16
|
-
},
|
17
|
-
price_adjustments: [
|
18
|
-
{
|
19
|
-
amount: 10.to_m
|
20
|
-
}
|
21
|
-
]
|
22
|
-
)
|
23
|
-
|
24
|
-
CreateFulfillment.new(order).perform
|
25
|
-
CreateOrderedGiftCards.new.perform('123')
|
26
|
-
card = Payment::GiftCard.first
|
27
|
-
assert(card.present?)
|
28
|
-
assert(card.notify)
|
29
|
-
assert(card.purchased)
|
30
|
-
assert_equal('bob@workarea.com', card.to)
|
31
|
-
assert_equal('system@workarea.com', card.from)
|
32
|
-
assert_equal('Hello', card.message)
|
33
|
-
assert_equal(order.id, card.order_id)
|
34
|
-
|
35
|
-
fulfillment = Fulfillment.find(order.id)
|
36
|
-
assert_equal(1, fulfillment.items.first.quantity_shipped)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|