Skip to content

Commit

Permalink
Fixing order of values in assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
omarshammas committed May 30, 2013
1 parent 3955a95 commit 4cc2039
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 112 deletions.
22 changes: 11 additions & 11 deletions test/fields/credit_card_cvc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,48 @@ describe 'credit_card_cvc.js', ->
describe 'Validating a CVC without credit card type', ->
it 'should fail if is empty', ->
topic = $.formance.validateCreditCardCVC ''
assert.equal topic, false
assert.equal false, topic

it 'should pass if is valid', ->
topic = $.formance.validateCreditCardCVC '123'
assert.equal topic, true
assert.equal true, topic

it 'should fail with non-digits', ->
topic = $.formance.validateCreditCardCVC '12e'
assert.equal topic, false
assert.equal false, topic

it 'should fail with less than 3 digits', ->
topic = $.formance.validateCreditCardCVC '12'
assert.equal topic, false
assert.equal false, topic

it 'should fail with more than 4 digits', ->
topic = $.formance.validateCreditCardCVC '12345'
assert.equal topic, false
assert.equal false, topic

describe 'Validating a CVC with credit card type', ->

it 'should validate a three digit number with no card type', ->
topic = $.formance.validateCreditCardCVC('123')
assert.equal topic, true
assert.equal true, topic

it 'should validate a three digit number with card type amex', ->
topic = $.formance.validateCreditCardCVC('123', 'amex')
assert.equal topic, true
assert.equal true, topic

it 'should validate a three digit number with card type other than amex', ->
topic = $.formance.validateCreditCardCVC('123', 'visa')
assert.equal topic, true
assert.equal true, topic

it 'should not validate a four digit number with a card type other than amex', ->
topic = $.formance.validateCreditCardCVC('1234', 'visa')
assert.equal topic, false
assert.equal false, topic

it 'should validate a four digit number with card type amex', ->
topic = $.formance.validateCreditCardCVC('1234', 'amex')
assert.equal topic, true
assert.equal true, topic

it 'should not validate a number larger than 4 digits', ->
topic = $.formance.validateCreditCardCVC('12344')
assert.equal topic, false
assert.equal false, topic


28 changes: 14 additions & 14 deletions test/fields/credit_card_expiry.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe 'credit_card_expiry.js', ->
e.which = 52 # '4'
$expiry.trigger(e)

assert.equal $expiry.val(), '04 / '
assert.equal '04 / ', $expiry.val()

it 'should format forward slash shorthand correctly', ->
$expiry = $('<input type=text>').formance('formatCreditCardExpiry')
Expand All @@ -29,7 +29,7 @@ describe 'credit_card_expiry.js', ->
e.which = 47 # '/'
$expiry.trigger(e)

assert.equal $expiry.val(), '01 / '
assert.equal '01 / ', $expiry.val()

it 'should only allow numbers', ->
$expiry = $('<input type=text>').formance('formatCreditCardExpiry')
Expand All @@ -39,55 +39,55 @@ describe 'credit_card_expiry.js', ->
e.which = 100 # 'd'
$expiry.trigger(e)

assert.equal $expiry.val(), '1'
assert.equal '1', $expiry.val()


describe 'Validating an expiration date', ->

it 'should fail expires is before the current year', ->
currentTime = new Date()
topic = $.formance.validateCreditCardExpiry currentTime.getMonth() + 1, currentTime.getFullYear() - 1
assert.equal topic, false
assert.equal false, topic

it 'that expires in the current year but before current month', ->
currentTime = new Date()
topic = $.formance.validateCreditCardExpiry currentTime.getMonth(), currentTime.getFullYear()
assert.equal topic, false
assert.equal false, topic

it 'that has an invalid month', ->
currentTime = new Date()
topic = $.formance.validateCreditCardExpiry 13, currentTime.getFullYear()
assert.equal topic, false
assert.equal false, topic

it 'that is this year and month', ->
currentTime = new Date()
topic = $.formance.validateCreditCardExpiry currentTime.getMonth() + 1, currentTime.getFullYear()
assert.equal topic, true
assert.equal true, topic

it 'that is just after this month', ->
# Remember - months start with 0 in JavaScript!
currentTime = new Date()
topic = $.formance.validateCreditCardExpiry currentTime.getMonth() + 1, currentTime.getFullYear()
assert.equal topic, true
assert.equal true, topic

it 'that is after this year', ->
currentTime = new Date()
topic = $.formance.validateCreditCardExpiry currentTime.getMonth() + 1, currentTime.getFullYear() + 1
assert.equal topic, true
assert.equal true, topic

it 'that has string numbers', ->
currentTime = new Date()
currentTime.setFullYear(currentTime.getFullYear() + 1, currentTime.getMonth() + 2)
topic = $.formance.validateCreditCardExpiry currentTime.getMonth() + '', currentTime.getFullYear() + ''
assert.equal topic, true
assert.equal true, topic

it 'that has non-numbers', ->
topic = $.formance.validateCreditCardExpiry 'h12', '3300'
assert.equal topic, false
assert.equal false, topic

it 'should fail if year or month is NaN', ->
topic = $.formance.validateCreditCardExpiry '12', NaN
assert.equal topic, false
assert.equal false, topic

it 'should support year shorthand', ->
assert.equal $.formance.validateCreditCardExpiry('05', '20'), true
Expand All @@ -98,11 +98,11 @@ describe 'credit_card_expiry.js', ->

it 'should parse string expiry', ->
topic = $.formance.creditCardExpiryVal('03 / 2025')
assert.deepEqual topic, month: 3, year: 2025
assert.deepEqual {month: 3, year: 2025}, topic

it 'should support shorthand year', ->
topic = $.formance.creditCardExpiryVal('05/04')
assert.deepEqual topic, month: 5, year: 2004
assert.deepEqual {month: 5, year: 2004}, topic

it 'should return NaN when it cannot parse', ->
topic = $.formance.creditCardExpiryVal('05/dd')
Expand Down
30 changes: 15 additions & 15 deletions test/fields/credit_card_number.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,46 @@ describe 'credit_card_number.js', ->
e.which = 52 # '4'
$number.trigger(e)

assert.equal $number.val(), '4242 4'
assert.equal '4242 4', $number.val()


describe 'Validating a card number', ->

it 'should fail if empty', ->
topic = $.formance.validateCreditCardNumber ''
assert.equal topic, false
assert.equal false, topic

it 'should fail if is a bunch of spaces', ->
topic = $.formance.validateCreditCardNumber ' '
assert.equal topic, false
assert.equal false, topic

it 'should success if is valid', ->
topic = $.formance.validateCreditCardNumber '4242424242424242'
assert.equal topic, true
assert.equal true, topic

it 'that has dashes in it but is valid', ->
topic = $.formance.validateCreditCardNumber '4242-4242-4242-4242'
assert.equal topic, true
assert.equal true, topic

it 'should succeed if it has spaces in it but is valid', ->
topic = $.formance.validateCreditCardNumber '4242 4242 4242 4242'
assert.equal topic, true
assert.equal true, topic

it 'that does not pass the luhn checker', ->
topic = $.formance.validateCreditCardNumber '4242424242424241'
assert.equal topic, false
assert.equal false, topic

it 'should fail if is more than 16 digits', ->
topic = $.formance.validateCreditCardNumber '42424242424242424'
assert.equal topic, false
assert.equal false, topic

it 'should fail if is less than 10 digits', ->
topic = $.formance.validateCreditCardNumber '424242424'
assert.equal topic, false
assert.equal false, topic

it 'should fail with non-digits', ->
topic = $.formance.validateCreditCardNumber '4242424e42424241'
assert.equal topic, false
assert.equal false, topic

it 'should validate for all card types', ->
assert($.formance.validateCreditCardNumber('378282246310005'), 'amex')
Expand Down Expand Up @@ -93,23 +93,23 @@ describe 'credit_card_number.js', ->

it 'should return Visa that begins with 40', ->
topic = $.formance.creditCardType '4012121212121212'
assert.equal topic, 'visa'
assert.equal 'visa', topic

it 'that begins with 5 should return MasterCard', ->
topic = $.formance.creditCardType '5555555555554444'
assert.equal topic, 'mastercard'
assert.equal 'mastercard', topic

it 'that begins with 34 should return American Express', ->
topic = $.formance.creditCardType '3412121212121212'
assert.equal topic, 'amex'
assert.equal 'amex', topic

it 'that is not numbers should return null', ->
topic = $.formance.creditCardType 'aoeu'
assert.equal topic, null
assert.equal null, topic

it 'that has unrecognized beginning numbers should return null', ->
topic = $.formance.creditCardType 'aoeu'
assert.equal topic, null
assert.equal null, topic

it 'should return correct type for all test numbers', ->
assert.equal($.formance.creditCardType('378282246310005'), 'amex')
Expand Down
Loading

0 comments on commit 4cc2039

Please sign in to comment.