net_registry 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,326 @@
1
+ # Copyright (c) 2015 Car Next Door
2
+ # Author: Ray Tung
3
+ #
4
+ # MIT License
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require "spec_helper"
26
+ RSpec.describe NetRegistry::ResponseBuilder do
27
+ let(:factory) { NetRegistry::ResponseBuilder.new }
28
+ let(:invalid_login_format) do
29
+ <<-RESPONSE.gsub(/^\s+/, "")
30
+ failed
31
+ Invalid login format
32
+ RESPONSE
33
+ end
34
+ let(:invalid_credit_card_number) do
35
+ <<-RESPONSE.gsub(/^\s+/, "")
36
+ failed
37
+
38
+
39
+ .
40
+ response_text=Invalid Credit card number
41
+ status=failed
42
+ response_code=-1
43
+ result=-1
44
+ RESPONSE
45
+ end
46
+ let(:status_invalid_transaction) do
47
+ <<-RESPONSE.gsub(/^\s+/, "")
48
+ card_number=XXXXXXXXXXXX1111
49
+ settlement_date=31/07/00
50
+ response_text=INVALID TRANSACTION
51
+ amount=100
52
+ status=complete
53
+ txnref=0007311428202312
54
+ bank_ref=000731000024
55
+ card_desc=VISA
56
+ response_code=12
57
+ card_expiry=01/01
58
+ MID=24
59
+ card_type=6
60
+ time=2000­07­31 14:28:20
61
+ command=purchase
62
+ result=0
63
+ .
64
+ done=1
65
+ RESPONSE
66
+ end
67
+ let(:purchase_invalid_transaction) do
68
+ <<-RESPONSE.gsub(/^\s+/, "")
69
+ training_mode=0
70
+ pld=0
71
+ approved=0
72
+ settlement_date=31/07/00
73
+ transaction_no=332546
74
+ status=declined
75
+ version=V1.0
76
+ operator_no=22546
77
+ refund_mode=0
78
+ merchant_index=24
79
+ response_code=12
80
+ receipt_array=ARRAY(0x8221b9c)
81
+ cashout_amount=0
82
+ account_type=CREDIT A/C
83
+ rrn=000782000024
84
+ response_text=INVALID TRANSACTION
85
+ txn_ref=0007311458332546
86
+ card_no=4111111111111111
87
+ total_amount=100
88
+ card_desc=VISA
89
+ card_expiry=01/01
90
+ card_type=6
91
+ result=0
92
+ Reciept follows
93
+ Transaction No: 00332546
94
+ ­­­­­­­­­­­­­­­­­­­­­­­­
95
+ TYRELL CORPORATION    
96
+ MERCH ID        99999999
97
+ TERM  ID          Y9TB99
98
+ COUNTRY CODE AU
99
+ 31/07/00           14:32
100
+ RRN         000782000024
101
+ VISA
102
+ 411111­111
103
+ CREDIT A/C         01/01
104
+ AUTHORISATION NO:
105
+ DECLINED   12
106
+ PURCHASE           $1.00
107
+ TOTAL   AUD        $1.00
108
+ PLEASE RETAIN AS RECORD 
109
+ OF PURCHASE
110
+ (SUBJECT TO CARDHOLDER'S
111
+ ACCEPTANCE)      
112
+ ­­­­­­­­­­­­­­­­­­­­­­­­
113
+ .
114
+ done=1
115
+ RESPONSE
116
+ end
117
+ describe "#init" do
118
+ it { expect(factory.response.class).to be(NetRegistry::Response) }
119
+ end
120
+
121
+ describe "#parse" do
122
+ context "response is not a string" do
123
+ it { expect {factory.parse(1)}.to raise_error(TypeError)}
124
+ end
125
+ context "failed response (invalid params)" do
126
+ before :each do
127
+ @response = factory.parse(invalid_credit_card_number).create
128
+ end
129
+ it { expect(@response.text).to eq("Invalid Credit card number") }
130
+ it { expect(@response.status).to eq("failed") }
131
+ it { expect(@response.code).to eq(-1) }
132
+ it { expect(@response.result).to eq(-1) }
133
+ end
134
+ context "failed response (invalid login)" do
135
+ before :each do
136
+ @response = factory.parse(invalid_login_format).create
137
+ end
138
+ it { expect(@response.text).to eq("Invalid login format") }
139
+ it { expect(@response.status).to eq("failed") }
140
+ it { expect(@response.code).to eq(-1) }
141
+ it { expect(@response.result).to eq(-1) }
142
+ end
143
+ context "#status_invalid_transaction" do
144
+ before :each do
145
+ @response = factory.parse(status_invalid_transaction).create
146
+ end
147
+ it { expect(@response.text).to eq("INVALID TRANSACTION") }
148
+ it { expect(@response.status).to eq("complete") }
149
+ it { expect(@response.code).to eq(12) }
150
+ it { expect(@response.result).to eq(0)}
151
+
152
+ it { expect(@response.transaction.amount).to eq("100") }
153
+ it { expect(@response.transaction.reference).to eq("0007311428202312") }
154
+ it { expect(@response.transaction.time).to eq("2000­07­31 14:28:20")}
155
+ it { expect(@response.transaction.command).to eq("purchase")}
156
+ it { expect(@response.transaction.settlement_date).to eq("31/07/00")}
157
+ it { expect(@response.transaction.bank_reference).to eq("000731000024")}
158
+ it { expect(@response.transaction.merchant_id).to eq("24")}
159
+
160
+ it { expect(@response.transaction.card.number).to eq("XXXXXXXXXXXX1111") }
161
+ it { expect(@response.transaction.card.description).to eq("VISA")}
162
+ it { expect(@response.transaction.card.type).to eq("6")}
163
+ it { expect(@response.transaction.card.expiry).to eq("01/01")}
164
+
165
+ end
166
+
167
+ context "#purchase_invalid_transaction" do
168
+ before :each do
169
+ @response = factory.parse(purchase_invalid_transaction).create
170
+ @receipt = <<-RECEIPT.gsub(/^\s+/, "")
171
+ Transaction No: 00332546
172
+ ­­­­­­­­­­­­­­­­­­­­­­­­
173
+ TYRELL CORPORATION    
174
+ MERCH ID        99999999
175
+ TERM  ID          Y9TB99
176
+ COUNTRY CODE AU
177
+ 31/07/00           14:32
178
+ RRN         000782000024
179
+ VISA
180
+ 411111­111
181
+ CREDIT A/C         01/01
182
+ AUTHORISATION NO:
183
+ DECLINED   12
184
+ PURCHASE           $1.00
185
+ TOTAL   AUD        $1.00
186
+ PLEASE RETAIN AS RECORD 
187
+ OF PURCHASE
188
+ (SUBJECT TO CARDHOLDER'S
189
+ ACCEPTANCE)      
190
+ ­­­­­­­­­­­­­­­­­­­­­­­­
191
+ RECEIPT
192
+ end
193
+ it { expect(@response.text).to eq("INVALID TRANSACTION") }
194
+ it { expect(@response.transaction.reference).to eq("0007311458332546") }
195
+ it { expect(@response.transaction.rrn).to eq("000782000024")}
196
+ it { expect(@response.result).to eq(0)}
197
+ it { expect(@response.code).to eq(12)}
198
+ it { expect(@response.status).to eq("declined")}
199
+
200
+ it { expect(@response.transaction.number).to eq("332546") }
201
+ it { expect(@response.transaction.card.number).to eq("4111111111111111") }
202
+ it { expect(@response.transaction.card.description).to eq("VISA")}
203
+ it { expect(@response.transaction.card.type).to eq("6")}
204
+ it { expect(@response.transaction.card.expiry).to eq("01/01")}
205
+
206
+ it "should have receipt" do
207
+ expect(@response.transaction.receipt.to_s.strip).to eq(@receipt.strip)
208
+ end
209
+ end
210
+
211
+ end
212
+
213
+ describe "#create" do
214
+ let(:invalid_status_params) { { TXNREF: nil } }
215
+ it { expect(factory.create.class).to be(NetRegistry::Response) }
216
+ it "has invalid status params" do
217
+ factory.verify_params(invalid_status_params.merge!(COMMAND: "status"))
218
+ response = factory.create
219
+ expect(response.text).to eq("TXNREF not found")
220
+ expect(response.status).to eq("failed")
221
+ expect(response.code).to eq(-1)
222
+ end
223
+
224
+ it "has not provided with a COMMAND" do
225
+ factory.verify_params(invalid_status_params)
226
+ response = factory.create
227
+ expect(response.text).to eq("Invalid command. Only [purchase status preauth refund] are valid.")
228
+ expect(response.status).to eq("failed")
229
+ expect(response.code).to eq(-1)
230
+ end
231
+ end
232
+
233
+ describe "#verify_params" do
234
+ let(:status_params) { { TXNREF: "1234567" } }
235
+ let(:refund_params) { { AMOUNT: "100", TXNREF: "1234567"} }
236
+ let(:purchase_params) { { AMOUNT: "100", CCNUM: "111111111111", CCEXP: "10/15"} }
237
+ let(:preauth_params) { { AMOUNT: "100", CCNUM: "111111111111", CCEXP: "10/15"} }
238
+
239
+ it { expect(factory.verify_params(preauth_params.merge!(COMMAND: "preauth"))).to be(true) }
240
+ it { expect(factory.verify_params(preauth_params.merge!(COMMAND: "purchase"))).to be(true)}
241
+ it { expect(factory.verify_params(preauth_params.merge!(COMMAND: "refund"))).to be(false) }
242
+ it { expect(factory.verify_params(preauth_params.merge!(COMMAND: "status"))).to be(false) }
243
+
244
+ it { expect(factory.verify_params(refund_params.merge!(COMMAND: "preauth"))).to be(false) }
245
+ it { expect(factory.verify_params(refund_params.merge!(COMMAND: "purchase"))).to be(false)}
246
+ it { expect(factory.verify_params(refund_params.merge!(COMMAND: "refund"))).to be(true) }
247
+ it { expect(factory.verify_params(refund_params.merge!(COMMAND: "status"))).to be(true) }
248
+
249
+ it { expect(factory.verify_params(purchase_params.merge!(COMMAND: "preauth"))).to be(true) }
250
+ it { expect(factory.verify_params(purchase_params.merge!(COMMAND: "purchase"))).to be(true)}
251
+ it { expect(factory.verify_params(purchase_params.merge!(COMMAND: "refund"))).to be(false) }
252
+ it { expect(factory.verify_params(purchase_params.merge!(COMMAND: "status"))).to be(false) }
253
+
254
+ it { expect(factory.verify_params(status_params.merge!(COMMAND: "preauth"))).to be(false) }
255
+ it { expect(factory.verify_params(status_params.merge!(COMMAND: "purchase"))).to be(false)}
256
+ it { expect(factory.verify_params(status_params.merge!(COMMAND: "refund"))).to be(false) }
257
+ it { expect(factory.verify_params(status_params.merge!(COMMAND: "status"))).to be(true) }
258
+ end
259
+
260
+ describe "#validate_preauth_params" do
261
+ let(:params) { {CCNUM: "111111111111", CCEXP: "10/14", AMOUNT: "100"} }
262
+ it { expect(factory.send(:validate_preauth_params, params)). to eq(["", true]) }
263
+ it "does not have AMOUNT in params hash" do
264
+ expect(factory.send(:validate_preauth_params, params.merge!(AMOUNT: nil))).to eq(["AMOUNT not found", false])
265
+ expect(factory.send(:validate_preauth_params, params.merge!(AMOUNT: ""))).to eq(["AMOUNT not found", false])
266
+ end
267
+ it "does not have CCNUM in params hash" do
268
+ expect(factory.send(:validate_preauth_params, params.merge!(CCNUM: nil))).to eq(["CCNUM not found", false])
269
+ expect(factory.send(:validate_preauth_params, params.merge!(CCNUM: ""))).to eq(["CCNUM not found", false])
270
+ end
271
+ it "does not have CCEXP in params hash" do
272
+ expect(factory.send(:validate_preauth_params, params.merge!(CCEXP: nil))).to eq(["CCEXP not found", false])
273
+ expect(factory.send(:validate_preauth_params, params.merge!(CCEXP: ""))).to eq(["CCEXP not found", false])
274
+ end
275
+ it "invalid CCEXP format" do
276
+ expect(factory.send(:validate_preauth_params, params.merge!(CCEXP: "what'sup"))).to eq(["CCEXP invalid format", false])
277
+ expect(factory.send(:validate_preauth_params, params.merge!(CCEXP: "12/20/2015"))).to eq(["CCEXP invalid format", false])
278
+ end
279
+ end
280
+
281
+ describe "#validate_status_params" do
282
+ let(:params) { { TXNREF: "1234567" } }
283
+ it { expect(factory.send(:validate_status_params, params)). to eq(["", true]) }
284
+ it "does not have txnref in params hash" do
285
+ expect(factory.send(:validate_status_params, params.merge!(TXNREF: nil))).to eq(["TXNREF not found", false])
286
+ expect(factory.send(:validate_status_params, params.merge!(TXNREF: ""))).to eq(["TXNREF not found", false])
287
+ end
288
+ end
289
+
290
+ describe "#vaidate_refund_params" do
291
+ let(:params) { {AMOUNT: "100", TXNREF: "1234567"} }
292
+ it { expect(factory.send(:validate_refund_params, params)). to eq(["", true]) }
293
+ it "does not have amount in params hash" do
294
+ expect(factory.send(:validate_refund_params, params.merge!(AMOUNT: nil))).to eq(["AMOUNT not found", false])
295
+ expect(factory.send(:validate_refund_params, params.merge!(AMOUNT: ""))).to eq(["AMOUNT not found", false])
296
+ end
297
+ it "does not have txnref in params hash" do
298
+ expect(factory.send(:validate_refund_params, params.merge!(TXNREF: nil))).to eq(["TXNREF not found", false])
299
+ expect(factory.send(:validate_refund_params, params.merge!(TXNREF: ""))).to eq(["TXNREF not found", false])
300
+ end
301
+ end
302
+
303
+ describe "#validate_purchase_params" do
304
+ let(:params) { {AMOUNT: "100", CCNUM: "111111111111", CCEXP: "10/15"}}
305
+ it { expect(factory.send(:validate_purchase_params, params)). to eq(["", true]) }
306
+ it "does not have amount in params hash" do
307
+ expect(factory.send(:validate_purchase_params, params.merge!(AMOUNT: nil))).to eq(["AMOUNT not found", false])
308
+ expect(factory.send(:validate_purchase_params, params.merge!(AMOUNT: ""))).to eq(["AMOUNT not found", false])
309
+ end
310
+
311
+ it "does not have CCNUM in params hash" do
312
+ expect(factory.send(:validate_purchase_params, params.merge!(CCNUM: nil))).to eq(["CCNUM not found", false])
313
+ expect(factory.send(:validate_purchase_params, params.merge!(CCNUM: ""))).to eq(["CCNUM not found", false])
314
+ end
315
+
316
+ it "does not have CCEXP in params hash" do
317
+ expect(factory.send(:validate_purchase_params, params.merge!(CCEXP: nil))).to eq(["CCEXP not found", false])
318
+ expect(factory.send(:validate_purchase_params, params.merge!(CCEXP: ""))).to eq(["CCEXP not found", false])
319
+ end
320
+
321
+ it "invalid CCEXP format" do
322
+ expect(factory.send(:validate_purchase_params, params.merge!(CCEXP: "12/29/2015"))).to eq(["CCEXP invalid format", false])
323
+ expect(factory.send(:validate_purchase_params, params.merge!(CCEXP: "What's up"))).to eq(["CCEXP invalid format", false])
324
+ end
325
+ end
326
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright (c) 2015 Car Next Door
2
+ # Author: Ray Tung
3
+ #
4
+ # MIT License
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require "spec_helper"
26
+
27
+ RSpec.describe NetRegistry::Response do
28
+ describe "#init" do
29
+ context "no argument is supplied to constructor" do
30
+ let(:response) { NetRegistry::Response.new }
31
+ it { expect(response.text).to eq("Unknown Error") }
32
+ it { expect(response.code).to eq(-1) }
33
+ it { expect(response.status).to eq("failed") }
34
+ it { expect(response.failed?).to be(true) }
35
+ it { expect(response.success?).to be(false) }
36
+ end
37
+
38
+ context "argument is supplied" do
39
+ text = "Something"
40
+ code = 1
41
+ status = "success"
42
+ let(:response) { NetRegistry::Response.new(text: text, code: code, status: status) }
43
+ it { expect(response.text).to eq(text) }
44
+ it { expect(response.code).to eq(code) }
45
+ it { expect(response.status).to eq(status) }
46
+ it { expect(response.failed?).to be(false) }
47
+ it { expect(response.success?).to be(true) }
48
+ end
49
+ end
50
+
51
+ text = "Something"
52
+ code = 1
53
+ status = "success"
54
+ let(:response) { NetRegistry::Response.new(text: text, code: code, status: status) }
55
+ describe "#text" do
56
+ it "assigns new text" do
57
+ new_text = "Say Something"
58
+ expect(response.text).to eq(text)
59
+ response.text = new_text
60
+ expect(response.text).to eq(new_text)
61
+ end
62
+ end
63
+
64
+ describe "#status" do
65
+ it "assigns new status" do
66
+ new_status = "I'm giving up on you"
67
+ expect(response.status).to eq(status)
68
+ response.status = new_status
69
+ expect(response.status).to eq(new_status)
70
+ end
71
+ end
72
+
73
+ describe "#code" do
74
+ it "assigns new code" do
75
+ new_code = -1
76
+ expect(response.code).to eq(code)
77
+ response.code = new_code
78
+ expect(response.code).to eq(new_code)
79
+ expect(response.failed?).to eq(true)
80
+ expect(response.success?).to eq(false)
81
+
82
+ new_code = "I'll be the one if you want me to"
83
+ response.code = new_code
84
+ expect(response.code).to eq(0)
85
+ expect(response.failed?).to eq(false)
86
+ expect(response.success?).to eq(true)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,103 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require 'bundler/setup'
21
+ Bundler.setup
22
+
23
+ require 'webmock/rspec'
24
+ WebMock.disable_net_connect!(allow_localost: true)
25
+ require 'net_registry'
26
+ RSpec.configure do |config|
27
+ # rspec-expectations config goes here. You can use an alternate
28
+ # assertion/expectation library such as wrong or the stdlib/minitest
29
+ # assertions if you prefer.
30
+ config.expect_with :rspec do |expectations|
31
+ # This option will default to `true` in RSpec 4. It makes the `description`
32
+ # and `failure_message` of custom matchers include text for helper methods
33
+ # defined using `chain`, e.g.:
34
+ # be_bigger_than(2).and_smaller_than(4).description
35
+ # # => "be bigger than 2 and smaller than 4"
36
+ # ...rather than:
37
+ # # => "be bigger than 2"
38
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ # Prevents you from mocking or stubbing a method that does not exist on
45
+ # a real object. This is generally recommended, and will default to
46
+ # `true` in RSpec 4.
47
+ mocks.verify_partial_doubles = true
48
+ end
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # These two settings work together to allow you to limit a spec run
54
+ # to individual examples or groups you care about by tagging them with
55
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
56
+ # get run.
57
+ config.filter_run :focus
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = 'doc'
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
@@ -0,0 +1,97 @@
1
+ # Copyright (c) 2015 Car Next Door
2
+ # Author: Ray Tung
3
+ #
4
+ # MIT License
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require "spec_helper"
26
+
27
+ RSpec.describe NetRegistry::Transaction do
28
+ let(:transaction) { NetRegistry::Transaction.new }
29
+ let(:card) { NetRegistry::Card.new }
30
+
31
+ describe "#card" do
32
+ it "assigns card object" do
33
+ transaction.card = card
34
+ expect(transaction.card).to eq(card)
35
+ end
36
+
37
+ it "assigns incorrect card object" do
38
+ expect { transaction.card = "Hello yo"}.to raise_error(TypeError)
39
+ end
40
+ end
41
+
42
+ describe "#settlement_date" do
43
+ it "assigns settlement_date" do
44
+ date = "31/07/00"
45
+ expect(transaction.settlement_date).to be_nil
46
+ transaction.settlement_date = date
47
+ expect(transaction.settlement_date).to eq(date)
48
+ end
49
+ end
50
+
51
+ describe "#amount" do
52
+ it "assigns amount" do
53
+ amount = "100.0"
54
+ expect(transaction.amount).to be_nil
55
+ transaction.amount = amount
56
+ expect(transaction.amount).to eq(amount)
57
+ end
58
+ end
59
+
60
+ describe "#reference" do
61
+ it "assigns reference" do
62
+ reference = "0007311428202312"
63
+ expect(transaction.reference).to be_nil
64
+ transaction.reference= reference
65
+ expect(transaction.reference).to eq(reference)
66
+ end
67
+ end
68
+
69
+ describe "#bank_reference" do
70
+ it "assigns bank_reference" do
71
+ reference = "0007311428202312"
72
+ expect(transaction.bank_reference).to be_nil
73
+ transaction.bank_reference = reference
74
+ expect(transaction.bank_reference).to eq(reference)
75
+ end
76
+ end
77
+
78
+ describe "#command" do
79
+ it "assigns command" do
80
+ command = "purchase"
81
+ expect(transaction.command).to be_nil
82
+ transaction.command = command
83
+ expect(transaction.command).to eq(command)
84
+ end
85
+ end
86
+
87
+ describe "#time" do
88
+ it "assigns time" do
89
+ time = "2000­07­31 14:28:20"
90
+ expect(transaction.time).to be_nil
91
+ transaction.time = time
92
+ expect(transaction.time).to eq(time)
93
+ end
94
+ end
95
+
96
+
97
+ end