<commit_before>assert = require('assert')
window = require('jsdom').jsdom().defaultView

global.window = window
global.document = window.document

Payment = require('../src/payment')
QJ = require('qj')

describe 'payment', ->
  describe 'Validating a card number', ->
    it 'should fail if empty', ->
      topic = Payment.fns.validateCardNumber ''
      assert.equal topic, false

    it 'should fail if is a bunch of spaces', ->
      topic = Payment.fns.validateCardNumber '                 '
      assert.equal topic, false

    it 'should success if is valid', ->
      topic = Payment.fns.validateCardNumber '4242424242424242'
      assert.equal topic, true

    it 'that has dashes in it but is valid', ->
      topic = Payment.fns.validateCardNumber '4242-4242-4242-4242'
      assert.equal topic, true

    it 'should succeed if it has spaces in it but is valid', ->
      topic = Payment.fns.validateCardNumber '4242 4242 4242 4242'
      assert.equal topic, true

    it 'that does not pass the luhn checker', ->
      topic = Payment.fns.validateCardNumber '4242424242424241'
      assert.equal topic, false

    it 'should fail if is more than 16 digits', ->
      topic = Payment.fns.validateCardNumber '42424242424242424'
      assert.equal topic, false

    it 'should fail if is less than 10 digits', ->
      topic = Payment.fns.validateCardNumber '424242424'
      assert.equal topic, false

    it 'should fail with non-digits', ->
      topic = Payment.fns.validateCardNumber '4242424e42424241'
      assert.equal topic, false

    it 'should validate for all card types', ->
      assert(Payment.fns.validateCardNumber('378282246310005'), 'amex')
      assert(Payment.fns.validateCardNumber('371449635398431'), 'amex')
      assert(Payment.fns.validateCardNumber('378734493671000'), 'amex')

      assert(Payment.fns.validateCardNumber('5019123456789013'), 'dankort')

      assert(Payment.fns.validateCardNumber('30569309025904'), 'dinersclub')
      assert(Payment.fns.validateCardNumber('38520000023237'), 'dinersclub')

      assert(Payment.fns.validateCardNumber('6011111111111117'), 'discover')
      assert(Payment.fns.validateCardNumber('6011000990139424'), 'discover')

      assert(Payment.fns.validateCardNumber('3530111333300000'), 'jcb')
      assert(Payment.fns.validateCardNumber('3566002020360505'), 'jcb')

      assert(Payment.fns.validateCardNumber('5555555555554444'), 'mastercard')

      assert(Payment.fns.validateCardNumber('4111111111111111'), 'visa')
      assert(Payment.fns.validateCardNumber('4012888888881881'), 'visa')
      assert(Payment.fns.validateCardNumber('4222222222222'), 'visa')

      assert(Payment.fns.validateCardNumber('4917300800000000'), 'visaelectron')

      assert(Payment.fns.validateCardNumber('6759649826438453'), 'maestro')

      assert(Payment.fns.validateCardNumber('6271136264806203568'), 'unionpay')
      assert(Payment.fns.validateCardNumber('6236265930072952775'), 'unionpay')
      assert(Payment.fns.validateCardNumber('6204679475679144515'), 'unionpay')
      assert(Payment.fns.validateCardNumber('6216657720782466507'), 'unionpay')

  describe 'Validating a CVC', ->
    it 'should fail if is empty', ->
      topic = Payment.fns.validateCardCVC ''
      assert.equal topic, false

    it 'should pass if is valid', ->
      topic = Payment.fns.validateCardCVC '123'
      assert.equal topic, true

    it 'should fail with non-digits', ->
      topic = Payment.fns.validateCardNumber '12e'
      assert.equal topic, false

    it 'should fail with less than 3 digits', ->
      topic = Payment.fns.validateCardNumber '12'
      assert.equal topic, false

    it 'should fail with more than 4 digits', ->
      topic = Payment.fns.validateCardNumber '12345'
      assert.equal topic, false

  describe 'Validating an expiration date', -><commit_msg>test(card-type): reorganize card type tests<commit_after>assert = require('assert')
window = require('jsdom').jsdom().defaultView

global.window = window
global.document = window.document

Payment = require('../src/payment')
QJ = require('qj')

describe 'payment', ->
  describe 'Validating a card number', ->
    it 'should fail if empty', ->
      topic = Payment.fns.validateCardNumber ''
      assert.equal topic, false

    it 'should fail if is a bunch of spaces', ->
      topic = Payment.fns.validateCardNumber '                 '
      assert.equal topic, false

    it 'should success if is valid', ->
      topic = Payment.fns.validateCardNumber '4242424242424242'
      assert.equal topic, true

    it 'that has dashes in it but is valid', ->
      topic = Payment.fns.validateCardNumber '4242-4242-4242-4242'
      assert.equal topic, true

    it 'should succeed if it has spaces in it but is valid', ->
      topic = Payment.fns.validateCardNumber '4242 4242 4242 4242'
      assert.equal topic, true

    it 'that does not pass the luhn checker', ->
      topic = Payment.fns.validateCardNumber '4242424242424241'
      assert.equal topic, false

    it 'should fail if is more than 16 digits', ->
      topic = Payment.fns.validateCardNumber '42424242424242424'
      assert.equal topic, false

    it 'should fail if is less than 10 digits', ->
      topic = Payment.fns.validateCardNumber '424242424'
      assert.equal topic, false

    it 'should fail with non-digits', ->
      topic = Payment.fns.validateCardNumber '4242424e42424241'
      assert.equal topic, false

  describe 'validating card types', ->
    it 'should validate amex card types', ->
      assert(Payment.fns.validateCardNumber('378282246310005'), 'amex')
      assert(Payment.fns.validateCardNumber('371449635398431'), 'amex')
      assert(Payment.fns.validateCardNumber('378734493671000'), 'amex')
    it 'should validate dankort card types', ->
      assert(Payment.fns.validateCardNumber('5019123456789013'), 'dankort')
    it 'should validate dinersclub card types', ->
      assert(Payment.fns.validateCardNumber('30569309025904'), 'dinersclub')
      assert(Payment.fns.validateCardNumber('38520000023237'), 'dinersclub')
    it 'should validate discover card types', ->
      assert(Payment.fns.validateCardNumber('6011111111111117'), 'discover')
      assert(Payment.fns.validateCardNumber('6011000990139424'), 'discover')
    it 'should validate jcb card types', ->
      assert(Payment.fns.validateCardNumber('3530111333300000'), 'jcb')
      assert(Payment.fns.validateCardNumber('3566002020360505'), 'jcb')
    it 'should validate mastercard card types', ->
      assert(Payment.fns.validateCardNumber('5555555555554444'), 'mastercard')
    it 'should validate visa card types', ->
      assert(Payment.fns.validateCardNumber('4111111111111111'), 'visa')
      assert(Payment.fns.validateCardNumber('4012888888881881'), 'visa')
      assert(Payment.fns.validateCardNumber('4222222222222'), 'visa')
      assert(Payment.fns.validateCardNumber('4000 0000 0000 0000 030'), 'visa')
    it 'should validate visaelectron card types', ->
      assert(Payment.fns.validateCardNumber('4917300800000000'), 'visaelectron')
    it 'should validate unionpay card types', ->
      assert(Payment.fns.validateCardNumber('6271136264806203568'), 'unionpay')
      assert(Payment.fns.validateCardNumber('6236265930072952775'), 'unionpay')
      assert(Payment.fns.validateCardNumber('6204679475679144515'), 'unionpay')
      assert(Payment.fns.validateCardNumber('6216657720782466507'), 'unionpay')
    it 'should validate maestro card types', ->
      assert(Payment.fns.validateCardNumber('6759649826438453'), 'maestro')
      assert(Payment.fns.validateCardNumber('6759 4111 0000 0008'), 'maestro')
      assert(Payment.fns.validateCardNumber('6759 6498 2643 8453'), 'maestro')

  describe 'Validating a CVC', ->
    it 'should fail if is empty', ->
      topic = Payment.fns.validateCardCVC ''
      assert.equal topic, false

    it 'should pass if is valid', ->
      topic = Payment.fns.validateCardCVC '123'
      assert.equal topic, true

    it 'should fail with non-digits', ->
      topic = Payment.fns.validateCardNumber '12e'
      assert.equal topic, false

    it 'should fail with less than 3 digits', ->
      topic = Payment.fns.validateCardNumber '12'
      assert.equal topic, false

    it 'should fail with more than 4 digits', ->
      topic = Payment.fns.validateCardNumber '12345'
      assert.equal topic, false

  describe 'Validating an expiration date', ->
{'fraction_non_alphanumeric': 0.11826934506121478, 'fraction_numerical': 0.1118507072387971, 'mean_word_length': 3.7058165548098434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 12, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '720207', 'n_tokens_mistral': 3154, 'n_tokens_neox': 2517, 'n_words': 605}