LitleOnline 8.16.0 → 8.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG +7 -0
  2. data/DESCRIPTION +1 -1
  3. data/README.md +2 -2
  4. data/Rakefile +6 -3
  5. data/bin/Setup.rb +14 -0
  6. data/bin/sample_batch_driver.rb +122 -0
  7. data/lib/LitleBatchRequest.rb +466 -0
  8. data/lib/LitleListeners.rb +142 -0
  9. data/lib/LitleOnline.rb +4 -0
  10. data/lib/LitleOnlineRequest.rb +25 -144
  11. data/lib/LitleRequest.rb +513 -0
  12. data/lib/LitleTransaction.rb +295 -0
  13. data/lib/XMLFields.rb +114 -4
  14. data/test/certification/certTest_batchAll.rb +337 -0
  15. data/test/certification/ts_all.rb +2 -0
  16. data/test/functional/test_batch.rb +164 -0
  17. data/test/functional/test_credit.rb +0 -18
  18. data/test/functional/test_litle_requests.rb +355 -0
  19. data/test/functional/test_updateCardValidationNumOnToken.rb +1 -1
  20. data/test/functional/test_xmlfields.rb +0 -19
  21. data/test/functional/ts_all.rb +2 -0
  22. data/test/unit/test_LitleAUBatch.rb +217 -0
  23. data/test/unit/test_LitleBatchRequest.rb +599 -0
  24. data/test/unit/test_LitleOnlineRequest.rb +9 -57
  25. data/test/unit/test_LitleRequest.rb +320 -0
  26. data/test/unit/test_LitleTransaction.rb +398 -0
  27. data/test/unit/test_auth.rb +25 -2
  28. data/test/unit/test_authReversal.rb +28 -5
  29. data/test/unit/test_capture.rb +24 -1
  30. data/test/unit/test_captureGivenAuth.rb +23 -1
  31. data/test/unit/test_credit.rb +92 -19
  32. data/test/unit/test_echeckCredit.rb +1 -1
  33. data/test/unit/test_echeckRedeposit.rb +1 -1
  34. data/test/unit/test_echeckSale.rb +1 -1
  35. data/test/unit/test_echeckVerification.rb +1 -1
  36. data/test/unit/test_echeckVoid.rb +1 -1
  37. data/test/unit/test_forceCapture.rb +24 -1
  38. data/test/unit/test_sale.rb +25 -2
  39. data/test/unit/test_token.rb +1 -1
  40. data/test/unit/test_updateCardValidationNumOnToken.rb +1 -1
  41. data/test/unit/test_xmlfields.rb +1 -1
  42. data/test/unit/ts_unit.rb +4 -0
  43. metadata +59 -14
@@ -0,0 +1,599 @@
1
+ =begin
2
+ Copyright (c) 2011 Litle & Co.
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
24
+ =end
25
+ require 'lib/LitleOnline'
26
+ require 'lib/LitleOnlineRequest'
27
+ require 'lib/LitleBatchRequest'
28
+ require 'test/unit'
29
+ require 'mocha/setup'
30
+
31
+ module LitleOnline
32
+
33
+ class TestLitleBatchRequest < Test::Unit::TestCase
34
+ def test_create_new_batch
35
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
36
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').twice
37
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
38
+ File.expects(:directory?).returns(false).once
39
+
40
+ batch = LitleBatchRequest.new
41
+ batch.create_new_batch('/usr/local/Batches/')
42
+ end
43
+
44
+
45
+ def test_add_authorization
46
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
47
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
48
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').at_most(3)
49
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').twice
50
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
51
+ File.expects(:directory?).returns(false).once
52
+ authHash = {
53
+ 'reportGroup'=>'Planets',
54
+ 'orderId'=>'12344',
55
+ 'amount'=>'106',
56
+ 'orderSource'=>'ecommerce',
57
+ 'card'=>{
58
+ 'type'=>'VI',
59
+ 'number' =>'4100000000000001',
60
+ 'expDate' =>'1210'
61
+ }}
62
+
63
+ batch = LitleBatchRequest.new
64
+ batch.create_new_batch('/usr/local/Batches/')
65
+
66
+ 2.times(){ batch.authorization(authHash) }
67
+ counts = batch.get_counts_and_amounts
68
+
69
+ assert_equal 2, counts[:auth][:numAuths]
70
+ assert_equal 212, counts[:auth][:authAmount]
71
+ end
72
+
73
+ def test_add_sale
74
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
75
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
76
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
77
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
78
+ File.expects(:directory?).returns(true).once
79
+
80
+ saleHash = {
81
+ 'reportGroup'=>'Planets',
82
+ 'id' => '006',
83
+ 'orderId'=>'12344',
84
+ 'amount'=>'6000',
85
+ 'orderSource'=>'ecommerce',
86
+ 'card'=>{
87
+ 'type'=>'VI',
88
+ 'number' =>'4100000000000001',
89
+ 'expDate' =>'1210'
90
+ }}
91
+
92
+ batch = LitleBatchRequest.new
93
+ batch.create_new_batch('D:\Batches\\')
94
+ batch.sale(saleHash)
95
+
96
+ counts = batch.get_counts_and_amounts
97
+ assert_equal 1, counts[:sale][:numSales]
98
+ assert_equal 6000, counts[:sale][:saleAmount]
99
+ end
100
+
101
+ def test_add_credit
102
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
103
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
104
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
105
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
106
+ File.expects(:directory?).returns(true).once
107
+
108
+ creditHash = {
109
+ 'merchantId' => '101',
110
+ 'version'=>'8.8',
111
+ 'reportGroup'=>'Planets',
112
+ 'orderId'=>'12344',
113
+ 'amount'=>'106',
114
+ 'orderSource'=>'ecommerce',
115
+ 'card'=>{
116
+ 'type'=>'VI',
117
+ 'number' =>'4100000000000001',
118
+ 'expDate' =>'1210'
119
+ }}
120
+
121
+ batch = LitleBatchRequest.new
122
+ batch.create_new_batch('D:\Batches\\')
123
+ batch.credit(creditHash)
124
+
125
+ counts = batch.get_counts_and_amounts
126
+ assert_equal 1, counts[:credit][:numCredits]
127
+ assert_equal 106, counts[:credit][:creditAmount]
128
+ end
129
+
130
+ def test_add_auth_reversal
131
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
132
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
133
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
134
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
135
+ File.expects(:directory?).returns(true).once
136
+
137
+ authReversalHash = {
138
+ 'merchantId' => '101',
139
+ 'version'=>'8.8',
140
+ 'reportGroup'=>'Planets',
141
+ 'litleTxnId'=>'12345678000',
142
+ 'amount'=>'106',
143
+ 'payPalNotes'=>'Notes'
144
+ }
145
+
146
+ batch = LitleBatchRequest.new
147
+ batch.create_new_batch('D:\Batches\\')
148
+ batch.auth_reversal(authReversalHash)
149
+
150
+ counts = batch.get_counts_and_amounts
151
+ assert_equal 1, counts[:authReversal][:numAuthReversals]
152
+ assert_equal 106, counts[:authReversal][:authReversalAmount]
153
+ end
154
+
155
+ def test_add_register_token_request
156
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
157
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
158
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
159
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
160
+ File.expects(:directory?).returns(true).once
161
+
162
+ registerTokenHash = {
163
+ 'merchantId' => '101',
164
+ 'version'=>'8.8',
165
+ 'reportGroup'=>'Planets',
166
+ 'orderId'=>'12344',
167
+ 'accountNumber'=>'1233456789103801'
168
+ }
169
+
170
+ batch = LitleBatchRequest.new
171
+ batch.create_new_batch('D:\Batches\\')
172
+ batch.register_token_request(registerTokenHash)
173
+
174
+ counts = batch.get_counts_and_amounts
175
+ assert_equal 1, counts[:numTokenRegistrations]
176
+ end
177
+
178
+ def test_add_update_card_validation_num_on_token
179
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
180
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
181
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
182
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
183
+ File.expects(:directory?).returns(true).once
184
+
185
+ updateCardHash = {
186
+ 'merchantId' => '101',
187
+ 'version'=>'8.8',
188
+ 'reportGroup'=>'Planets',
189
+ 'orderId'=>'12344',
190
+ 'litleToken'=>'1233456789103801',
191
+ 'cardValidationNum'=>'123'
192
+ }
193
+
194
+ batch = LitleBatchRequest.new
195
+ batch.create_new_batch('D:\Batches\\')
196
+ batch.update_card_validation_num_on_token(updateCardHash)
197
+
198
+ counts = batch.get_counts_and_amounts
199
+ assert_equal 1, counts[:numUpdateCardValidationNumOnTokens]
200
+ end
201
+
202
+ def test_add_force_capture
203
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
204
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
205
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
206
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
207
+ File.expects(:directory?).returns(true).once
208
+
209
+ forceCaptHash = {
210
+ 'merchantId' => '101',
211
+ 'version'=>'8.8',
212
+ 'reportGroup'=>'Planets',
213
+ 'litleTxnId'=>'123456',
214
+ 'orderId'=>'12344',
215
+ 'amount'=>'106',
216
+ 'orderSource'=>'ecommerce',
217
+ 'card'=>{
218
+ 'type'=>'VI',
219
+ 'number' =>'4100000000000001',
220
+ 'expDate' =>'1210'
221
+ }}
222
+
223
+ batch = LitleBatchRequest.new
224
+ batch.create_new_batch('D:\Batches\\')
225
+ batch.force_capture(forceCaptHash)
226
+
227
+ counts = batch.get_counts_and_amounts
228
+ assert_equal 1, counts[:forceCapture][:numForceCaptures]
229
+ assert_equal 106, counts[:forceCapture][:forceCaptureAmount]
230
+ end
231
+
232
+ def test_add_capture
233
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
234
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
235
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
236
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
237
+ File.expects(:directory?).returns(true).once
238
+
239
+ captHash = {
240
+ 'merchantId' => '101',
241
+ 'version'=>'8.8',
242
+ 'reportGroup'=>'Planets',
243
+ 'litleTxnId'=>'123456000',
244
+ 'amount'=>'106',
245
+ }
246
+
247
+ batch = LitleBatchRequest.new
248
+ batch.create_new_batch('D:\Batches\\')
249
+ batch.capture(captHash)
250
+
251
+ counts = batch.get_counts_and_amounts
252
+ assert_equal 1, counts[:capture][:numCaptures]
253
+ assert_equal 106, counts[:capture][:captureAmount]
254
+ end
255
+
256
+ def test_add_capture_given_auth
257
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
258
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
259
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
260
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
261
+ File.expects(:directory?).returns(true).once
262
+
263
+ captGivenAuthHash = {
264
+ 'merchantId' => '101',
265
+ 'version'=>'8.8',
266
+ 'reportGroup'=>'Planets',
267
+ 'orderId'=>'12344',
268
+ 'amount'=>'106',
269
+ 'authInformation' => {
270
+ 'authDate'=>'2002-10-09','authCode'=>'543216',
271
+ 'authAmount'=>'12345'
272
+ },
273
+ 'orderSource'=>'ecommerce',
274
+ 'card'=>{
275
+ 'type'=>'VI',
276
+ 'number' =>'4100000000000000',
277
+ 'expDate' =>'1210'
278
+ }}
279
+
280
+ batch = LitleBatchRequest.new
281
+ batch.create_new_batch('D:\Batches\\')
282
+ batch.capture_given_auth(captGivenAuthHash)
283
+
284
+ counts = batch.get_counts_and_amounts
285
+ assert_equal 1, counts[:captureGivenAuth][:numCaptureGivenAuths]
286
+ assert_equal 106, counts[:captureGivenAuth][:captureGivenAuthAmount]
287
+ end
288
+
289
+ def test_add_echeck_verification
290
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
291
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
292
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
293
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
294
+ File.expects(:directory?).returns(true).once
295
+
296
+ echeckVerificationHash = {
297
+ 'merchantId' => '101',
298
+ 'version'=>'8.8',
299
+ 'reportGroup'=>'Planets',
300
+ 'amount'=>'123456',
301
+ 'orderId'=>'12345',
302
+ 'orderSource'=>'ecommerce',
303
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
304
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
305
+ }
306
+
307
+ batch = LitleBatchRequest.new
308
+ batch.create_new_batch('D:\Batches\\')
309
+ batch.echeck_verification(echeckVerificationHash)
310
+
311
+ counts = batch.get_counts_and_amounts
312
+ assert_equal 1, counts[:echeckVerification][:numEcheckVerification]
313
+ assert_equal 123456, counts[:echeckVerification][:echeckVerificationAmount]
314
+ end
315
+
316
+ def test_add_echeck_credit
317
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
318
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
319
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
320
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
321
+ File.expects(:directory?).returns(true).once
322
+
323
+ echeckCreditHash = {
324
+ 'merchantId' => '101',
325
+ 'version'=>'8.8',
326
+ 'reportGroup'=>'Planets',
327
+ 'litleTxnId'=>'123456789101112',
328
+ 'amount'=>'12'
329
+ }
330
+
331
+ batch = LitleBatchRequest.new
332
+ batch.create_new_batch('D:\Batches\\')
333
+ batch.echeck_credit(echeckCreditHash)
334
+
335
+ counts = batch.get_counts_and_amounts
336
+ assert_equal 1, counts[:echeckCredit][:numEcheckCredit]
337
+ assert_equal 12, counts[:echeckCredit][:echeckCreditAmount]
338
+ end
339
+
340
+ def test_add_echeck_redeposit
341
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
342
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
343
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
344
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
345
+ File.expects(:directory?).returns(true).once
346
+
347
+ echeckRedeopsitHash = {
348
+ 'merchantId' => '101',
349
+ 'version'=>'8.8',
350
+ 'reportGroup'=>'Planets',
351
+ 'litleTxnId'=>'123456'
352
+ }
353
+
354
+ batch = LitleBatchRequest.new
355
+ batch.create_new_batch('D:\Batches\\')
356
+ batch.echeck_redeposit(echeckRedeopsitHash)
357
+
358
+ counts = batch.get_counts_and_amounts
359
+ assert_equal 1, counts[:numEcheckRedeposit]
360
+ end
361
+
362
+ def test_add_echeck_sale
363
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
364
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
365
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
366
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
367
+ File.expects(:directory?).returns(true).once
368
+
369
+ echeckSaleHash = {
370
+ 'merchantId' => '101',
371
+ 'version'=>'8.8',
372
+ 'reportGroup'=>'Planets',
373
+ 'amount'=>'123456',
374
+ 'verify'=>'true',
375
+ 'orderId'=>'12345',
376
+ 'orderSource'=>'ecommerce',
377
+ 'echeck' => {'accType'=>'Checking','accNum'=>'12345657890','routingNum'=>'123456789','checkNum'=>'123455'},
378
+ 'billToAddress'=>{'name'=>'Bob','city'=>'lowell','state'=>'MA','email'=>'litle.com'}
379
+ }
380
+
381
+ batch = LitleBatchRequest.new
382
+ batch.create_new_batch('D:\Batches\\')
383
+ batch.echeck_sale(echeckSaleHash)
384
+
385
+ counts = batch.get_counts_and_amounts
386
+ assert_equal 1, counts[:echeckSale][:numEcheckSales]
387
+ assert_equal 123456, counts[:echeckSale][:echeckSalesAmount]
388
+ end
389
+
390
+ def test_close_batch
391
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
392
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
393
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').twice
394
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').once
395
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
396
+ File.expects(:rename).once
397
+ File.expects(:delete).once
398
+ File.expects(:directory?).returns(true).once
399
+
400
+ saleHash = {
401
+ 'reportGroup'=>'Planets',
402
+ 'id' => '006',
403
+ 'orderId'=>'12344',
404
+ 'amount'=>'6000',
405
+ 'orderSource'=>'ecommerce',
406
+ 'card'=>{
407
+ 'type'=>'VI',
408
+ 'number' =>'4100000000000001',
409
+ 'expDate' =>'1210'
410
+ }}
411
+
412
+ batch = LitleBatchRequest.new
413
+ batch.create_new_batch('D:\Batches\\')
414
+
415
+ batch.sale(saleHash)
416
+ batch.close_batch()
417
+ end
418
+
419
+ def test_open_existing_batch
420
+
421
+ saleHash = {
422
+ 'reportGroup'=>'Planets',
423
+ 'id' => '006',
424
+ 'orderId'=>'12344',
425
+ 'amount'=>'6000',
426
+ 'orderSource'=>'ecommerce',
427
+ 'card'=>{
428
+ 'type'=>'VI',
429
+ 'number' =>'4100000000000001',
430
+ 'expDate' =>'1210'
431
+ }}
432
+
433
+ open = sequence('open')
434
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).times(2).in_sequence(open)
435
+
436
+ File.expects(:file?).returns(false).once.in_sequence(open)
437
+ File.expects(:directory?).returns(true).in_sequence(open)
438
+ File.expects(:file?).returns(false).in_sequence(open)
439
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(open)
440
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(open)
441
+ File.expects(:file?).returns(true).in_sequence(open)
442
+
443
+
444
+
445
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'rb').returns({:numAccountUpdates => 0}).once.in_sequence(open)
446
+ File.expects(:rename).once.in_sequence(open)
447
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once.in_sequence(open)
448
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once.in_sequence(open)
449
+ batch1 = LitleBatchRequest.new
450
+ batch2 = LitleBatchRequest.new
451
+ batch2.expects(:build_batch_header).returns("foo")
452
+ batch1.create_new_batch('/usr/local/Batches/')
453
+ batch2.open_existing_batch(batch1.get_batch_name)
454
+ batch2.close_batch()
455
+ end
456
+
457
+ def test_build_batch_header
458
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
459
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
460
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
461
+ File.expects(:rename).once
462
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'w').once
463
+ File.expects(:delete).once
464
+ File.expects(:directory?).returns(true).once
465
+
466
+ batch = LitleBatchRequest.new
467
+ batch.get_counts_and_amounts.expects(:[]).returns(hash = Hash.new).at_least(25)
468
+ hash.expects(:[]).returns('a').at_least(20)
469
+
470
+ batch.create_new_batch('/usr/local/Batches')
471
+ batch.close_batch()
472
+ end
473
+
474
+ def test_create_new_batch_missing_separator
475
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
476
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').once
477
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').once
478
+
479
+ batch = LitleBatchRequest.new
480
+ batch.create_new_batch('/usr/local')
481
+
482
+ assert batch.get_batch_name.include?('/usr/local/')
483
+ end
484
+
485
+ def test_create_new_batch_name_collision
486
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
487
+
488
+ fileExists = sequence('fileExists')
489
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
490
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(true).in_sequence(fileExists)
491
+ File.expects(:file?).with(regexp_matches(/.*\/usr\/local\//)).returns(false).in_sequence(fileExists)
492
+ File.expects(:file?).with(regexp_matches(/.*batch_.*\d.*/)).returns(false).in_sequence(fileExists)
493
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(fileExists)
494
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(fileExists)
495
+
496
+
497
+ batch = LitleBatchRequest.new
498
+ batch.create_new_batch('/usr/local/')
499
+ end
500
+
501
+ def test_create_new_batch_when_full
502
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
503
+
504
+ batch = LitleBatchRequest.new
505
+ addTxn = sequence('addTxn')
506
+
507
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').in_sequence(addTxn)
508
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
509
+ batch.create_new_batch('/usr/local')
510
+
511
+ batch.get_counts_and_amounts.expects(:[]).with(:sale).returns({:numSales => 10, :saleAmount => 20}).twice.in_sequence(addTxn)
512
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(499999).in_sequence(addTxn)
513
+
514
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d_txns.*/), 'a+').in_sequence(addTxn)
515
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').in_sequence(addTxn)
516
+ batch.get_counts_and_amounts.expects(:[]).with(:total).returns(100000).in_sequence(addTxn)
517
+
518
+ batch.expects(:close_batch).once.in_sequence(addTxn)
519
+ batch.expects(:initialize).once.in_sequence(addTxn)
520
+ batch.expects(:create_new_batch).once.in_sequence(addTxn)
521
+
522
+ saleHash = {
523
+ 'reportGroup'=>'Planets',
524
+ 'id' => '006',
525
+ 'orderId'=>'12344',
526
+ 'amount'=>'6000',
527
+ 'orderSource'=>'ecommerce',
528
+ 'card'=>{
529
+ 'type'=>'VI',
530
+ 'number' =>'4100000000000001',
531
+ 'expDate' =>'1210'
532
+ }}
533
+
534
+ batch.sale(saleHash)
535
+
536
+ end
537
+
538
+ def test_complete_batch
539
+ Configuration.any_instance.stubs(:config).returns({'currency_merchant_map'=>{'DEFAULT'=>'1'}, 'user'=>'a','password'=>'b','version'=>'8.10'}).once
540
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'a+').at_most(9)
541
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.*/), 'wb').at_most(7)
542
+ File.expects(:rename).once
543
+ File.expects(:open).with(regexp_matches(/.*batch_.*\d.closed.*/), 'w').once
544
+ File.expects(:delete).with(regexp_matches(/.*batch_.*\d_txns.*/)).once
545
+ Dir.expects(:mkdir).with('/usr/local/Batches/').once
546
+ File.expects(:directory?).returns(false).once
547
+
548
+ authHash = {
549
+ 'reportGroup'=>'Planets',
550
+ 'orderId'=>'12344',
551
+ 'amount'=>'106',
552
+ 'orderSource'=>'ecommerce',
553
+ 'card'=>{
554
+ 'type'=>'VI',
555
+ 'number' =>'4100000000000001',
556
+ 'expDate' =>'1210'
557
+ }}
558
+
559
+ saleHash = {
560
+ 'reportGroup'=>'Planets',
561
+ 'id' => '006',
562
+ 'orderId'=>'12344',
563
+ 'amount'=>'6000',
564
+ 'orderSource'=>'ecommerce',
565
+ 'card'=>{
566
+ 'type'=>'VI',
567
+ 'number' =>'4100000000000001',
568
+ 'expDate' =>'1210'
569
+ }}
570
+
571
+ updateCardHash = {
572
+ 'merchantId' => '101',
573
+ 'version'=>'8.8',
574
+ 'reportGroup'=>'Planets',
575
+ 'id'=>'12345',
576
+ 'customerId'=>'0987',
577
+ 'orderId'=>'12344',
578
+ 'litleToken'=>'1233456789103801',
579
+ 'cardValidationNum'=>'123'
580
+ }
581
+
582
+ batch = LitleBatchRequest.new
583
+ batch.create_new_batch('/usr/local/Batches/')
584
+
585
+ 5.times(){ batch.authorization(authHash) }
586
+ 2.times(){ batch.sale(saleHash) }
587
+
588
+ #pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{$$}"`.strip.split.map(&:to_i)
589
+ #puts "PID: " + pid.to_s + " size: " + size.to_s
590
+ batch.close_batch()
591
+ counts = batch.get_counts_and_amounts
592
+
593
+ assert_equal 5, counts[:auth][:numAuths]
594
+ #assert_equal 212, counts[:auth][:authAmount]
595
+ assert_equal 2, counts[:sale][:numSales]
596
+ #assert_equal 6000, counts[:sale][:saleAmount]
597
+ end
598
+ end
599
+ end