forked from navyxie/bankcardinfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
202 lines (202 loc) · 6.02 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var should = require('should');
var BCI = require('./index');
var async = require('async');
describe('#getBankInfoByCardNo()', function() {
this.timeout(50000);
it('test PSBC card', function(done) {
BCI.getBankBin('6228108888888888', function(err, data) {
should.not.exist(err);
data.cardType.should.be.equal('CC');
done();
});
});
it('test PSBC card', function(done) {
BCI.getBankBin('6228108888888888', function(err, data) {
should.not.exist(err);
data.cardType.should.be.equal('CC');
done();
});
});
it('test ICBC card', function(done) {
BCI.getBankBin('624000888888888888', function(err, data) {
should.not.exist(err);
data.bankCode.should.be.equal('ICBC');
done();
});
});
it('test ICBC card', function(done) {
BCI.getBankBin('370248888888888', function(err, data) {
should.not.exist(err);
data.cardType.should.be.equal('CC');
done();
});
});
it('test ABC card', function(done) {
BCI.getBankBin('6228278888888888888', function(err, data) {
should.not.exist(err);
data.bankCode.should.be.equal('ABC');
done();
});
});
it('test ABC card', function(done) {
BCI.getBankBin('5442438888888888', function(err, data) {
should.not.exist(err);
data.cardType.should.be.equal('CC');
done();
});
});
it('test BOC card', function(done) {
BCI.getBankBin('6222738888888888888', function(err, data) {
should.not.exist(err);
data.bankCode.should.be.equal('BOC');
done();
});
});
it('test BOC card', function(done) {
BCI.getBankBin('6253338888888888', function(err, data) {
should.not.exist(err);
data.cardType.should.be.equal('SCC');
done();
});
});
it('test CCB card', function(done) {
BCI.getBankBin('5264108888888888', function(err, data) {
should.not.exist(err);
data.bankCode.should.be.equal('CCB');
done();
});
});
it('test CCB card', function(done) {
BCI.getBankBin('554403388888888888', function(err, data) {
should.not.exist(err);
data.cardType.should.be.equal('CC');
done();
});
});
it('test CCB card async', function(done) {
BCI.getBankBin('6236688888888888888', function(err, data) {
should.not.exist(err);
data.bankCode.should.be.equal('CCB');
done();
})
})
it('test not a number card', function(done) {
BCI.getBankBin("test", function(err, data) {
err.should.not.be.ok;
done();
});
});
it('test Invalid card number', function(done) {
BCI.getBankBin('1234568749', function(err, data) {
err.should.not.be.ok;
done();
});
});
it('test BDCBANK', function(done) {
BCI.getBankBin('6210910002001951239', function(err, data) {
data.bankCode.should.be.equal('BDCBANK');
done();
});
});
it('test concurrent request', function(done) {
async.parallel([
function(callback) {
BCI.getBankBin('62270033202400375331', function(err, info) {
callback(null, {
err: err,
info: info
});
});
},
function(callback) {
BCI.getBankBin('6227003320240030000', function(err, info) {
callback(null, {
err: err,
info: info
});
});
},
function(callback) {
BCI.getBankBin('6111111111111111', function(err, info) {
callback(null, {
err: err,
info: info
});
});
},
function(callback) {
BCI.getBankBin('622700332024003', function(err, info) {
callback(null, {
err: err,
info: info
});
});
}
],
function(err, results) {
results[0].err.should.be.equal('62270033202400375331:银行卡位数必须是15到19位');
should.not.exist(results[1].err);
results[2].err.indexOf('6111111111111111:该银行卡不存在').should.not.be.equal(-1);
results[3].err.indexOf('622700332024003:该银行卡不存在').should.not.be.equal(-1);
done(null);
});
});
it('test promise api, ok', function(done) {
BCI.getBankBin('5264108888888888')
.then(function (data) {
data.bankCode.should.be.equal('CCB');
done();
})
});
it('test promise api, fail', function(done) {
BCI.getBankBin('1234568749')
.catch(function (err) {
err.should.not.be.ok;
done();
})
});
it('test concurrent request, promise api', function(done) {
async.parallel([
function(callback) {
BCI.getBankBin('62270033202400375331')
.catch(function (err) {
callback(null, {
err: err
});
})
},
function(callback) {
BCI.getBankBin('6227003320240030000')
.then(function (info) {
callback(null, {
err: null,
info: info
});
})
},
function(callback) {
BCI.getBankBin('6111111111111111')
.catch(function (err) {
callback(null, {
err: err
});
})
},
function(callback) {
BCI.getBankBin('622700332024003')
.catch(function (err) {
callback(null, {
err: err
});
})
}
],
function(err, results) {
results[0].err.should.be.equal('62270033202400375331:银行卡位数必须是15到19位');
should.not.exist(results[1].err);
results[2].err.indexOf('6111111111111111:该银行卡不存在').should.not.be.equal(-1);
results[3].err.indexOf('622700332024003:该银行卡不存在').should.not.be.equal(-1);
done(null);
});
});
})