xhash_client 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +59 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +74 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/lib/xhash/client/api_client.rb +27 -0
- data/lib/xhash/client/json_api.rb +48 -0
- data/lib/xhash/database_lookup.rb +28 -0
- data/lib/xhash/document_types.rb +15 -0
- data/lib/xhash/error.rb +15 -0
- data/lib/xhash/error_messages.rb +8 -0
- data/lib/xhash/formatters.rb +9 -0
- data/lib/xhash/general.rb +63 -0
- data/lib/xhash/ocr.rb +124 -0
- data/lib/xhash/sat.rb +18 -0
- data/lib/xhash/structs/curp.rb +15 -0
- data/lib/xhash/structs/customer.rb +49 -0
- data/lib/xhash/structs/identification.rb +30 -0
- data/lib/xhash/structs/proof_of_address.rb +15 -0
- data/lib/xhash/structs/rfc.rb +3 -0
- data/lib/xhash/version.rb +3 -0
- data/spec/files/ife_front.png +0 -0
- data/spec/files/ife_reverse.jpg +0 -0
- data/spec/files/telmex.png +0 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/xhash/database_lookup_spec.rb +95 -0
- data/spec/xhash/general_spec.rb +208 -0
- data/spec/xhash/ocr_spec.rb +365 -0
- data/spec/xhash/sat_spec.rb +36 -0
- data/spec/xhash_ruby_spec.rb +11 -0
- data/xhash_client.gemspec +28 -0
- metadata +43 -2
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xhash::SAT do
|
4
|
+
describe '.renapo' do
|
5
|
+
it 'successfully with valid CURP' do
|
6
|
+
curp = 'OESJ980828HDFLNR04'
|
7
|
+
|
8
|
+
stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
|
9
|
+
.to_return(
|
10
|
+
body:
|
11
|
+
JSON.dump(
|
12
|
+
{
|
13
|
+
result: true,
|
14
|
+
payload: {
|
15
|
+
curp: curp,
|
16
|
+
name: 'JERONIMO',
|
17
|
+
last_name: 'OLIVA',
|
18
|
+
mothers_last_name: 'SANCHEZ',
|
19
|
+
gender: 'H',
|
20
|
+
province_of_birth: 'DF',
|
21
|
+
day_of_birth: '1999-08-28 00:00:00',
|
22
|
+
updated_at: '2019-10-03 13:12:32',
|
23
|
+
created_at: '2019-10-03 13:12:32',
|
24
|
+
id: 76
|
25
|
+
}
|
26
|
+
}
|
27
|
+
),
|
28
|
+
status: 200
|
29
|
+
)
|
30
|
+
|
31
|
+
curp_data = Xhash::DatabaseLookup.renapo(curp)
|
32
|
+
|
33
|
+
expect(curp_data).to be_a(Xhash::CURP)
|
34
|
+
expect(curp_data.name).to eq('JERONIMO')
|
35
|
+
expect(curp_data.last_name).to eq('OLIVA')
|
36
|
+
expect(curp_data.mothers_last_name).to eq('SANCHEZ')
|
37
|
+
expect(curp_data.day_of_birth).to eq('1999-08-28 00:00:00')
|
38
|
+
expect(curp_data.gender).to eq('H')
|
39
|
+
expect(curp_data.curp).to eq(curp)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'fails with invalid CURP' do
|
43
|
+
curp = 'JIQJ890611HDFXNN04'
|
44
|
+
|
45
|
+
stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
|
46
|
+
.to_return(
|
47
|
+
body:
|
48
|
+
JSON.dump(
|
49
|
+
{
|
50
|
+
result: true,
|
51
|
+
payload: {
|
52
|
+
id: 65,
|
53
|
+
curp: curp,
|
54
|
+
name: 'CURP INVALIDO',
|
55
|
+
last_name: '',
|
56
|
+
mothers_last_name: nil,
|
57
|
+
gender: 'H',
|
58
|
+
day_of_birth: nil,
|
59
|
+
country_of_birth: nil,
|
60
|
+
province_of_birth: nil,
|
61
|
+
proof_document_payload: nil,
|
62
|
+
proof_document_name: nil,
|
63
|
+
created_at: '2019-09-02 16:09:07',
|
64
|
+
updated_at: '2019-09-02 16:09:07'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
),
|
68
|
+
status: 200
|
69
|
+
)
|
70
|
+
|
71
|
+
begin
|
72
|
+
Xhash::DatabaseLookup.renapo(curp)
|
73
|
+
rescue => exception
|
74
|
+
expect(exception).to be_a(Xhash::InvalidFieldError)
|
75
|
+
expect(exception.message).to eq(Xhash::ErrorMessage::INVALID_CURP)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'fails with malformed CURP' do
|
80
|
+
curp = 'asdf'
|
81
|
+
|
82
|
+
stub_request(:post, 'https://xhash.dev/api/database-lookup/renapo')
|
83
|
+
.to_return(
|
84
|
+
body: JSON.dump({ result: false, payload: nil }), status: 200
|
85
|
+
)
|
86
|
+
|
87
|
+
begin
|
88
|
+
Xhash::DatabaseLookup.renapo(curp)
|
89
|
+
rescue => exception
|
90
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
91
|
+
expect(exception.message).to eq(Xhash::ErrorMessage::MISSING_CURP)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xhash::General do
|
4
|
+
describe '.store_data' do
|
5
|
+
it 'successfully creates a customer' do
|
6
|
+
stub_request(:post, 'https://xhash.dev/api/store-data').to_return(
|
7
|
+
body:
|
8
|
+
JSON.dump(
|
9
|
+
{
|
10
|
+
id: 1,
|
11
|
+
name: 'pedro',
|
12
|
+
last_name: 'can',
|
13
|
+
mothers_last_name: 'quintal',
|
14
|
+
birth_date: '1997-03-18 00:00:00',
|
15
|
+
rfc: 'JIQJ890611FC9',
|
16
|
+
curp: 'JIQJ890611HDFXNN04',
|
17
|
+
address: 'calle',
|
18
|
+
ext_address: 'asdfasdf',
|
19
|
+
gender: 'MALE',
|
20
|
+
clabe: '032180000118359719',
|
21
|
+
activity: '7129019',
|
22
|
+
email: 'emilio@xhash.tech',
|
23
|
+
phone_number: '9999503059',
|
24
|
+
zip_code: '97400',
|
25
|
+
external_customer_id: 'my-customer-id-1'
|
26
|
+
}
|
27
|
+
),
|
28
|
+
status: 200
|
29
|
+
)
|
30
|
+
|
31
|
+
customer =
|
32
|
+
Xhash::General.store_data(
|
33
|
+
name: 'pedro',
|
34
|
+
last_name: 'can',
|
35
|
+
mothers_last_name: 'quintal',
|
36
|
+
birth_date: '1997-03-18',
|
37
|
+
rfc: 'JIQJ890611FC9',
|
38
|
+
curp: 'JIQJ890611HDFXNN04',
|
39
|
+
address: 'calle',
|
40
|
+
ext_address: 'asdfasdf',
|
41
|
+
gender: 'MALE',
|
42
|
+
clabe: '032180000118359719',
|
43
|
+
activity: '7129019',
|
44
|
+
email: 'emilio@xhash.tech',
|
45
|
+
phone_number: '9999503059',
|
46
|
+
zip_code: '97400',
|
47
|
+
external_customer_id: 'my-customer-id-1'
|
48
|
+
)
|
49
|
+
|
50
|
+
expect(customer).to be_a(Xhash::Customer)
|
51
|
+
expect(customer.id).to be_truthy
|
52
|
+
expect(customer.name).to eq('pedro')
|
53
|
+
expect(customer.last_name).to eq('can')
|
54
|
+
expect(customer.mothers_last_name).to eq('quintal')
|
55
|
+
expect(customer.birth_date).to eq('1997-03-18 00:00:00')
|
56
|
+
expect(customer.gender).to eq('MALE')
|
57
|
+
expect(customer.curp).to eq('JIQJ890611HDFXNN04')
|
58
|
+
expect(customer.rfc).to eq('JIQJ890611FC9')
|
59
|
+
expect(customer.email).to eq('emilio@xhash.tech')
|
60
|
+
expect(customer.external_customer_id).to eq('my-customer-id-1')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'fails to creates a customer by missing data' do
|
64
|
+
stub_request(:post, 'https://xhash.dev/api/store-data').to_return(
|
65
|
+
body:
|
66
|
+
JSON.dump(
|
67
|
+
{
|
68
|
+
curp: ['The curp field is required.'],
|
69
|
+
gender: ['The gender field is required.']
|
70
|
+
}
|
71
|
+
),
|
72
|
+
status: 200
|
73
|
+
)
|
74
|
+
|
75
|
+
begin
|
76
|
+
customer =
|
77
|
+
Xhash::General.store_data(
|
78
|
+
name: 'pedro',
|
79
|
+
last_name: 'can',
|
80
|
+
mothers_last_name: 'quintal',
|
81
|
+
birth_date: '1997-03-18',
|
82
|
+
rfc: 'JIQJ890611FC9',
|
83
|
+
address: 'calle',
|
84
|
+
ext_address: 'asdfasdf',
|
85
|
+
clabe: '032180000118359719',
|
86
|
+
activity: '7129019',
|
87
|
+
email: 'emilio@xhash.tech',
|
88
|
+
phone_number: '9999503059',
|
89
|
+
zip_code: '97400',
|
90
|
+
external_customer_id: 'my-customer-id-1'
|
91
|
+
)
|
92
|
+
rescue => exception
|
93
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
94
|
+
expect(exception.message).to eq(
|
95
|
+
'The curp field is required. The gender field is required.'
|
96
|
+
)
|
97
|
+
expect(exception.response[:curp]).to eq(['The curp field is required.'])
|
98
|
+
expect(exception.response[:gender]).to eq(
|
99
|
+
['The gender field is required.']
|
100
|
+
)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '.get_customer' do
|
106
|
+
it 'successfully fetch customer data' do
|
107
|
+
stub_request(:get, 'https://xhash.dev/api/get-customer/my-customer-id-1')
|
108
|
+
.to_return(
|
109
|
+
body:
|
110
|
+
JSON.dump(
|
111
|
+
{
|
112
|
+
payload: {
|
113
|
+
id: 1,
|
114
|
+
name: 'pedro',
|
115
|
+
last_name: 'can',
|
116
|
+
mothers_last_name: 'quintal',
|
117
|
+
birth_date: '1997-03-18 00:00:00',
|
118
|
+
rfc: 'JIQJ890611FC9',
|
119
|
+
curp: 'JIQJ890611HDFXNN04',
|
120
|
+
address: 'calle',
|
121
|
+
ext_address: 'asdfasdf',
|
122
|
+
gender: 'MALE',
|
123
|
+
clabe: '032180000118359719',
|
124
|
+
activity: '7129019',
|
125
|
+
email: 'emilio@xhash.tech',
|
126
|
+
phone_number: '9999503059',
|
127
|
+
zip_code: '97400',
|
128
|
+
external_customer_id: 'my-customer-id-1'
|
129
|
+
}
|
130
|
+
}
|
131
|
+
),
|
132
|
+
status: 200
|
133
|
+
)
|
134
|
+
|
135
|
+
customer = Xhash::General.get_customer(customer_id: 'my-customer-id-1')
|
136
|
+
|
137
|
+
expect(customer).to be_a(Xhash::Customer)
|
138
|
+
expect(customer.id).to be_truthy
|
139
|
+
expect(customer.name).to eq('pedro')
|
140
|
+
expect(customer.external_customer_id).to eq('my-customer-id-1')
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'fails to fetch a customer data with bad id' do
|
144
|
+
stub_request(:get, 'https://xhash.dev/api/get-customer/my-customer-id-2')
|
145
|
+
.to_return(
|
146
|
+
body:
|
147
|
+
JSON.dump({ customer_id: ['The selected customer id is invalid.'] }),
|
148
|
+
status: 200
|
149
|
+
)
|
150
|
+
|
151
|
+
begin
|
152
|
+
customer = Xhash::General.get_customer(customer_id: 'my-customer-id-2')
|
153
|
+
rescue => exception
|
154
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
155
|
+
expect(exception.message).to eq('The selected customer id is invalid.')
|
156
|
+
expect(exception.response[:customer_id]).to eq(
|
157
|
+
['The selected customer id is invalid.']
|
158
|
+
)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '.store_file' do
|
164
|
+
it 'successfully store file to a customer' do
|
165
|
+
stub_request(:post, 'https://xhash.dev/api/store-file').to_return(
|
166
|
+
body: 'Image stored', status: 200
|
167
|
+
)
|
168
|
+
|
169
|
+
document = File.open('spec/files/ife_front.png')
|
170
|
+
|
171
|
+
response =
|
172
|
+
Xhash::General.store_file(
|
173
|
+
customer_id: 'my-customer-id-1',
|
174
|
+
document_type: Xhash::DocumentType::ID::INE_FRONT,
|
175
|
+
document: document
|
176
|
+
)
|
177
|
+
|
178
|
+
document.close
|
179
|
+
expect(response).to eq('Image stored')
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'fails store file to unexisting user' do
|
183
|
+
stub_request(:post, 'https://xhash.dev/api/store-file').to_return(
|
184
|
+
body:
|
185
|
+
JSON.dump({ customer_id: ['The selected customer id is invalid.'] }),
|
186
|
+
status: 200
|
187
|
+
)
|
188
|
+
|
189
|
+
document = File.open('spec/files/ife_front.png')
|
190
|
+
|
191
|
+
begin
|
192
|
+
response =
|
193
|
+
Xhash::General.store_file(
|
194
|
+
customer_id: 'my-customer-id-1',
|
195
|
+
document_type: Xhash::DocumentType::ID::INE_FRONT,
|
196
|
+
document: document
|
197
|
+
)
|
198
|
+
rescue => exception
|
199
|
+
document.close
|
200
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
201
|
+
expect(exception.message).to eq('The selected customer id is invalid.')
|
202
|
+
expect(exception.response[:customer_id]).to eq(
|
203
|
+
['The selected customer id is invalid.']
|
204
|
+
)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,365 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xhash::OCR do
|
4
|
+
describe '.generic' do
|
5
|
+
it 'successfully serialize INE to document by url' do
|
6
|
+
stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
|
7
|
+
body:
|
8
|
+
JSON.dump(
|
9
|
+
{
|
10
|
+
payload: {
|
11
|
+
name: 'MARGARITA',
|
12
|
+
last_name: 'GOMEZ',
|
13
|
+
mothers_last_name: 'VELAZQUEZ',
|
14
|
+
expiration_date: '2024-12-31',
|
15
|
+
street: 'C',
|
16
|
+
neighborhood: 'NACIO PITAGORAS 1253',
|
17
|
+
zip_code: 'INT 4',
|
18
|
+
city: 'COL. MORELOS 04800',
|
19
|
+
type: 'INE'
|
20
|
+
}
|
21
|
+
}
|
22
|
+
),
|
23
|
+
status: 200
|
24
|
+
)
|
25
|
+
|
26
|
+
ine =
|
27
|
+
Xhash::OCR.generic(
|
28
|
+
document_url:
|
29
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
|
30
|
+
)
|
31
|
+
|
32
|
+
expect(ine).to be_a(Xhash::Identification)
|
33
|
+
expect(ine.name).to eq('MARGARITA')
|
34
|
+
expect(ine.last_name).to eq('GOMEZ')
|
35
|
+
expect(ine.mothers_last_name).to eq('VELAZQUEZ')
|
36
|
+
expect(ine.expiration_date).to eq('2024-12-31')
|
37
|
+
expect(ine.street).to eq('C')
|
38
|
+
expect(ine.neighborhood).to eq('NACIO PITAGORAS 1253')
|
39
|
+
expect(ine.zip_code).to eq('INT 4')
|
40
|
+
expect(ine.city).to eq('COL. MORELOS 04800')
|
41
|
+
expect(ine.type).to eq('INE')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'successfully serialize INE to document by file' do
|
45
|
+
stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
|
46
|
+
body:
|
47
|
+
JSON.dump(
|
48
|
+
{
|
49
|
+
payload: {
|
50
|
+
name: 'MARGARITA',
|
51
|
+
last_name: 'GOMEZ',
|
52
|
+
mothers_last_name: 'VELAZQUEZ',
|
53
|
+
expiration_date: '2024-12-31',
|
54
|
+
street: 'C',
|
55
|
+
neighborhood: 'NACIO PITAGORAS 1253',
|
56
|
+
zip_code: 'INT 4',
|
57
|
+
city: 'COL. MORELOS 04800',
|
58
|
+
type: 'INE'
|
59
|
+
}
|
60
|
+
}
|
61
|
+
),
|
62
|
+
status: 200
|
63
|
+
)
|
64
|
+
|
65
|
+
document = File.open('spec/files/ife_front.png')
|
66
|
+
|
67
|
+
ine = Xhash::OCR.generic(document_file: document)
|
68
|
+
|
69
|
+
document.close
|
70
|
+
|
71
|
+
expect(ine).to be_a(Xhash::Identification)
|
72
|
+
expect(ine.name).to eq('MARGARITA')
|
73
|
+
expect(ine.last_name).to eq('GOMEZ')
|
74
|
+
expect(ine.mothers_last_name).to eq('VELAZQUEZ')
|
75
|
+
expect(ine.expiration_date).to eq('2024-12-31')
|
76
|
+
expect(ine.street).to eq('C')
|
77
|
+
expect(ine.neighborhood).to eq('NACIO PITAGORAS 1253')
|
78
|
+
expect(ine.zip_code).to eq('INT 4')
|
79
|
+
expect(ine.city).to eq('COL. MORELOS 04800')
|
80
|
+
expect(ine.type).to eq('INE')
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'successfully serialize proof of address to document by url' do
|
84
|
+
stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
|
85
|
+
body:
|
86
|
+
JSON.dump(
|
87
|
+
{
|
88
|
+
payload: {
|
89
|
+
full_name: 'Prof Francesco Reichert',
|
90
|
+
neighborhood: 'Parkerchester',
|
91
|
+
full_address: 'CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111',
|
92
|
+
zip_code: '97302',
|
93
|
+
province: 'Port Rosemarieview,VT',
|
94
|
+
date: '2019-09-01',
|
95
|
+
type: 'TELMEX'
|
96
|
+
}
|
97
|
+
}
|
98
|
+
),
|
99
|
+
status: 200
|
100
|
+
)
|
101
|
+
|
102
|
+
proof_of_address =
|
103
|
+
Xhash::OCR.generic(
|
104
|
+
document_url:
|
105
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/c7d40899ab9ed7aa689837e39b64a6eb07117353f88ce3f8b9d1ca73bea3d80e.png'
|
106
|
+
)
|
107
|
+
|
108
|
+
expect(proof_of_address).to be_a(Xhash::ProofOfAddress)
|
109
|
+
expect(proof_of_address.full_name).to eq('Prof Francesco Reichert')
|
110
|
+
expect(proof_of_address.neighborhood).to eq('Parkerchester')
|
111
|
+
expect(proof_of_address.province).to eq('Port Rosemarieview,VT')
|
112
|
+
expect(proof_of_address.type).to eq('TELMEX')
|
113
|
+
expect(proof_of_address.date).to eq('2019-09-01')
|
114
|
+
expect(proof_of_address.zip_code).to eq('97302')
|
115
|
+
expect(proof_of_address.full_address).to eq('CLL 59 E DIAGONAL 623\n76 Y 74 A Y RED CANALIZA\nLAS AMERICAS\nMERIDA, MERIDA YU\nC.P. 97302-CR -97111')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'successfully serialize proof of address to document by file' do
|
119
|
+
stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
|
120
|
+
body:
|
121
|
+
JSON.dump(
|
122
|
+
{
|
123
|
+
payload: {
|
124
|
+
full_name: 'Prof Francesco Reichert',
|
125
|
+
neighborhood: 'Parkerchester',
|
126
|
+
province: 'Port Rosemarieview,VT',
|
127
|
+
type: 'TELMEX'
|
128
|
+
}
|
129
|
+
}
|
130
|
+
),
|
131
|
+
status: 200
|
132
|
+
)
|
133
|
+
|
134
|
+
document = File.open('spec/files/telmex.png')
|
135
|
+
|
136
|
+
proof_of_address = Xhash::OCR.generic(document_file: document)
|
137
|
+
|
138
|
+
document.close
|
139
|
+
|
140
|
+
expect(proof_of_address).to be_a(Xhash::ProofOfAddress)
|
141
|
+
expect(proof_of_address.full_name).to eq('Prof Francesco Reichert')
|
142
|
+
expect(proof_of_address.neighborhood).to eq('Parkerchester')
|
143
|
+
expect(proof_of_address.province).to eq('Port Rosemarieview,VT')
|
144
|
+
expect(proof_of_address.type).to eq('TELMEX')
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'fails to serialize INE to document with html error' do
|
148
|
+
stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
|
149
|
+
body: '<p>error</p>',
|
150
|
+
status: 200,
|
151
|
+
headers: { 'Content-Type' => 'text/html; charset=UTF-8' }
|
152
|
+
)
|
153
|
+
|
154
|
+
begin
|
155
|
+
ine =
|
156
|
+
Xhash::OCR.generic(
|
157
|
+
document_url:
|
158
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
|
159
|
+
)
|
160
|
+
rescue => exception
|
161
|
+
expect(exception).to be_a(JSON::ParserError)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'fails with missing file or url' do
|
166
|
+
begin
|
167
|
+
ine = Xhash::OCR.generic
|
168
|
+
rescue => exception
|
169
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
170
|
+
expect(exception.message).to eq(Xhash::ErrorMessage::MISSING_FILE)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe '.identification' do
|
176
|
+
it 'successfully serialize INE to document' do
|
177
|
+
stub_request(:post, 'https://xhash.dev/api/ocr/identification').to_return(
|
178
|
+
body:
|
179
|
+
JSON.dump(
|
180
|
+
{
|
181
|
+
payload: {
|
182
|
+
name: 'MARGARITA',
|
183
|
+
last_name: 'GOMEZ',
|
184
|
+
mothers_last_name: 'VELAZQUEZ',
|
185
|
+
expiration_date: '2024-12-31',
|
186
|
+
street: 'C',
|
187
|
+
neighborhood: 'NACIO PITAGORAS 1253',
|
188
|
+
zip_code: 'INT 4',
|
189
|
+
city: 'COL. MORELOS 04800',
|
190
|
+
type: 'INE'
|
191
|
+
}
|
192
|
+
}
|
193
|
+
),
|
194
|
+
status: 200
|
195
|
+
)
|
196
|
+
|
197
|
+
ine_anverse =
|
198
|
+
Xhash::OCR.identification(
|
199
|
+
document_url:
|
200
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
|
201
|
+
)
|
202
|
+
|
203
|
+
expect(ine_anverse).to be_a(Xhash::Identification)
|
204
|
+
expect(ine_anverse.name).to eq('MARGARITA')
|
205
|
+
expect(ine_anverse.last_name).to eq('GOMEZ')
|
206
|
+
expect(ine_anverse.mothers_last_name).to eq('VELAZQUEZ')
|
207
|
+
expect(ine_anverse.expiration_date).to eq('2024-12-31')
|
208
|
+
expect(ine_anverse.street).to eq('C')
|
209
|
+
expect(ine_anverse.neighborhood).to eq('NACIO PITAGORAS 1253')
|
210
|
+
expect(ine_anverse.zip_code).to eq('INT 4')
|
211
|
+
expect(ine_anverse.city).to eq('COL. MORELOS 04800')
|
212
|
+
expect(ine_anverse.type).to eq('INE')
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'fails with missing file or url' do
|
216
|
+
begin
|
217
|
+
ine = Xhash::OCR.identification
|
218
|
+
rescue => exception
|
219
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'fails with invalid INE document' do
|
224
|
+
stub_request(:post, 'https://xhash.dev/api/ocr').to_return(
|
225
|
+
body: JSON.dump({ result: false, payload: nil }), status: 200
|
226
|
+
)
|
227
|
+
|
228
|
+
begin
|
229
|
+
ine =
|
230
|
+
Xhash::OCR.generic(
|
231
|
+
document_url:
|
232
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
|
233
|
+
)
|
234
|
+
rescue => exception
|
235
|
+
expect(exception).to be_a(Xhash::InvalidFieldError)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe '.proof_of_address' do
|
241
|
+
it 'successfully serialize proof of address to document' do
|
242
|
+
stub_request(:post, 'https://xhash.dev/api/ocr/proof-of-address')
|
243
|
+
.to_return(
|
244
|
+
body:
|
245
|
+
JSON.dump(
|
246
|
+
{
|
247
|
+
payload: {
|
248
|
+
full_name: 'Prof Francesco Reichert',
|
249
|
+
neighborhood: 'Parkerchester',
|
250
|
+
province: 'Port Rosemarieview,VT',
|
251
|
+
type: 'TELMEX'
|
252
|
+
}
|
253
|
+
}
|
254
|
+
),
|
255
|
+
status: 200
|
256
|
+
)
|
257
|
+
|
258
|
+
proof_of_address =
|
259
|
+
Xhash::OCR.proof_of_address(
|
260
|
+
document_url:
|
261
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/c7d40899ab9ed7aa689837e39b64a6eb07117353f88ce3f8b9d1ca73bea3d80e.png'
|
262
|
+
)
|
263
|
+
|
264
|
+
expect(proof_of_address).to be_a(Xhash::ProofOfAddress)
|
265
|
+
expect(proof_of_address.full_name).to eq('Prof Francesco Reichert')
|
266
|
+
expect(proof_of_address.neighborhood).to eq('Parkerchester')
|
267
|
+
expect(proof_of_address.province).to eq('Port Rosemarieview,VT')
|
268
|
+
expect(proof_of_address.type).to eq('TELMEX')
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'fails with missing file or url' do
|
272
|
+
begin
|
273
|
+
proof_of_address = Xhash::OCR.proof_of_address
|
274
|
+
rescue => exception
|
275
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'fails with invalid proof of address document' do
|
280
|
+
stub_request(:post, 'https://xhash.dev/api/ocr/proof-of-address')
|
281
|
+
.to_return(
|
282
|
+
body: JSON.dump({ result: false, payload: nil }), status: 200
|
283
|
+
)
|
284
|
+
|
285
|
+
begin
|
286
|
+
ine =
|
287
|
+
Xhash::OCR.proof_of_address(
|
288
|
+
document_url:
|
289
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
|
290
|
+
)
|
291
|
+
rescue => exception
|
292
|
+
expect(exception).to be_a(Xhash::InvalidFieldError)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe '.ine_reverse' do
|
298
|
+
it 'successfully serialize INE (reverse) to document' do
|
299
|
+
stub_request(:post, 'https://xhash.dev/api/ocr/ine-reverse').to_return(
|
300
|
+
body:
|
301
|
+
JSON.dump(
|
302
|
+
{
|
303
|
+
is_consistentent: false,
|
304
|
+
payload: {
|
305
|
+
lines: [
|
306
|
+
'IDMEX1836577170<<0747116375842',
|
307
|
+
'8007057M1812315MEX<02<<12345<7',
|
308
|
+
'GOMEZ<VELAZzQUEZ<<MARGARITA<',
|
309
|
+
''
|
310
|
+
],
|
311
|
+
cic: '183657717',
|
312
|
+
cic_digit_check: '0',
|
313
|
+
is_cic_digit_check_consistent: false,
|
314
|
+
section_and_consecutive: '0747116375842',
|
315
|
+
date: '800705',
|
316
|
+
date_check_digit: '7',
|
317
|
+
gender: 'M',
|
318
|
+
expiration_date: '181231',
|
319
|
+
expiration_date_digit: '5',
|
320
|
+
nationality: 'MEX',
|
321
|
+
emission_and_fuar: '02-12345',
|
322
|
+
name: 'MARGARITA ',
|
323
|
+
mothers_last_name: 'VELAZzQUEZ',
|
324
|
+
last_name: 'GOMEZ',
|
325
|
+
last_names: 'GOMEZ VELAZzQUEZ'
|
326
|
+
}
|
327
|
+
}
|
328
|
+
),
|
329
|
+
status: 200
|
330
|
+
)
|
331
|
+
|
332
|
+
ine_reverse =
|
333
|
+
Xhash::OCR.ine_reverse(
|
334
|
+
document_url:
|
335
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/b3f43a31929437c35b8fb22580119fe389d2e758bad8718387701ee8363caee7.jpg'
|
336
|
+
)
|
337
|
+
|
338
|
+
expect(ine_reverse).to be_a(Xhash::Identification)
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'fails with missing file or url' do
|
342
|
+
begin
|
343
|
+
ine_reverse = Xhash::OCR.ine_reverse
|
344
|
+
rescue => exception
|
345
|
+
expect(exception).to be_a(Xhash::MissingRequiredFieldError)
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'fails with invalid INE reverse document' do
|
350
|
+
stub_request(:post, 'https://xhash.dev/api/ocr/ine-reverse').to_return(
|
351
|
+
body: JSON.dump({ result: false, payload: nil }), status: 200
|
352
|
+
)
|
353
|
+
|
354
|
+
begin
|
355
|
+
ine =
|
356
|
+
Xhash::OCR.ine_reverse(
|
357
|
+
document_url:
|
358
|
+
'https://kyc-xhash.s3-us-west-2.amazonaws.com/documents/7cd6994d9ad52e8943be1ae00bac60c461430cdf2af6159afa4b9be749706472.png'
|
359
|
+
)
|
360
|
+
rescue => exception
|
361
|
+
expect(exception).to be_a(Xhash::InvalidFieldError)
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|