Compute works with json object as param

This commit is contained in:
Valentina Vandro 2017-09-05 23:56:46 +02:00
parent e1e19be4a3
commit 5dd0e290bc
6 changed files with 35 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@
"scripts": { "scripts": {
"build": "webpack", "build": "webpack",
"pretest": "npm run build", "pretest": "npm run build",
"test": "karma start" "test": "npm run build && karma start"
}, },
"author": "Luca Vandro <lucavandro@gmail.com>", "author": "Luca Vandro <lucavandro@gmail.com>",
"contributors": [ "contributors": [

View File

@ -3,7 +3,24 @@ const catastalCodes = require('./catastal-codes.json')
var CodiceFiscale={} var CodiceFiscale={}
CodiceFiscale.compute=function(name,surname,gender,day,month,year,birthplace, birthplace_provincia){ CodiceFiscale.compute=function(name,surname,gender,day,month,year,birthplace, birthplace_provincia){
// Pass an object as parameter
if(
typeof name == 'object'
){
console.log(JSON.stringify(name));
var params = name;
name = params['name'],
surname = params['surname'],
gender = params['gender'],
day = params['day'],
month = params['month'],
year = params['year'],
birthplace = params['birthplace'],
birthplace_provincia = params['birthplace_provincia'];
}
var code= var code=
this.surnameCode(surname)+ this.surnameCode(surname)+
this.nameCode(name)+ this.nameCode(name)+

View File

@ -9,10 +9,23 @@ describe("CodiceFiscale.compute", function() {
expect(CodiceFiscale.compute).not.toBe(undefined); expect(CodiceFiscale.compute).not.toBe(undefined);
}); });
it("compute il codice fiscale", function() { it("calcola il codice fiscale", function() {
expect(CodiceFiscale.compute("Luca", "Moreno",'M', 1, 1, 2000, "Roma", "RM")).toBe("MRNLCU00A01H501J"); expect(CodiceFiscale.compute("Luca", "Moreno",'M', 1, 1, 2000, "Roma", "RM")).toBe("MRNLCU00A01H501J");
}); });
it("calcola il codice fiscale da un oggetto JSON", function() {
expect(CodiceFiscale.compute({
name: "Luca",
surname: "Moreno",
gender: 'M',
day: 1,
month: 1,
year: 2000,
birthplace: "Roma",
birthplace_provincia:"RM"
})).toBe("MRNLCU00A01H501J");
});
it("se il comune non esiste lancia un eccezione", function() { it("se il comune non esiste lancia un eccezione", function() {
var comuneInventato = function(){ var comuneInventato = function(){
CodiceFiscale.compute("Luca", "Moreno",'M', 1, 1, 2000, "Pufflandia", "CE"); CodiceFiscale.compute("Luca", "Moreno",'M', 1, 1, 2000, "Pufflandia", "CE");

View File

@ -4,7 +4,7 @@ const path = require('path'),
module.exports = { module.exports = {
entry: { entry: {
'codice.fiscale': './lib/codice.fiscale.js' 'codice.fiscale': './src/codice.fiscale.js'
}, },
output: { output: {
// this will publish the module on the window object in order to support the karma tests // this will publish the module on the window object in order to support the karma tests