Skip to content

Commit

Permalink
Added test for saving user without any changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Sep 21, 2015
1 parent a2ac10e commit 6f22cd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/src/common/services/user/userService.spec.ts
Expand Up @@ -283,6 +283,19 @@ namespace common.services.user {
$httpBackend.flush();
});



it('should not make an api call if nothing has changed', () => {

let user = common.models.UserMock.entity();
user.setExists(true);

let savePromise = userService.saveUserWithRelated(user);

expect(savePromise).eventually.to.equal(user);

});

});

});
Expand Down
4 changes: 4 additions & 0 deletions app/src/common/services/user/userService.ts
Expand Up @@ -197,6 +197,10 @@ namespace common.services.user {
*/
private saveUserProfile(user:common.models.User):ng.IPromise<common.models.UserProfile|boolean>{

if (!user._userProfile){ //don't try to save if there is no profile
return this.$q.when(false);
}

let changes:any = (<common.decorators.IChangeAwareDecorator>user._userProfile).getChanged();
if (_.isEmpty(changes)){
return this.$q.when(false);
Expand Down

0 comments on commit 6f22cd6

Please sign in to comment.