Permalink
Browse files

[test] Added test for the parse method

  • Loading branch information...
1 parent 6429ea7 commit fba32afe35e74dbfc9e82371ebea2acd8b02c193 @3rd-Eden 3rd-Eden committed Dec 1, 2012
Showing with 28 additions and 0 deletions.
  1. +2 −0 lib/creditcard.js
  2. +26 −0 test/creditcard.test.js
View
2 lib/creditcard.js
@@ -175,5 +175,7 @@ exports.parse = function parse(number) {
? 4 // American Express requires 4 digits
: 3 // All other credit cards
, pan: exports.pan(number) // PAN truncated version
+ , scheme: scheme // Creditcard scheme
+ , validates: exports.validate(number) // Does the creditcard validate
};
};
View
26 test/creditcard.test.js
@@ -67,3 +67,29 @@ describe('creditcard#pan', function () {
expect(creditcard.pan('4222222222222')).to.equal('XXXX XXXX X222 2');
});
});
+
+describe('creditcard#parse', function () {
+ it('should extract information', function () {
+ var data = creditcard.parse('4111111111111111');
+
+ expect(data).to.have.property('iin');
+ expect(data).to.have.property('mii');
+ expect(data).to.have.property('cvv');
+ expect(data).to.have.property('pan');
+ expect(data).to.have.property('scheme');
+ expect(data).to.have.property('formatted');
+ expect(data).to.have.property('validates');
+ });
+
+ it('should extract the correct information', function () {
+ var data = creditcard.parse('4111111111111111');
+
+ expect(data.iin).to.equal('411111111');
+ expect(data.mii).to.equal('Banking and financial');
+ expect(data.cvv).to.equal(3);
+ expect(data.pan).to.equal('XXXX XXXX XXXX 1111');
+ expect(data.scheme).to.equal('Visa');
+ expect(data.formatted).to.equal('4111 1111 1111 1111');
+ expect(data.validates).to.equal(true);
+ });
+});

0 comments on commit fba32af

Please sign in to comment.