test.js 5.8 KB

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