Fixed issue #37

This commit is contained in:
Luca Vandro 2020-07-17 00:37:12 +02:00
parent 4ef659187f
commit a23f104245
6 changed files with 49 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -80,7 +80,19 @@ export class Comune {
if (result.length === 1) {
return { cc: result[0][0], prov: result[0][1], nome: result[0][2] }
} else if (result.length > 1) {
throw new Error(`Comune with name of ${nome} is found in more than one province. Please specify the province code`)
for(let i=0; i < result.length; i++){
if (result[i][1]!=result[0][1]){
throw new Error(`Comune with name of ${nome} is found in more than one province. Please specify the province code`);
}
}
for(let i=0; i < result.length; i++){
if (result[i][3]==1){
return { cc: result[i][0], prov: result[i][1], nome: result[i][2] }
}
}
}
}
searchByNameAndProvince (nome, prov) {

View File

@ -362,6 +362,37 @@ describe('Calcolo del codice fiscale inverso',()=>{
test('funziona con i comuni che hanno cambiato provincia, restituendo la provincia a cui è assegnato attualmente il comune', () => {
expect(CodiceFiscale.reverse(maria_rossi_cf2).birthplace).toEqual('VIMERCATE');
expect(CodiceFiscale.reverse(maria_rossi_cf2).birthplaceProvincia).toEqual('MB');
})
});
describe('non rileva anomalie con il comune di Calendasco',()=>{
test('calcola il codice fiscale', () => {
expect(CodiceFiscale.compute({
name: 'Mario',
surname: 'Rossi',
gender: 'M',
day: 25,
month: 12,
year: 1980,
birthplace: 'Calendasco'
}))
.toBe('RSSMRA80T25B405Z')
})
test("e anche il codice fiscale inverso", () => {
let reverse = CodiceFiscale.reverse('RSSMRA80T25B405Z');
expect(reverse.name).toEqual('MRA');
expect(reverse.surname).toEqual('RSS');
expect(reverse.gender).toEqual('M');
expect(reverse.day).toEqual(25);
expect(reverse.month).toEqual(12);
expect(reverse.year).toEqual(1980);
expect(reverse.birthplace).toEqual('CALENDASCO');
expect(reverse.birthplaceProvincia).toEqual('PC');
});
});
})