const validateDni = require('../validateTin');

describe('TIN validation', () => {
    it('should return true for any TIN when no country is passed', () => {
        let isValid = validateDni('Pepinillos');

        expect(isValid).toBeTruthy();
    });

    describe('Spanish', () => {
        it('should return true for valid spanish TIN', () => {
            let isValid = validateDni('20849756A', 'es');

            expect(isValid).toBeTruthy();
        });

        it('should return false for spanish TIN with exceeded digits', () => {
            let isValid = validateDni('208497563239A', 'es');

            expect(isValid).toBeFalsy();
        });

        it('should return false for spanish TIN with invalid letter', () => {
            let isValid = validateDni('20243746E', 'es');

            expect(isValid).toBeFalsy();
        });

        it('should return true for valid spanish CIF', () => {
            let isValid = validateDni('B97367486', 'es');

            expect(isValid).toBeTruthy();
        });

        it('should return false for spanish CIF with invalid letter', () => {
            let isValid = validateDni('A97527786', 'es');

            expect(isValid).toBeFalsy();
        });
    });

    describe('Italian', () => {
        it('should return true for valid italian TIN', () => {
            let isValid = validateDni('12345678911', 'it');

            expect(isValid).toBeTruthy();
        });

        it('should return false for italian TIN with exceeded digits', () => {
            let isValid = validateDni('123456789112', 'it');

            expect(isValid).toBeFalsy();
        });

        it('should return false for italian TIN with bad syntax', () => {
            let isValid = validateDni('1234567891A', 'it');

            expect(isValid).toBeFalsy();
        });
    });

    describe('Portuguese', () => {
        it('should return true for valid portuguese TIN', () => {
            let isValid = validateDni('123456789', 'pt');

            expect(isValid).toBeTruthy();
        });

        it('should return false for portuguese TIN with exceeded digits', () => {
            let isValid = validateDni('12345678910', 'pt');

            expect(isValid).toBeFalsy();
        });

        it('should return false for portuguese TIN with bad syntax', () => {
            let isValid = validateDni('12345678A', 'pt');

            expect(isValid).toBeFalsy();
        });
    });
});