I'm trying to do a test but it does not wait to make the request in the database and it looks like the function returns undefined and only after the request it returns true or false and the test falls on the else.
My problem is in RestService of angular 4/5
function in which you perform the password validation to perform an update
handler: data => {
if (this.checkPassword(data.password)) {
console.log("4--------");
// logged in!
let jsonCreate = {
name: form.value.inputName,
email: form.value.inputEmail,
password: form.value.inputPassword,
description: form.value.inputDescription,
id: this.id
};
console.log('jsonCreate');
console.log(jsonCreate);
//adiciona cliente ao banco
this.rest.put('usersClient/atualizacao', jsonCreate)
.subscribe(userUpdated => {
console.log(userUpdated);
});
} else {
console.log("3--------");
return false;
}
}
check password func
}
public checkPassword(password){
console.log("check");
let jsonPost = {};
jsonPost["email"] = this.user.email;
jsonPost["senha"] = password;
console.log(jsonPost);
this.rest.post('Login/clientAuth', jsonPost).subscribe(user => {
console.log("11--------");
if(this.isEmptyObject(user)==true){
console.log("1--------");
return false;
}
else{
console.log("2--------");
return true;
}
});
}