From eaa95565971526d85be976786340bca431e5c125 Mon Sep 17 00:00:00 2001 From: Luca Vandro Date: Wed, 17 Feb 2021 10:45:00 +0100 Subject: [PATCH] Fixed bug #58 --- package.json | 2 +- src/codice-fiscale.js | 4 ++-- tests/index.spec.js | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 60e6a56..350b094 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codice-fiscale-js", - "version": "2.3.7", + "version": "2.3.8", "description": "The Italian Tax Code Library for Javascript and Typescript", "main": "dist/codice.fiscale.commonjs2.js", "types": "types/codice-fiscale.d.ts", diff --git a/src/codice-fiscale.js b/src/codice-fiscale.js index bc4544a..b70c94f 100755 --- a/src/codice-fiscale.js +++ b/src/codice-fiscale.js @@ -154,8 +154,8 @@ class CodiceFiscale { } omocodie () { const results = [] - let lastOmocode = (this.code = this.code.slice(0, 15)) - for (let i = this.code.length - 1; i >= 0; i = i - 1) { + let lastOmocode = (this.code.slice(0, 15)) + for (let i = this.code.length - 1; i >= 0; i--) { const char = this.code[i] if (char.match(/\d/) !== null) { lastOmocode = `${lastOmocode.substr(0, i)}${OMOCODIA_TABLE[char]}${lastOmocode.substr(i + 1)}` diff --git a/tests/index.spec.js b/tests/index.spec.js index 551ee12..cdd3cbd 100755 --- a/tests/index.spec.js +++ b/tests/index.spec.js @@ -441,5 +441,23 @@ describe("La classe Comune", ()=>{ let bz = new Comune("Bolzano", "BZ") expect(bz.nome).toEqual('BOLZANO') + }) +}) + + +describe("Il metodo toString()", ()=>{ + test("funziona correttamente anche con le omocodie", ()=>{ + let cf = new CodiceFiscale({ + name: "Mario", + surname: "Rossi", + gender: "M", + birthday: "1987-02-01", + birthplace: "H501" + }); + + expect(cf.toString()).toBe("RSSMRA87B01H501A"); + cf.omocodie(); + expect(cf.toString()).toBe("RSSMRA87B01H501A"); + }) }) \ No newline at end of file