bankserv 0.1.3

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.
Files changed (75) hide show
  1. data/.gitignore +6 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +16 -0
  4. data/Rakefile +8 -0
  5. data/bankserv.gemspec +31 -0
  6. data/config.ru +7 -0
  7. data/lib/bankserv.rb +48 -0
  8. data/lib/bankserv/account_holder_verification.rb +90 -0
  9. data/lib/bankserv/bank_account.rb +19 -0
  10. data/lib/bankserv/configuration.rb +67 -0
  11. data/lib/bankserv/credit.rb +70 -0
  12. data/lib/bankserv/debit.rb +94 -0
  13. data/lib/bankserv/eft.rb +83 -0
  14. data/lib/bankserv/engine.rb +183 -0
  15. data/lib/bankserv/engine/engine_configuration.rb +12 -0
  16. data/lib/bankserv/engine/engine_process.rb +3 -0
  17. data/lib/bankserv/request.rb +27 -0
  18. data/lib/bankserv/transaction.rb +22 -0
  19. data/lib/bankserv/transmission/document.rb +43 -0
  20. data/lib/bankserv/transmission/input_document.rb +84 -0
  21. data/lib/bankserv/transmission/output_document.rb +27 -0
  22. data/lib/bankserv/transmission/record.rb +13 -0
  23. data/lib/bankserv/transmission/reply_document.rb +27 -0
  24. data/lib/bankserv/transmission/set.rb +120 -0
  25. data/lib/bankserv/transmission/set/account_holder_verification.rb +81 -0
  26. data/lib/bankserv/transmission/set/account_holder_verification_output.rb +17 -0
  27. data/lib/bankserv/transmission/set/credit.rb +44 -0
  28. data/lib/bankserv/transmission/set/debit.rb +44 -0
  29. data/lib/bankserv/transmission/set/document.rb +45 -0
  30. data/lib/bankserv/transmission/set/eft.rb +228 -0
  31. data/lib/bankserv/transmission/set/eft_output.rb +12 -0
  32. data/lib/bankserv/transmission/set/eft_redirect.rb +18 -0
  33. data/lib/bankserv/transmission/set/eft_unpaid.rb +18 -0
  34. data/lib/bankserv/transmission/set/reply.rb +47 -0
  35. data/lib/bankserv/transmission/statement.rb +46 -0
  36. data/lib/bankserv/version.rb +3 -0
  37. data/lib/config/ahv.yml +9 -0
  38. data/lib/core_extensions.rb +37 -0
  39. data/lib/generators/active_record/bankserv_generator.rb +30 -0
  40. data/lib/generators/active_record/templates/migration.rb +141 -0
  41. data/spec/examples/ahv_input_file.txt +7 -0
  42. data/spec/examples/ahv_output_file.txt +7 -0
  43. data/spec/examples/credit_eft_input.txt +166 -0
  44. data/spec/examples/debit_eft_input_file.txt +20 -0
  45. data/spec/examples/eft_input_with_2_sets.txt +8 -0
  46. data/spec/examples/eft_output_file.txt +35 -0
  47. data/spec/examples/host2host/tmp.log +1 -0
  48. data/spec/examples/reply/rejected_transmission.txt +7 -0
  49. data/spec/examples/reply/reply_file.txt +5 -0
  50. data/spec/examples/statement4_unpacked.dat +51 -0
  51. data/spec/examples/tmp/OUTPUT0412153500.txt +35 -0
  52. data/spec/examples/tmp/REPLY0412153000.txt +5 -0
  53. data/spec/factories.rb +90 -0
  54. data/spec/internal/config/database.yml.sample +3 -0
  55. data/spec/internal/config/routes.rb +3 -0
  56. data/spec/internal/db/schema.rb +138 -0
  57. data/spec/internal/log/.gitignore +1 -0
  58. data/spec/internal/public/favicon.ico +0 -0
  59. data/spec/lib/bankserv/account_holder_verification_spec.rb +104 -0
  60. data/spec/lib/bankserv/configuration_spec.rb +34 -0
  61. data/spec/lib/bankserv/core_ext_spec.rb +43 -0
  62. data/spec/lib/bankserv/credit_spec.rb +92 -0
  63. data/spec/lib/bankserv/debit_spec.rb +187 -0
  64. data/spec/lib/bankserv/engine/engine_spec.rb +142 -0
  65. data/spec/lib/bankserv/transaction_spec.rb +32 -0
  66. data/spec/lib/bankserv/transmission/input_document_spec.rb +207 -0
  67. data/spec/lib/bankserv/transmission/output_document_spec.rb +210 -0
  68. data/spec/lib/bankserv/transmission/reply_document_spec.rb +117 -0
  69. data/spec/lib/bankserv/transmission/set/account_holder_verification_spec.rb +108 -0
  70. data/spec/lib/bankserv/transmission/set/credit_spec.rb +96 -0
  71. data/spec/lib/bankserv/transmission/set/debit_spec.rb +103 -0
  72. data/spec/lib/bankserv/transmission/statement_spec.rb +109 -0
  73. data/spec/spec_helper.rb +28 -0
  74. data/spec/support/helpers.rb +207 -0
  75. metadata +223 -0
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bankserv::Configuration do
4
+ include Helpers
5
+
6
+ before(:all) do
7
+ create(:configuration)
8
+ end
9
+
10
+ it "should store the client code" do
11
+ Bankserv::Configuration.client_code.should == Bankserv::Configuration.active.client_code
12
+ end
13
+
14
+ it "should store the client name" do
15
+ Bankserv::Configuration.client_name.should == Bankserv::Configuration.active.client_name
16
+ end
17
+
18
+ it "should store the user code" do
19
+ Bankserv::Configuration.user_code.should == Bankserv::Configuration.active.user_code
20
+ end
21
+
22
+ it "should store the department code" do
23
+ Bankserv::Configuration.department_code.should == Bankserv::Configuration.active.department_code
24
+ end
25
+
26
+ it "should store the user generation number" do
27
+ Bankserv::Configuration.user_generation_number.should == Bankserv::Configuration.active.user_generation_number
28
+ end
29
+
30
+ it "should be able to set the user generation number" do
31
+ Bankserv::Configuration.set_user_generation_number!(66)
32
+ Bankserv::Configuration.user_generation_number.should == 66
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Date do
4
+
5
+ context "Checking dates against South African holidays/work days" do
6
+
7
+ it "should know that Sunday is not a business day" do
8
+ t = Time.local(2012, 1, 22, 10, 5, 0)
9
+ Timecop.travel(t)
10
+ Date.today.business_day?.should be_false
11
+ end
12
+
13
+ it "should know that Saturday is not a business day" do
14
+ t = Time.local(2012, 1, 21, 10, 5, 0)
15
+ Timecop.travel(t)
16
+ Date.today.business_day?.should be_false
17
+ end
18
+
19
+ it "should know that holidays are not business days" do
20
+ [ Time.local(2007,1,1),
21
+ Time.local(2007,3,21),
22
+ Time.local(2007,4,6),
23
+ Time.local(2007,4,9),
24
+ Time.local(2007,4,27),
25
+ Time.local(2007,5,1),
26
+ Time.local(2007,6,16),
27
+ Time.local(2007,8,9),
28
+ Time.local(2007,9,24),
29
+ Time.local(2007,12,16),
30
+ Time.local(2007,12,25),
31
+ Time.local(2007,12,26)].each do |t|
32
+ Timecop.travel(t)
33
+ Date.today.business_day?.should be_false
34
+ end
35
+ end
36
+
37
+ it "should know that Monday 23rd January 2012 is a business day" do
38
+ t = Time.local(2012, 1, 23, 10, 5, 0)
39
+ Timecop.travel(t)
40
+ Date.today.business_day?.should be_true
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bankserv::Debit do
4
+
5
+ context "creating a new credit" do
6
+
7
+ it "should generate a unique internal reference" do
8
+ create(:credit)
9
+ Bankserv::Credit.last.internal_user_ref.should match /CREDIT[0-9]+/
10
+ end
11
+
12
+ end
13
+
14
+ context "queuing a batch of credit orders" do
15
+
16
+ before(:all) do
17
+ @data = [{
18
+ debit: {
19
+ account_number: "907654321",
20
+ branch_code: "632005",
21
+ account_type: 'savings',
22
+ id_number: '8207205263083',
23
+ initials: "RC",
24
+ account_name: "Rawson Milnerton",
25
+ amount: 1000000,
26
+ user_ref: 134,
27
+ action_date: Date.today
28
+ },
29
+ credit: [
30
+ { account_number: "13123123123", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "200"},
31
+ { account_number: "45645645645", branch_code: "123123", account_type: "savings", id_number: "198273922723", initials: "WX", account_name: "Tefant", amount: 250000, action_date: Date.today, user_ref: "201"},
32
+ { account_number: "78978978978", branch_code: "789789", account_type: "savings", id_number: "197873933723", initials: "WB", account_name: "Tebant", amount: 250000, action_date: Date.today, user_ref: "202"}
33
+ ]
34
+ }]
35
+
36
+ @hash = {
37
+ type: 'credit',
38
+ data: { batches: @data, type_of_service: "SAMEDAY"}
39
+ }
40
+ end
41
+
42
+ it "should be able to queue a request of credit orders" do
43
+ Bankserv::Credit.request(@hash).should be_true
44
+ Bankserv::Credit.all.each {|db| db.completed?.should be_false }
45
+ Bankserv::Credit.all.each {|db| db.new?.should be_true }
46
+ end
47
+
48
+ it "should link all debit order to the credit record" do
49
+ Bankserv::Credit.request(@hash)
50
+ Bankserv::Credit.all.map(&:batch_id).uniq.length.should == 1
51
+ end
52
+
53
+ end
54
+
55
+ context "queuing a batch of batched credit orders" do
56
+ before(:all) do
57
+ @data = [{
58
+ debit: {
59
+ account_number: "907654321", branch_code: "632005", account_type: 'savings', id_number: '8207205263083', initials: "RC", account_name: "Rawson Milnerton", amount: 1000000, user_ref: 234, action_date: Date.today },
60
+ credit: [
61
+ { account_number: "13123123123", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "235"},
62
+ { account_number: "45645645645", branch_code: "123123", account_type: "savings", id_number: "198273922723", initials: "WX", account_name: "Tefant", amount: 250000, action_date: Date.today, user_ref: "236"},
63
+ { account_number: "78978978978", branch_code: "789789", account_type: "savings", id_number: "197873933723", initials: "WB", account_name: "Tebant", amount: 250000, action_date: Date.today, user_ref: "237"}
64
+ ]
65
+ }, {
66
+ debit: {
67
+ account_number: "907654522", branch_code: "632005", account_type: 'savings', id_number: '8207205263083', initials: "RC", account_name: "Rawson Claremont", amount: 1500000, user_ref: 300, action_date: Date.today },
68
+ credit: [
69
+ { account_number: "13123123122", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "301"},
70
+ { account_number: "45645645642", branch_code: "123123", account_type: "savings", id_number: "198273922723", initials: "WX", account_name: "Tefant", amount: 250000, action_date: Date.today, user_ref: "302"},
71
+ { account_number: "78978978972", branch_code: "789789", account_type: "savings", id_number: "197873933723", initials: "WB", account_name: "Tebant", amount: 750000, action_date: Date.today, user_ref: "303"}
72
+ ]
73
+ }]
74
+
75
+ @hash = {
76
+ type: 'credit',
77
+ data: {batches: @data, type_of_service: "SAMEDAY"}
78
+ }
79
+ end
80
+
81
+ it "should be able to queue a batched request of credit orders" do
82
+ Bankserv::Credit.request(@hash).should be_true
83
+ Bankserv::Credit.all.each {|db| db.completed?.should be_false }
84
+ Bankserv::Credit.all.each {|db| db.new?.should be_true }
85
+ end
86
+
87
+ it "should link all debit order to their respective credit record" do
88
+ Bankserv::Credit.request(@hash)
89
+ Bankserv::Credit.all.map(&:batch_id).uniq.length.should == 2
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bankserv::Debit do
4
+
5
+ context "creating a new debit" do
6
+
7
+ it "should generate a unique internal reference" do
8
+ create(:debit)
9
+ Bankserv::Debit.last.internal_user_ref.should match /DEBIT[0-9]+/
10
+ end
11
+
12
+ end
13
+
14
+ context "queuing a batch of debit orders" do
15
+
16
+ before(:all) do
17
+
18
+ create(:configuration, client_code: "10", client_name: "LDC USER 10 AFRICA (PTY)", user_code: "9534", client_abbreviated_name: "ALIMITTST")
19
+ @data = [{
20
+ credit: {
21
+ account_number: "907654321",
22
+ branch_code: "632005",
23
+ account_type: 'savings',
24
+ id_number: '8207205263083',
25
+ initials: "RC",
26
+ account_name: "Rawson Milnerton",
27
+ amount: 1000000,
28
+ user_ref: 134,
29
+ action_date: Date.today
30
+ },
31
+ debit: [
32
+ { account_number: "13123123123", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "200"},
33
+ { account_number: "45645645645", branch_code: "123123", account_type: "savings", id_number: "198273922723", initials: "WX", account_name: "Tefant", amount: 250000, action_date: Date.today, user_ref: "201"},
34
+ { account_number: "78978978978", branch_code: "789789", account_type: "savings", id_number: "197873933723", initials: "WB", account_name: "Tebant", amount: 250000, action_date: Date.today, user_ref: "202"}
35
+ ]
36
+ }]
37
+
38
+ @hash = {
39
+ type: 'debit',
40
+ data: { type_of_service: "SAMEDAY", batches: @data }
41
+ }
42
+ end
43
+
44
+ it "should be able to queue a request of debit orders" do
45
+ Bankserv::Debit.request(@hash).should be_true
46
+ Bankserv::Debit.all.each {|db| db.completed?.should be_false }
47
+ Bankserv::Debit.all.each {|db| db.new?.should be_true }
48
+ end
49
+
50
+ it "should link all debit order to the credit record" do
51
+ Bankserv::Debit.request(@hash)
52
+ Bankserv::Debit.all.map(&:batch_id).uniq.length.should == 1
53
+ end
54
+
55
+ end
56
+
57
+ context "queuing a batch of batched debit orders" do
58
+ before(:all) do
59
+ @data = [{
60
+ credit: {
61
+ account_number: "907654321", branch_code: "632005", account_type: 'savings', id_number: '8207205263083', initials: "RC", account_name: "Rawson Milnerton", amount: 1000000, user_ref: 234, action_date: Date.today },
62
+ debit: [
63
+ { account_number: "13123123123", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "235"},
64
+ { account_number: "45645645645", branch_code: "123123", account_type: "savings", id_number: "198273922723", initials: "WX", account_name: "Tefant", amount: 250000, action_date: Date.today, user_ref: "236"},
65
+ { account_number: "78978978978", branch_code: "789789", account_type: "savings", id_number: "197873933723", initials: "WB", account_name: "Tebant", amount: 250000, action_date: Date.today, user_ref: "237"}
66
+ ]
67
+ }, {
68
+ credit: {
69
+ account_number: "907654322", branch_code: "632005", account_type: 'savings', id_number: '8207205263083', initials: "RC", account_name: "Rawson Milnerton", amount: 1500000, user_ref: 300, action_date: Date.today },
70
+ debit: [
71
+ { account_number: "13123123122", branch_code: "123123", account_type: "savings", id_number: "198273981723", initials: "WC", account_name: "Tenant", amount: 500000, action_date: Date.today, user_ref: "301"},
72
+ { account_number: "45645645642", branch_code: "123123", account_type: "savings", id_number: "198273922723", initials: "WX", account_name: "Tefant", amount: 250000, action_date: Date.today, user_ref: "302"},
73
+ { account_number: "78978978972", branch_code: "789789", account_type: "savings", id_number: "197873933723", initials: "WB", account_name: "Tebant", amount: 750000, action_date: Date.today, user_ref: "303"}
74
+ ]
75
+ }]
76
+
77
+ @hash = {
78
+ type: 'debit',
79
+ data: {type_of_service: "ONE DAY", batches: @data}
80
+ }
81
+ end
82
+
83
+ it "should be able to queue a batched request of debit orders" do
84
+ Bankserv::Debit.request(@hash).should be_true
85
+ Bankserv::Debit.all.each {|db| db.completed?.should be_false }
86
+ Bankserv::Credit.all.each {|db| db.new?.should be_true }
87
+ end
88
+
89
+ it "should link all debit order to their respective credit record" do
90
+ Bankserv::Debit.request(@hash)
91
+ Bankserv::Debit.all.map(&:batch_id).uniq.length.should == 2
92
+ end
93
+
94
+ end
95
+
96
+ context "when processing an unpaid debit response" do
97
+
98
+ before(:each) do
99
+ @debit = create(:debit)
100
+
101
+ @unpaid_response = {
102
+ :rec_id=>"013",
103
+ :rec_status=>"T",
104
+ :transaction_type=>"50",
105
+ :transmission_date=>"20010111",
106
+ :original_sequence_number=>"3378",
107
+ :homing_branch_code=>"270124",
108
+ :homing_account_number=>"53090317766",
109
+ :amount=>"13755",
110
+ :user_ref=>"DEBIT5",
111
+ :rejection_reason=>"2",
112
+ :rejection_qualifier=>"0",
113
+ :distribution_sequence_number=>"0",
114
+ :homing_account_name=>"",
115
+ :response_status=>"unpaid"
116
+ }
117
+
118
+ @debit.process_response(@unpaid_response)
119
+ end
120
+
121
+ it "should be marked as unpaid if the response status is unpaid" do
122
+ @debit.unpaid?.should be_true
123
+ end
124
+
125
+ it "should record the rejection reason code" do
126
+ @debit.response[:rejection_reason].should == "2"
127
+ end
128
+
129
+ it "should record a rejection reason description" do
130
+ @debit.response[:rejection_reason_description].should == "NOT PROVIDED FOR"
131
+ end
132
+
133
+ it "should record the rejection qualifier code" do
134
+ @debit.response[:rejection_qualifier].should == "0"
135
+ end
136
+
137
+ it "should record the rejection qualifier description" do
138
+ @debit.response[:rejection_qualifier_description].should be_nil
139
+ end
140
+
141
+ end
142
+
143
+ context "when processing a redirect debit response" do
144
+
145
+ before(:each) do
146
+ @debit = create(:debit)
147
+
148
+ @redirect_response = {
149
+ :rec_id=>"017",
150
+ :rec_status=>"T",
151
+ :transaction_type=>"50",
152
+ :transmission_date=>"20010116",
153
+ :original_sequence_number=>"73",
154
+ :homing_branch=>"52749",
155
+ :homing_account=>"405662263",
156
+ :amount=>"9964",
157
+ :user_ref=>"DEBIT2",
158
+ :new_homing_branch=>"55",
159
+ :new_homing_account_number=>"405663293",
160
+ :new_homing_account_type=>"2",
161
+ :distribution_sequence_number=>"0",
162
+ :homing_account_name=>"",
163
+ :response_status=>"redirect"
164
+ }
165
+
166
+ @debit.process_response(@redirect_response)
167
+ end
168
+
169
+ it "should be marked as redirect if the response status is redirect" do
170
+ @debit.redirect?.should be_true
171
+ end
172
+
173
+ it "should record the new homing branch" do
174
+ @debit.response[:new_homing_branch].should == "55"
175
+ end
176
+
177
+ it "should record the new homing account number" do
178
+ @debit.response[:new_homing_account_number].should == "405663293"
179
+ end
180
+
181
+ it "should record the new homing account type" do
182
+ @debit.response[:new_homing_account_type].should == "2"
183
+ end
184
+
185
+ end
186
+
187
+ end
@@ -0,0 +1,142 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bankserv::Engine do
4
+ include Helpers
5
+
6
+ before(:all) do
7
+ FileUtils.mkdir(Dir.pwd + "/spec/examples/host2host/archives") unless File.directory?(Dir.pwd + "/spec/examples/host2host/archives")
8
+ FileUtils.copy(Dir.pwd + "/spec/examples/tmp/OUTPUT0412153500.txt", Dir.pwd + "/spec/examples/host2host/")
9
+ FileUtils.copy(Dir.pwd + "/spec/examples/tmp/REPLY0412153000.txt", Dir.pwd + "/spec/examples/host2host/")
10
+ end
11
+
12
+ after(:all) do
13
+ Dir.glob(Dir.pwd + "/spec/examples/host2host/*.txt").each do |input_file|
14
+ File.delete(input_file)
15
+ end
16
+
17
+ FileUtils.rm_rf(Dir.pwd + "/spec/examples/host2host/archives", secure: true)
18
+
19
+ end
20
+
21
+ context "Prepare engine" do
22
+
23
+ it "should contain default values from the migration" do
24
+ Bankserv::Engine.config.should == { interval_in_minutes: 15, input_directory: "/tmp", output_directory: "/tmp", archive_directory: "/tmp" }
25
+ end
26
+
27
+ it "should be able to update engines config" do
28
+ Bankserv::Engine.interval = 15
29
+ Bankserv::Engine.output_directory = Dir.pwd + "/spec/examples/host2host"
30
+ Bankserv::Engine.config[:interval_in_minutes].should == 15
31
+ Bankserv::Engine.config[:output_directory].should == Dir.pwd + "/spec/examples/host2host"
32
+ end
33
+
34
+ it "should not have any running processes" do
35
+ Bankserv::Engine.running?.should be_false
36
+ end
37
+
38
+ end
39
+
40
+ context "Testing individual methods of engine" do
41
+
42
+ before(:all) do
43
+ t = Time.local(2012, 1, 23, 10, 5, 0)
44
+ Timecop.travel(t)
45
+ file_contents = File.open("./spec/examples/eft_input_with_2_sets.txt", "rb").read
46
+ Bankserv::InputDocument.store(file_contents)
47
+
48
+ Bankserv::Document.last.mark_processed!
49
+
50
+ Bankserv::Engine.output_directory = Dir.pwd + "/spec/examples/host2host"
51
+ Bankserv::Engine.input_directory = Dir.pwd + "/spec/examples/host2host"
52
+ Bankserv::Engine.archive_directory = Dir.pwd + "/spec/examples/host2host/archives"
53
+
54
+ @queue = Bankserv::Engine.new
55
+ end
56
+
57
+ it "should be able to start processing work" do
58
+ @queue.start!.should be_true
59
+ end
60
+
61
+ it "should be set to running" do
62
+ @queue.running?.should be_true
63
+ end
64
+
65
+ it "should be expecting a reply file" do
66
+ @queue.expecting_reply_file?.should be_true
67
+ end
68
+
69
+ it "should be able to return a list of reply files" do
70
+ Bankserv::Engine.reply_files.should == ["REPLY0412153000.txt"]
71
+ end
72
+
73
+ it "should be able to return a list of output files" do
74
+ Bankserv::Engine.output_files.should == ["OUTPUT0412153500.txt"]
75
+ end
76
+
77
+ it "should be able to process reply files" do
78
+ @queue.process_reply_files
79
+ Bankserv::Document.first.reply_status.should == "ACCEPTED"
80
+ @queue.expecting_reply_file?.should be_false
81
+ end
82
+
83
+ it "should be able to process output files" do
84
+ @queue.process_output_files
85
+ end
86
+
87
+ it "should be able to set the process to finished" do
88
+ @queue.finish!.should be_true
89
+ @queue.running?.should be_false
90
+ @queue.process.success.should be_true
91
+ end
92
+
93
+ it "should not have any processes running" do
94
+ Bankserv::Engine.running?.should be_false
95
+ end
96
+
97
+ end
98
+
99
+ context "Processing an input document." do
100
+
101
+ before(:all) do
102
+ Bankserv::Document.delete_all
103
+ Bankserv::Set.delete_all
104
+ Bankserv::Record.delete_all
105
+ Bankserv::AccountHolderVerification.delete_all
106
+ Bankserv::Debit.delete_all
107
+ Bankserv::Credit.delete_all
108
+
109
+ tear_it_down
110
+ create(:configuration, client_code: "986", client_name: "TESTTEST", user_code: "9999", user_generation_number: 846, client_abbreviated_name: "TESTTEST")
111
+
112
+ t = Time.local(2008, 8, 8, 10, 5, 0)
113
+ Timecop.travel(t)
114
+
115
+ create_credit_request
116
+
117
+ Bankserv::Configuration.stub!(:live_env?).and_return(true)
118
+ Bankserv::InputDocument.stub!(:fetch_next_transmission_number).and_return("846")
119
+ Bankserv::Record.create! record_type:"standard_record", data: {user_sequence_number: 77}, set_id: 76876
120
+
121
+ Bankserv::Engine.output_directory = Dir.pwd + "/spec/examples/host2host"
122
+ Bankserv::Engine.input_directory = Dir.pwd + "/spec/examples/host2host"
123
+ Bankserv::Engine.archive_directory = Dir.pwd + "/spec/examples/host2host/archives"
124
+
125
+ @queue = Bankserv::Engine.new
126
+ @queue.start! # create a process
127
+ end
128
+
129
+ it "should process the document" do
130
+ @queue.process_input_files
131
+ @document = Bankserv::Document.last
132
+ @document.processed.should be_true
133
+ @queue.expecting_reply_file?.should be_true
134
+ end
135
+
136
+ it "should write a file to the input directory" do
137
+ (Dir.glob(Dir.pwd + "/spec/examples/host2host/INPUT*.txt").size == 1).should be_true
138
+ end
139
+
140
+ end
141
+
142
+ end