workarea-gift_cards 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cad03a3ad49bb8c2ca3708d40d76a92a15cc54957a94f1470d4c523a14967325
4
- data.tar.gz: 8e42247357331ef7475c3110c18ffdd2fac3c9b4c917ab6e8f1104c055e0a318
3
+ metadata.gz: 4640c0b94ade3085580304d3a0220f85cb73a570d93e3a7c945081a1bda0a72f
4
+ data.tar.gz: bcab8a176b67c59e809a89d0b459d3f01dd123d91e05b6aab8f51f3ea13766cd
5
5
  SHA512:
6
- metadata.gz: a21ec364a0d7534e4df67b63fbe304846b6dd1b15c60a46dd8533e7a020c184b015f5e95d9ebb4d05ea4f3aa75a02721df72569eb1f68d0d49db44d434b772aa
7
- data.tar.gz: a7cc9714355e711aebb5db593be66ff917b611474d59e62d3789957668c6e5573b0f12eb4aeff3ba3cf8fe412185d3689ebd69fb110ea342e5b6759401d9d8fe
6
+ metadata.gz: 4f8f96a3442cabeb3cc94aef6fd542b6a77d0c792947cf795edade12f36f6e67ca1ef743632415a2d4d689990e2f70eeefa8a4b28024699f44658851eeb2e18f
7
+ data.tar.gz: 800f842ad499e8adac230b8fabc356ad890d82c38f8269f449baf2e0f5082740e092df674c14c43c3c2b4a038bad49a9b4e7d13897aab24415668232285c5743
@@ -1,3 +1,34 @@
1
+ Workarea Gift Cards 4.0.3 (2020-08-19)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Fix Update Step Result
5
+
6
+ Prevent returning `false` early when no Gift Card params are set. This
7
+ ensures the step won't block checkout.
8
+
9
+ Tom Scott
10
+
11
+ * Improve Test Experience For Custom Gift Card Gateways
12
+
13
+ If you're creating a new custom gift card gateway for your project, and
14
+ you want to use the tests from base as a starting point for that
15
+ integration, you currently must duplicate the tests from the plugin in
16
+ your own plugin, which makes things a bit harder but also removes the
17
+ ability to take on updates to the test in case of bug fixes. To improve
18
+ this experience, the `Workarea::GiftCards::GatewayTest` has been
19
+ modified to more easily allow decorating it in a host application. All
20
+ tests are now wrapped in a VCR cassette whose name is defined by the
21
+ parameterized gateway class name and the name of the method being
22
+ tested. This will activate and create cassettes in the real world when a
23
+ gateway makes an outbound HTTP call, similar to
24
+ `CreditCardIntegrationTest`.
25
+
26
+ GIFTCARDS-9
27
+
28
+ Tom Scott
29
+
30
+
31
+
1
32
  Workarea Gift Cards 4.0.2 (2020-03-03)
2
33
  --------------------------------------------------------------------------------
3
34
 
data/README.md CHANGED
@@ -107,6 +107,30 @@ end
107
107
 
108
108
  Note that it is set to a string of the class constant, and not an instance of the class. The system constantizes and initializes a new instance whenever it uses the gateway to ensure autoloading works correctly and so a gateway that cares about the current state of the application is applied correctly. This is most relevant in multi-site environments where each site might want to use their own gift card gateway.
109
109
 
110
+ ### Testing Your Custom Gateway
111
+
112
+ Workarea comes with unit tests for the main Gateway class, and you can
113
+ decorate this test to provide your own setup code. A minimal
114
+ implementation would look as follows:
115
+
116
+ ```ruby
117
+ module Workarea
118
+ module GiftCards
119
+ decorate GatewayTest do
120
+ # Provide your own Gateway instance here to use it in each test.
121
+ def gateway
122
+ CustomGiftCardGateway.new
123
+ end
124
+
125
+ # Provide a custom object representing a Gift Card on your
126
+ # 3rd-party service.
127
+ def gift_card
128
+ CustomGiftCard.new(balance: 10.to_m)
129
+ end
130
+ end
131
+ end
132
+ end
133
+ ```
110
134
 
111
135
  Workarea Commerce Documentation
112
136
  --------------------------------------------------------------------------------
@@ -12,8 +12,9 @@ module Workarea
12
12
  #
13
13
  def update(params = {})
14
14
  gift_card_params = extract_gift_card_params(params)
15
- return false unless applicable_gift_card?(gift_card_params)
16
- return false unless add_gift_card(gift_card_params)
15
+
16
+ add_gift_card(gift_card_params) if applicable_gift_card?(gift_card_params)
17
+
17
18
  update_order
18
19
  end
19
20
 
@@ -1,5 +1,5 @@
1
1
  module Workarea
2
2
  module GiftCards
3
- VERSION = '4.0.2'.freeze
3
+ VERSION = '4.0.3'.freeze
4
4
  end
5
5
  end
@@ -5,10 +5,17 @@ module Workarea
5
5
  class GatewayTest < TestCase
6
6
  setup :gift_card
7
7
 
8
+ # Override this to instantiate an object that models a gift card
9
+ # on the remote system.
8
10
  def gift_card
9
11
  @gift_card ||= create_gift_card(amount: 10.to_m)
10
12
  end
11
13
 
14
+ # The tender object used on an order that will be passed into each
15
+ # gateway method call. Override this to provide your own
16
+ # information.
17
+ #
18
+ # @return [Payment::Tender::GiftCard]
12
19
  def tender
13
20
  @tender ||= Payment::Tender::GiftCard.new(
14
21
  number: gift_card.token,
@@ -16,81 +23,108 @@ module Workarea
16
23
  )
17
24
  end
18
25
 
26
+ # Override this in your test to instantiate a gateway for use in
27
+ # tests. The class name of the gateway is used to generate the
28
+ # folder name for the VCR cassettes used within this test.
19
29
  def gateway
20
30
  Gateway.new
21
31
  end
22
32
 
33
+ # Use the class name of the gateway to generate a directory in
34
+ # `test/vcr_cassettes` where all cassettes for the custom gateway
35
+ # will go. This doesn't need to be overridden unless you need to
36
+ # customize the gateway cassette directory name.
37
+ #
38
+ # @return [String]
39
+ def gateway_cassette_name
40
+ gateway.class.name.systemize
41
+ end
42
+
23
43
  def test_authorize
24
- response = gateway.authorize(200, tender)
44
+ VCR.use_cassette "#{gateway_cassette_name}/authorize" do
45
+ response = gateway.authorize(200, tender)
25
46
 
26
- assert(response.success?)
27
- assert(response.message.present?)
47
+ assert(response.success?)
48
+ assert(response.message.present?)
28
49
 
29
- gift_card.reload
30
- assert_equal(8.to_m, gift_card.balance)
31
- assert_equal(2.to_m, gift_card.used)
50
+ gift_card.reload
51
+ assert_equal(8.to_m, gift_card.balance)
52
+ assert_equal(2.to_m, gift_card.used)
53
+ end
32
54
  end
33
55
 
34
56
  def test_cancel
35
- response = gateway.authorize(200, tender)
36
- assert(response.success?)
57
+ VCR.use_cassette "#{gateway_cassette_name}/cancel" do
58
+ response = gateway.authorize(200, tender)
59
+ assert(response.success?)
37
60
 
38
- response = gateway.cancel(200, tender)
61
+ response = gateway.cancel(200, tender)
39
62
 
40
- assert(response.success?)
41
- assert(response.message.present?)
63
+ assert(response.success?)
64
+ assert(response.message.present?)
42
65
 
43
- gift_card.reload
44
- assert_equal(10.to_m, gift_card.balance)
45
- assert_equal(0.to_m, gift_card.used)
66
+ gift_card.reload
67
+ assert_equal(10.to_m, gift_card.balance)
68
+ assert_equal(0.to_m, gift_card.used)
69
+ end
46
70
  end
47
71
 
48
72
  def test_capture
49
- assert(gateway.capture(200, tender).success?)
50
- assert_equal(10.to_m, gift_card.reload.balance)
73
+ VCR.use_cassette "#{gateway_cassette_name}/capture" do
74
+ assert(gateway.capture(200, tender).success?)
75
+ assert_equal(10.to_m, gift_card.reload.balance)
76
+ end
51
77
  end
52
78
 
53
79
  def test_purchase
54
- response = gateway.purchase(200, tender)
80
+ VCR.use_cassette "#{gateway_cassette_name}/purchase" do
81
+ response = gateway.purchase(200, tender)
55
82
 
56
- assert(response.success?)
57
- assert(response.message.present?)
83
+ assert(response.success?)
84
+ assert(response.message.present?)
58
85
 
59
- gift_card.reload
60
- assert_equal(8.to_m, gift_card.balance)
61
- assert_equal(2.to_m, gift_card.used)
86
+ gift_card.reload
87
+ assert_equal(8.to_m, gift_card.balance)
88
+ assert_equal(2.to_m, gift_card.used)
89
+ end
62
90
  end
63
91
 
64
92
  def test_refund
65
- response = gateway.authorize(200, tender)
66
- assert(response.success?)
93
+ VCR.use_cassette "#{gateway_cassette_name}/refund" do
94
+ response = gateway.authorize(200, tender)
95
+ assert(response.success?)
67
96
 
68
- response = gateway.refund(200, tender)
97
+ response = gateway.refund(200, tender)
69
98
 
70
- assert(response.success?)
71
- assert(response.message.present?)
99
+ assert(response.success?)
100
+ assert(response.message.present?)
72
101
 
73
- gift_card.reload
74
- assert_equal(10.to_m, gift_card.balance)
75
- assert_equal(0.to_m, gift_card.used)
102
+ gift_card.reload
103
+ assert_equal(10.to_m, gift_card.balance)
104
+ assert_equal(0.to_m, gift_card.used)
105
+ end
76
106
  end
77
107
 
78
108
  def test_balance
79
- balance = gateway.balance(gift_card.number)
80
- assert_equal(10.to_m, balance)
109
+ VCR.use_cassette "#{gateway_cassette_name}/balance" do
110
+ balance = gateway.balance(gift_card.number)
111
+ assert_equal(10.to_m, balance)
81
112
 
82
- gateway.authorize(300, tender)
113
+ gateway.authorize(300, tender)
83
114
 
84
- balance = gateway.balance(gift_card.number)
85
- assert_equal(7.to_m, balance)
115
+ balance = gateway.balance(gift_card.number)
116
+ assert_equal(7.to_m, balance)
117
+ end
86
118
  end
87
119
 
88
120
  def test_lookup
89
- lookup = gateway.lookup(email: gift_card.to, token: gift_card.token)
90
- assert_equal(gift_card.id, lookup.id)
121
+ VCR.use_cassette "#{gateway_cassette_name}/lookup" do
122
+ lookup = gateway.lookup(email: gift_card.to, token: gift_card.token)
123
+ assert_equal(gift_card.id, lookup.id)
91
124
 
92
- lookup = gateway.lookup(email: 'foo', token: gift_card.token)
93
- assert_nil(lookup)
125
+ lookup = gateway.lookup(email: 'foo', token: gift_card.token)
126
+ assert_nil(lookup)
127
+ end
94
128
  end
95
129
  end
96
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-gift_cards
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.2
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - bcrouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-03 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  - !ruby/object:Gem::Version
225
225
  version: '0'
226
226
  requirements: []
227
- rubygems_version: 3.0.6
227
+ rubygems_version: 3.0.3
228
228
  signing_key:
229
229
  specification_version: 4
230
230
  summary: Gift Cards plugin for the Workarea Commerce Platform