absa-h2h 0.0.11
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.
- data/.gitignore +5 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/README +0 -0
- data/Rakefile +7 -0
- data/absa-h2h.gemspec +23 -0
- data/lib/absa-h2h/account_holder_verification.rb +22 -0
- data/lib/absa-h2h/account_holder_verification_output.rb +22 -0
- data/lib/absa-h2h/eft/rejection_code.rb +30 -0
- data/lib/absa-h2h/eft.rb +200 -0
- data/lib/absa-h2h/eft_output.rb +12 -0
- data/lib/absa-h2h/eft_redirect.rb +13 -0
- data/lib/absa-h2h/eft_unpaid.rb +13 -0
- data/lib/absa-h2h/reply.rb +27 -0
- data/lib/absa-h2h/transmission/document.rb +26 -0
- data/lib/absa-h2h/transmission/record.rb +18 -0
- data/lib/absa-h2h/transmission/set.rb +168 -0
- data/lib/absa-h2h/version.rb +5 -0
- data/lib/absa-h2h.rb +22 -0
- data/lib/config/account_holder_verification.yml +196 -0
- data/lib/config/account_holder_verification_output.yml +182 -0
- data/lib/config/document.yml +54 -0
- data/lib/config/eft.yml +284 -0
- data/lib/config/eft_output.yml +65 -0
- data/lib/config/eft_redirect.yml +129 -0
- data/lib/config/eft_rejection_codes.yml +321 -0
- data/lib/config/eft_unpaid.yml +125 -0
- data/lib/config/reply.yml +222 -0
- data/lib/tmp/test.txt +0 -0
- data/spec/examples/ahv_input_file.txt +7 -0
- data/spec/examples/ahv_output_file.txt +7 -0
- data/spec/examples/eft_input_credit_file.txt +166 -0
- data/spec/examples/eft_input_credit_file2.txt +0 -0
- data/spec/examples/eft_input_file.txt +20 -0
- data/spec/examples/eft_output_file.txt +35 -0
- data/spec/examples/reply_file.txt +5 -0
- data/spec/examples/transmission_header_file.txt +1 -0
- data/spec/lib/account_holder_verification_spec.rb +157 -0
- data/spec/lib/eft/rejection_code_spec.rb +37 -0
- data/spec/lib/eft_output_spec.rb +9 -0
- data/spec/lib/eft_spec.rb +369 -0
- data/spec/lib/eft_transaction_standard_spec.rb +88 -0
- data/spec/lib/string_spec.rb +9 -0
- data/spec/lib/transmission/document_spec.rb +152 -0
- data/spec/lib/transmission/header_spec.rb +28 -0
- data/spec/lib/transmission/record_spec.rb +24 -0
- data/spec/lib/transmission/trailer_spec.rb +26 -0
- data/spec/spec_helper.rb +9 -0
- metadata +135 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Absa::H2h::Transmission::AccountHolderVerification do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
|
7
|
+
@internal_section_content = [
|
8
|
+
{type: 'header', data: {
|
9
|
+
rec_id: "030",
|
10
|
+
rec_status: "T",
|
11
|
+
gen_no: "5",
|
12
|
+
dept_code: "000006"
|
13
|
+
}},
|
14
|
+
{type: 'internal_account_detail', data: {
|
15
|
+
rec_id: "031",
|
16
|
+
rec_status: "T",
|
17
|
+
seq_no: "1",
|
18
|
+
account_number: "1094402524",
|
19
|
+
id_number: "6703085829086",
|
20
|
+
initials: "M",
|
21
|
+
surname: "CHAUKE",
|
22
|
+
return_code_1: "00",
|
23
|
+
return_code_2: "00",
|
24
|
+
return_code_3: "00",
|
25
|
+
return_code_4: "00",
|
26
|
+
user_ref: "1495050000600002236"
|
27
|
+
}},
|
28
|
+
{type: 'internal_account_detail', data: {
|
29
|
+
rec_id: "031",
|
30
|
+
rec_status: "T",
|
31
|
+
seq_no: "2",
|
32
|
+
account_number: "1094402524",
|
33
|
+
id_number: "6703085829086",
|
34
|
+
initials: "S",
|
35
|
+
surname: "CHAUKE",
|
36
|
+
return_code_1: "00",
|
37
|
+
return_code_2: "00",
|
38
|
+
return_code_3: "00",
|
39
|
+
return_code_4: "00",
|
40
|
+
user_ref: "1495050000600002236"
|
41
|
+
}},
|
42
|
+
{type: 'trailer', data: {
|
43
|
+
rec_id: "039",
|
44
|
+
rec_status: "T",
|
45
|
+
no_det_recs: "2",
|
46
|
+
acc_total: "6554885370"
|
47
|
+
}}
|
48
|
+
]
|
49
|
+
|
50
|
+
@external_section_content = [
|
51
|
+
{type: 'header', data: {
|
52
|
+
rec_id: "030",
|
53
|
+
rec_status: "T",
|
54
|
+
gen_no: "5",
|
55
|
+
dept_code: "000006"
|
56
|
+
}},
|
57
|
+
{
|
58
|
+
type: 'external_account_detail',
|
59
|
+
data: {
|
60
|
+
rec_id: "031",
|
61
|
+
rec_status: "T",
|
62
|
+
seq_no: "1",
|
63
|
+
account_number: "1094402524",
|
64
|
+
id_number: "6703085829086",
|
65
|
+
initials: "DA",
|
66
|
+
surname: "ANDERSON",
|
67
|
+
return_code_1: "00",
|
68
|
+
return_code_2: "00",
|
69
|
+
return_code_3: "00",
|
70
|
+
return_code_4: "00",
|
71
|
+
user_ref: "AND033",
|
72
|
+
branch_code: "255023",
|
73
|
+
originating_bank: "60",
|
74
|
+
ld_code: "LD00000",
|
75
|
+
return_code_5: "00",
|
76
|
+
return_code_6: "00",
|
77
|
+
return_code_7: "00",
|
78
|
+
return_code_8: "00",
|
79
|
+
return_code_9: "00",
|
80
|
+
return_code_10: "00",
|
81
|
+
}
|
82
|
+
},
|
83
|
+
{type: 'trailer', data: {
|
84
|
+
rec_id: "039",
|
85
|
+
rec_status: "T",
|
86
|
+
no_det_recs: "1",
|
87
|
+
acc_total: "6554885370"
|
88
|
+
}}
|
89
|
+
]
|
90
|
+
|
91
|
+
@hash = {
|
92
|
+
type: 'document',
|
93
|
+
data: [
|
94
|
+
{type: 'account_holder_verification', data: @internal_section_content},
|
95
|
+
{type: 'account_holder_verification',data: @external_section_content}
|
96
|
+
]
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should be able to build a header" do
|
101
|
+
header = Absa::H2h::Transmission::AccountHolderVerification::Header.new(@internal_section_content[0][:data])
|
102
|
+
|
103
|
+
string = " " * 198 + "\r\n"
|
104
|
+
string[0,17] = "030T0000005000006"
|
105
|
+
|
106
|
+
header.to_s.should == string
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should be able to build a trailer" do
|
110
|
+
header = Absa::H2h::Transmission::AccountHolderVerification::Trailer.new(@internal_section_content[-1][:data])
|
111
|
+
|
112
|
+
string = " " * 198 + "\r\n"
|
113
|
+
string[0,29] = "039T0000002000000006554885370"
|
114
|
+
|
115
|
+
header.to_s.should == string
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should be able to build an internal transaction record" do
|
119
|
+
string1 = " " * 198 + "\r\n"
|
120
|
+
string2 = " " * 198 + "\r\n"
|
121
|
+
string1[0,143] = "031T00000010000000010944025246703085829086M CHAUKE 000000001495050000600002236 "
|
122
|
+
string2[0,143] = "031T00000020000000010944025246703085829086S CHAUKE 000000001495050000600002236 "
|
123
|
+
|
124
|
+
result = @internal_section_content[1..-2].map do |t|
|
125
|
+
Absa::H2h::Transmission::AccountHolderVerification::InternalAccountDetail.new(t[:data]).to_s
|
126
|
+
end.join
|
127
|
+
|
128
|
+
result.should == (string1 + string2)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should be able to build an external transaction record" do
|
132
|
+
string = " " * 198 + "\r\n"
|
133
|
+
string[0,174] = "031T00000010000000010944025246703085829086DA ANDERSON 00000000AND033 255023000060LD00000000000000000"
|
134
|
+
|
135
|
+
result = @external_section_content[1..-2].map do |t|
|
136
|
+
Absa::H2h::Transmission::AccountHolderVerification::ExternalAccountDetail.new(t[:data]).to_s
|
137
|
+
end.join
|
138
|
+
|
139
|
+
result.should == string
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should validate that the number of transactions matches the specified amount in the trailer" do
|
143
|
+
lambda {Absa::H2h::Transmission::AccountHolderVerification::build(@internal_section_content)}.should_not raise_error(Exception)
|
144
|
+
|
145
|
+
@internal_section_content[-1][:data][:no_det_recs] = "3"
|
146
|
+
lambda {Absa::H2h::Transmission::AccountHolderVerification::build(@internal_section_content)}.should raise_error(Exception, "no_det_recs mismatch: expected 3, got 2")
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should validate that the transaction sequence numbers are a contigious index of numbers" do
|
150
|
+
lambda {Absa::H2h::Transmission::AccountHolderVerification::build(@internal_section_content)}.should_not raise_error(Exception)
|
151
|
+
|
152
|
+
@internal_section_content[1][:data][:seq_no] = "2"
|
153
|
+
lambda {Absa::H2h::Transmission::AccountHolderVerification::build(@internal_section_content)}.should raise_error(Exception, 'seq_no mismatch: ["2", "2"]')
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Absa::H2h::Eft::RejectionCode do
|
4
|
+
|
5
|
+
it "should provide a list of eft rejection reasons" do
|
6
|
+
list = Absa::H2h::Eft::RejectionCode.reasons
|
7
|
+
|
8
|
+
list.length.should == 52
|
9
|
+
|
10
|
+
list.each do |code, reason|
|
11
|
+
code.is_a?(String).should be_true
|
12
|
+
reason.is_a?(String).should be_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should retrieve a rejection reason for a given code" do
|
17
|
+
reason = Absa::H2h::Eft::RejectionCode.reason_for_code("2")
|
18
|
+
reason.should == "NOT PROVIDED FOR"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should provide a list of eft rejection qualifiers" do
|
22
|
+
list = Absa::H2h::Eft::RejectionCode.qualifiers
|
23
|
+
|
24
|
+
list.length.should == 267
|
25
|
+
|
26
|
+
list.each do |code, qualifier|
|
27
|
+
code.is_a?(String).should be_true
|
28
|
+
qualifier.is_a?(String).should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should retrieve a rejection qualifier for a given code" do
|
33
|
+
reason = Absa::H2h::Eft::RejectionCode.qualifier_for_code("2")
|
34
|
+
reason.should == "COURT ORDER HOLD ON ACCOUNT"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,369 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Absa::H2h::Transmission::Eft do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@hash = {
|
7
|
+
type: 'document',
|
8
|
+
data: [
|
9
|
+
{type: 'header', data: {}},
|
10
|
+
{type: 'eft', data: [
|
11
|
+
{type: 'header', data: {
|
12
|
+
rec_id: "001",
|
13
|
+
rec_status: "T",
|
14
|
+
bankserv_record_identifier: "04",
|
15
|
+
bankserv_user_code: "9534",
|
16
|
+
bankserv_creation_date: Time.now.strftime("%y%m%d"),
|
17
|
+
bankserv_purge_date: Time.now.strftime("%y%m%d"),
|
18
|
+
first_action_date: Time.now.strftime("%y%m%d"),
|
19
|
+
last_action_date: Time.now.strftime("%y%m%d"),
|
20
|
+
first_sequence_number: "1",
|
21
|
+
user_generation_number: "37",
|
22
|
+
type_of_service: "CORPSSV",
|
23
|
+
}},
|
24
|
+
{
|
25
|
+
type: "standard_record",
|
26
|
+
data: {
|
27
|
+
rec_id: "001",
|
28
|
+
rec_status: "T",
|
29
|
+
bankserv_record_identifier: "50",
|
30
|
+
user_branch: "632005",
|
31
|
+
user_nominated_account: "4053538939",
|
32
|
+
user_code: "9534",
|
33
|
+
user_sequence_number: "1",
|
34
|
+
homing_branch: "632005",
|
35
|
+
homing_account_number: "01019611899",
|
36
|
+
type_of_account: "1",
|
37
|
+
amount: "1000",
|
38
|
+
action_date: Time.now.strftime("%y%m%d"),
|
39
|
+
entry_class: "44",
|
40
|
+
tax_code: "0",
|
41
|
+
user_ref: "ALIMITTST1SPP 040524 01",
|
42
|
+
homing_account_name: "HENNIE DU TOIT 040524",
|
43
|
+
homing_institution: "21"
|
44
|
+
}},
|
45
|
+
{type: "contra_record", data: {
|
46
|
+
rec_id: "001",
|
47
|
+
rec_status: "T",
|
48
|
+
bankserv_record_identifier: "52",
|
49
|
+
user_branch: "632005",
|
50
|
+
user_nominated_account: "4053538939",
|
51
|
+
user_code: "9534",
|
52
|
+
user_sequence_number: "2",
|
53
|
+
homing_branch: "632005",
|
54
|
+
homing_account_number: "4053538939",
|
55
|
+
type_of_account: "1",
|
56
|
+
amount: "1000",
|
57
|
+
action_date: Time.now.strftime("%y%m%d"),
|
58
|
+
entry_class: "10",
|
59
|
+
user_ref: "ALIMITTST1CONTRA 040524 08"
|
60
|
+
}},
|
61
|
+
{type: 'trailer', data: {
|
62
|
+
rec_id: "001",
|
63
|
+
rec_status: "T",
|
64
|
+
bankserv_record_identifier: "92",
|
65
|
+
bankserv_user_code: "9534",
|
66
|
+
first_sequence_number: "1",
|
67
|
+
last_sequence_number: "2",
|
68
|
+
first_action_date: Time.now.strftime("%y%m%d"),
|
69
|
+
last_action_date: Time.now.strftime("%y%m%d"),
|
70
|
+
no_debit_records: "1",
|
71
|
+
no_credit_records: "1",
|
72
|
+
no_contra_records: "1",
|
73
|
+
total_debit_value: "1000",
|
74
|
+
total_credit_value: "1000",
|
75
|
+
hash_total_of_homing_account_numbers: "5073150838",
|
76
|
+
}}
|
77
|
+
]},
|
78
|
+
{type: 'trailer', data: {}}
|
79
|
+
]
|
80
|
+
}
|
81
|
+
|
82
|
+
@invalid_transaction = {
|
83
|
+
type: "standard_record",
|
84
|
+
data: {
|
85
|
+
rec_id: "001",
|
86
|
+
rec_status: "T",
|
87
|
+
bankserv_record_identifier: "50",
|
88
|
+
user_branch: "632005",
|
89
|
+
user_nominated_account: "4053538939",
|
90
|
+
user_code: "9534",
|
91
|
+
user_sequence_number: "1",
|
92
|
+
homing_branch: "632005",
|
93
|
+
homing_account_number: "01019611899",
|
94
|
+
type_of_account: "1",
|
95
|
+
amount: "1000",
|
96
|
+
action_date: (Time.now + (2*24*3600)).strftime("%y%m%d"),
|
97
|
+
entry_class: "44",
|
98
|
+
tax_code: "0",
|
99
|
+
user_ref: "ALIMITTST1SPP 040524 01",
|
100
|
+
homing_account_name: "HENNIE DU TOIT 040524",
|
101
|
+
homing_institution: "21"
|
102
|
+
},
|
103
|
+
}
|
104
|
+
|
105
|
+
@user_set = @hash[:data][1][:data]
|
106
|
+
today = Time.now.strftime("%y%m%d")
|
107
|
+
@header = " " * 198 + "\r\n"
|
108
|
+
@header[0,51] = "001T049534#{today}#{today}#{today}#{today}0000010037CORPSSV"
|
109
|
+
|
110
|
+
@trailer = " " * 198 + "\r\n"
|
111
|
+
@trailer[0,88] = "001T929534000001000002#{today}#{today}000001000001000001000000001000000000001000005073150838"
|
112
|
+
@transaction = " " * 198 + "\r\n"
|
113
|
+
@transaction[0,172] = "001T5063200504053538939953400000163200501019611899100000001000#{today}440 ALIMITTST1SPP 040524 01 HENNIE DU TOIT 040524 21"
|
114
|
+
@transaction[134, 20] = "0" * 20
|
115
|
+
|
116
|
+
@additional_transactions = [{type: "standard_record", data: { rec_id: "001", rec_status: "T", bankserv_record_identifier: "50",user_branch: "632005",
|
117
|
+
user_nominated_account: "4053538939", user_code: "9534",user_sequence_number: "3",homing_branch: "632005",homing_account_number: "01019611899",type_of_account: "1",
|
118
|
+
amount: "12000",action_date: Time.now.strftime("%y%m%d"),entry_class: "44",tax_code: "0",user_ref: "ALIMITTST1SPP 040524 01",homing_account_name: "HENNIE DU TOIT 040524",
|
119
|
+
homing_institution: "21"
|
120
|
+
}},
|
121
|
+
{type: "standard_record", data: { rec_id: "001", rec_status: "T", bankserv_record_identifier: "50",user_branch: "632005",
|
122
|
+
user_nominated_account: "4053538939", user_code: "9534",user_sequence_number: "4",homing_branch: "632005",homing_account_number: "01019611899",type_of_account: "1",
|
123
|
+
amount: "1000",action_date: Time.now.strftime("%y%m%d"),entry_class: "44",tax_code: "0",user_ref: "ALIMITTST1SPP 040524 01",homing_account_name: "HENNIE DU TOIT 040524",
|
124
|
+
homing_institution: "21"
|
125
|
+
}},
|
126
|
+
{type: "standard_record", data: { rec_id: "001", rec_status: "T", bankserv_record_identifier: "50",user_branch: "632005",
|
127
|
+
user_nominated_account: "4053538939", user_code: "9534",user_sequence_number: "5",homing_branch: "632005",homing_account_number: "01019611899",type_of_account: "1",
|
128
|
+
amount: "4000",action_date: Time.now.strftime("%y%m%d"),entry_class: "44",tax_code: "0",user_ref: "ALIMITTST1SPP 040524 01",homing_account_name: "HENNIE DU TOIT 040524",
|
129
|
+
homing_institution: "21"
|
130
|
+
}},
|
131
|
+
{type: "standard_record", data: { rec_id: "001", rec_status: "T", bankserv_record_identifier: "50",user_branch: "632005",
|
132
|
+
user_nominated_account: "4053538939", user_code: "9534",user_sequence_number: "6",homing_branch: "632005",homing_account_number: "01019611899",type_of_account: "1",
|
133
|
+
amount: "3500",action_date: Time.now.strftime("%y%m%d"),entry_class: "44",tax_code: "0",user_ref: "ALIMITTST1SPP 040524 01",homing_account_name: "HENNIE DU TOIT 040524",
|
134
|
+
homing_institution: "21"
|
135
|
+
}},
|
136
|
+
{type: "contra_record",data: {rec_id: "001",rec_status: "T",bankserv_record_identifier: "52",user_branch: "632005",user_nominated_account: "4053538939",
|
137
|
+
user_code: "9534", user_sequence_number: "7",homing_branch: "632005",homing_account_number: "4053538939",type_of_account: "1",amount: "21500",
|
138
|
+
action_date: Time.now.strftime("%y%m%d"),entry_class: "10",user_ref: "ALIMITTST1CONTRA 040524 08"
|
139
|
+
}}]
|
140
|
+
end
|
141
|
+
|
142
|
+
context "building a header" do
|
143
|
+
|
144
|
+
it "should be able to build a document header" do
|
145
|
+
header = Absa::H2h::Transmission::Eft::Header.new(@user_set[0][:data])
|
146
|
+
today = Time.now.strftime("%y%m%d")
|
147
|
+
|
148
|
+
string = " " * 198 + "\r\n"
|
149
|
+
string[0,51] = "001T049534#{today}#{today}#{today}#{today}0000010037CORPSSV"
|
150
|
+
|
151
|
+
header.to_s.should == string
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should raise an exception if a provided field exceeds the allowed length" do
|
155
|
+
@user_set[0][:data][:rec_id] = "0000"
|
156
|
+
lambda {document = Absa::H2h::Transmission::Eft::Header.new(@user_set[0][:data])}.should raise_error("rec_id: Input too long")
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should raise an exception if a provided field is not a specified type" do
|
160
|
+
@user_set[0][:data][:type_of_service] = "SAVINGS"
|
161
|
+
lambda {document = Absa::H2h::Transmission::Eft::Header.new(@user_set[0][:data])}.should raise_error("type_of_service: Invalid data")
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
context "building a trailer" do
|
167
|
+
|
168
|
+
it "should be able to build a document trailer" do
|
169
|
+
trailer = Absa::H2h::Transmission::Eft::Trailer.new(@user_set[-1][:data])
|
170
|
+
today = Time.now.strftime("%y%m%d")
|
171
|
+
|
172
|
+
string = " " * 198 + "\r\n"
|
173
|
+
string[0,88] = "001T929534000001000002#{today}#{today}000001000001000001000000001000000000001000005073150838"
|
174
|
+
|
175
|
+
trailer.to_s.should == string
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should be able to build an eft user set" do
|
181
|
+
eft = Absa::H2h::Transmission::Eft.build(@user_set)
|
182
|
+
eft.header.to_s.should == @header
|
183
|
+
eft.trailer.to_s.should == @trailer
|
184
|
+
eft.transactions.first.to_s.should == @transaction
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should validate the action date for the transaction records" do
|
188
|
+
@invalid_transaction[:data][:user_sequence_number] = '3'
|
189
|
+
@user_set = @user_set[0..-2] + [@invalid_transaction] + [@user_set[-1]]
|
190
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("action_date: Must be within the range of the headers first_action_date and last_action_date")
|
191
|
+
end
|
192
|
+
|
193
|
+
it "should validate the record status of the header and trailer records" do
|
194
|
+
@user_set[-1][:data][:rec_status] = 'L'
|
195
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("rec_status: Trailer and Header record status must be equal")
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should validate the record status of the header and transaction records" do
|
199
|
+
@user_set[1..-2].first[:data][:rec_status] = 'L'
|
200
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("rec_status: Transaction and Header record status must be equal")
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should validate the first standard transaction record and header record sequence numbers" do
|
204
|
+
@user_set[1..-2].first[:data][:user_sequence_number] = '2'
|
205
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_sequence_number: 1st Standard transactions user sequence number and the headers first sequence number must be equal.")
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should check for duplicate user sequence numbers in transactions" do
|
209
|
+
@invalid_transaction[:data][:action_date] = Time.now.strftime("%y%m%d")
|
210
|
+
@user_set = @user_set[0..-2] + [@invalid_transaction] + [@user_set[-1]]
|
211
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_sequence_number: Duplicate user sequence number. Transactions must have unique sequence numbers!")
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should check that transactions increment sequentially" do
|
215
|
+
@invalid_transaction[:data][:user_sequence_number] = "5"
|
216
|
+
@user_set = @user_set[0..-2] + [@invalid_transaction] + [@user_set[-1]]
|
217
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_sequence_number: Transactions must increment sequentially. Got: #{["1", "2", "5"]}")
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should validate the bankserv user code in the Trailer and header" do
|
221
|
+
@user_set[-1][:data][:bankserv_user_code] = "7890"
|
222
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("bankserv_user_code: Trailer and Header user code must be equal.")
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should validate the first sequence number in the Trailer and header" do
|
226
|
+
@user_set[-1][:data][:first_sequence_number] = "3"
|
227
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("first_sequence_number: Trailer and Header sequence number must be equal.")
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should validate the first action date in the Trailer and header" do
|
231
|
+
@user_set[-1][:data][:first_action_date] = (Time.now + (2*24*3600)).strftime("%y%m%d")
|
232
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("first_action_date: Trailer and Header first action date must be equal.")
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should validate the last action date in the Trailer and header" do
|
236
|
+
@user_set[-1][:data][:last_action_date] = (Time.now + (2*24*3600)).strftime("%y%m%d")
|
237
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("last_action_date: Trailer and Header last action date must be equal.")
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should have a contra record containing the total monetary value of all preceding standard transactions" do
|
241
|
+
@user_set[1..-2].last[:data][:amount] = "2000"
|
242
|
+
lambda {eft = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("amount: Contra record amount must be the sum amount of all preceeding transactions. Expected 1000. Got 2000.")
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should test all contra records monetary value in a given user set" do
|
246
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
247
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("amount: Contra record amount must be the sum amount of all preceeding transactions. Expected 20500. Got 21500.")
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should test all contra records action dates in a given user set" do
|
251
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
252
|
+
today = Time.now.strftime("%y%m%d")
|
253
|
+
@user_set[0][:data][:last_action_date] = (Time.now + (3*24*3600)).strftime("%y%m%d")
|
254
|
+
@user_set[-1][:data][:last_action_date] = (Time.now + (3*24*3600)).strftime("%y%m%d")
|
255
|
+
@user_set[1..-2][3][:data][:action_date] = (Time.now + (2*24*3600)).strftime("%y%m%d")
|
256
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
257
|
+
|
258
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("action_date: Contra records action date must be equal to all preceeding standard transactions action date. Got [\"#{today}\", \"#{(Time.now + (2*24*3600)).strftime("%y%m%d")}\", \"#{today}\", \"#{today}\"].")
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should validate the contra records user nominated account against all its transactions" do
|
262
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
263
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
264
|
+
@user_set[1..-2][-2][:data][:user_nominated_account] = "4053538949"
|
265
|
+
|
266
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_nominated_account: Contra records user nominated account must match all preceeding standard transactions user nominated accounts. Got [\"4053538939\", \"4053538939\", \"4053538939\", \"4053538949\"].")
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should validate the contra records user branch against all its transactions" do
|
270
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
271
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
272
|
+
@user_set[1..-2][-2][:data][:user_branch] = "632100"
|
273
|
+
|
274
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_branch_code: Contra records user branch must match all preceeding standard transactions user branch. Got [\"632005\", \"632005\", \"632005\", \"632100\"].")
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should raise an error if the contras homing branch does not match the user branch" do
|
278
|
+
@user_set[1..-2].last[:data][:homing_branch] = "632100"
|
279
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("homing_branch: Should match the user branch. Got 632100. Expected 632005.")
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should raise an error if the contras homing account number does not match the user nominated account number" do
|
283
|
+
@user_set[1..-2].last[:data][:homing_account_number] = "2929292"
|
284
|
+
lambda {document = Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("homing_account_number: Should match the user nominated account number. Got 2929292. Expected 4053538939.")
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should raise an error if the contras user code does not match the headers bankserv user code" do
|
288
|
+
@user_set[1..-2].last[:data][:user_code] = "8888"
|
289
|
+
lambda { Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_code: Contra records user code must match the headers users code. Got 8888. Expected 9534.")
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should raise an error if the contras user reference position 1-10 is blank" do
|
293
|
+
@user_set[1..-2].last[:data][:user_ref] = " CONTRA 040524 08"
|
294
|
+
lambda { Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_ref: Position 1 - 10 is compulsory. Please provide users abbreviated name.")
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should raise an error if the contras user reference position 11-16 does not match CONTRA" do
|
298
|
+
@user_set[1..-2].last[:data][:user_ref] = "ALIMITTST1CON RA 040524 08"
|
299
|
+
lambda { Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("user_ref: Position 11 - 16 is compulsory and must be set to 'CONTRA'. Got CON RA")
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should raise an error if the trailer records last sequence number does not match the preceeding contra records sequence number" do
|
303
|
+
@user_set[-1][:data][:last_sequence_number] = "16"
|
304
|
+
lambda { Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("last_sequence_number: Trailer records last sequence number must match the last contra records sequence number. Got 16. Expected 2")
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should validate the contra records user nominated account against all its transactions" do
|
308
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
309
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
310
|
+
@user_set[-1][:data][:last_sequence_number] = "7"
|
311
|
+
|
312
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("no_debit_records: Trailer records number of debit records must match the number of debit records. Expected 5. Got 1.")
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should validate the number of debit transactions in a user set" do
|
316
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
317
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
318
|
+
@user_set[-1][:data][:last_sequence_number] = "7"
|
319
|
+
|
320
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("no_debit_records: Trailer records number of debit records must match the number of debit records. Expected 5. Got 1.")
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should validate the number of credit transactions in a user set" do
|
324
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
325
|
+
|
326
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
327
|
+
@user_set[-1][:data][:last_sequence_number] = "7"
|
328
|
+
@user_set[-1][:data][:no_debit_records] = "4"
|
329
|
+
@user_set[1..-2][5][:data][:bankserv_record_identifier] = "10"
|
330
|
+
|
331
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("no_credit_records: Trailer records number of credit records must match the number of credit records and contra debit records. Expected 3. Got 1.")
|
332
|
+
end
|
333
|
+
|
334
|
+
it "should validate the number of contra transactions in a user set" do
|
335
|
+
@user_set[-1][:data][:no_contra_records] = "2"
|
336
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("no_contra_records: Trailer records number of contra records must match the number of contra records. Expected 1. Got 2.")
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should validate the total value of debit transactions and any credit contra records in the trailer" do
|
340
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
341
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
342
|
+
@user_set[-1][:data][:last_sequence_number] = "7"
|
343
|
+
@user_set[-1][:data][:no_debit_records] = "5"
|
344
|
+
@user_set[-1][:data][:no_credit_records] = "2"
|
345
|
+
@user_set[-1][:data][:no_contra_records] = "2"
|
346
|
+
@user_set[-1][:data][:total_debit_value] = "22500"
|
347
|
+
|
348
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("total_debit_value: Trailer records total debit value must equal the sum amount of all transactions and credit contra records. Expected 21500. Got 22500.")
|
349
|
+
end
|
350
|
+
|
351
|
+
it "should validate the total value of credit transactions and any debit contra records in the trailer" do
|
352
|
+
@additional_transactions.each do |t|
|
353
|
+
t[:data][:bankserv_record_identifier] = "10" if t[:type] == "standard_record"
|
354
|
+
end
|
355
|
+
|
356
|
+
@user_set = @user_set[0..-2] + @additional_transactions + [@user_set[-1]]
|
357
|
+
|
358
|
+
@user_set[1..-2].last[:data][:amount] = "20500"
|
359
|
+
@user_set[-1][:data][:last_sequence_number] = "7"
|
360
|
+
@user_set[-1][:data][:no_debit_records] = "1"
|
361
|
+
@user_set[-1][:data][:no_credit_records] = "6"
|
362
|
+
@user_set[-1][:data][:no_contra_records] = "2"
|
363
|
+
@user_set[-1][:data][:total_debit_value] = "1000"
|
364
|
+
|
365
|
+
lambda {Absa::H2h::Transmission::Eft.build(@user_set)}.should raise_error("total_credit_value: Trailer records total credit value must equal the sum amount of all transactions and debit contra records. Expected 42000. Got 1000.")
|
366
|
+
end
|
367
|
+
|
368
|
+
|
369
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Absa::H2h::Transmission::Eft::StandardRecord do
|
4
|
+
before(:each) do
|
5
|
+
@hash = {
|
6
|
+
transmission: {
|
7
|
+
user_sets: [{
|
8
|
+
type: 'eft',
|
9
|
+
content: {
|
10
|
+
transactions: [{
|
11
|
+
type: "standard_record",
|
12
|
+
content: {
|
13
|
+
rec_id: "001",
|
14
|
+
rec_status: "T",
|
15
|
+
bankserv_record_identifier: "50",
|
16
|
+
user_branch: "632005",
|
17
|
+
user_nominated_account: "4053538939",
|
18
|
+
user_code: "9534",
|
19
|
+
user_sequence_number: "1",
|
20
|
+
homing_branch: "632005",
|
21
|
+
homing_account_number: "01019611899",
|
22
|
+
type_of_account: "1",
|
23
|
+
amount: "1000",
|
24
|
+
action_date: Time.now.strftime("%y%m%d"),
|
25
|
+
entry_class: "44",
|
26
|
+
tax_code: "0",
|
27
|
+
user_ref: "ALIMITTST1SPP 040524 01",
|
28
|
+
homing_account_name: "HENNIE DU TOIT 040524",
|
29
|
+
homing_institution: "21"
|
30
|
+
}
|
31
|
+
},{
|
32
|
+
type: "contra_record",
|
33
|
+
content: {
|
34
|
+
rec_id: "001",
|
35
|
+
rec_status: "T",
|
36
|
+
bankserv_record_identifier: "52",
|
37
|
+
user_branch: "632005",
|
38
|
+
user_nominated_account: "4053538939",
|
39
|
+
user_code: "9534",
|
40
|
+
user_sequence_number: "8",
|
41
|
+
homing_branch: "632005",
|
42
|
+
homing_account_number: "4053538939",
|
43
|
+
type_of_account: "1",
|
44
|
+
amount: "16028000",
|
45
|
+
action_date: Time.now.strftime("%y%m%d"),
|
46
|
+
entry_class: "10",
|
47
|
+
user_ref: "ALIMITTST1CONTRA 040524 08"
|
48
|
+
}
|
49
|
+
}],
|
50
|
+
}
|
51
|
+
}]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
@eft_transaction = @hash[:transmission][:user_sets].first[:content][:transactions].first[:content]
|
55
|
+
@contra_transaction = @hash[:transmission][:user_sets].first[:content][:transactions].last[:content]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be able to build an eft transaction record" do
|
59
|
+
record = Absa::H2h::Transmission::Eft::StandardRecord.new(@eft_transaction)
|
60
|
+
today = Time.now.strftime("%y%m%d")
|
61
|
+
string = " " * 198 + "\r\n"
|
62
|
+
string[0,172] = "001T5063200504053538939953400000163200501019611899100000001000#{today}440 ALIMITTST1SPP 040524 01 HENNIE DU TOIT 040524 21"
|
63
|
+
string[134, 20] = "0" * 20
|
64
|
+
|
65
|
+
record.to_s.should == string
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be able to build an eft contra record" do
|
69
|
+
record = Absa::H2h::Transmission::Eft::ContraRecord.new(@contra_transaction)
|
70
|
+
|
71
|
+
today = Time.now.strftime("%y%m%d")
|
72
|
+
string = " " * 198 + "\r\n"
|
73
|
+
string[0,104] = "001T5263200504053538939953400000863200504053538939100016028000#{today}100000ALIMITTST1CONTRA 040524 08 "
|
74
|
+
|
75
|
+
record.to_s.should == string
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise an exception if the user reference has blank values for pos 1-10" do
|
79
|
+
@eft_transaction[:user_ref] = " 0404404"
|
80
|
+
lambda {Absa::H2h::Transmission::Eft::StandardRecord.new(@eft_transaction)}.should raise_error("user_ref: Position 1 - 10 is compulsory. Please provide users abbreviated name.")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should raise an exception if the homing account name is blank" do
|
84
|
+
@eft_transaction[:homing_account_name] = ""
|
85
|
+
lambda {Absa::H2h::Transmission::Eft::StandardRecord.new(@eft_transaction)}.should raise_error("homing_account_name: Not to be left blank.")
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|