Skip to content

Commit

Permalink
test: user profile & session update
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it committed Mar 24, 2020
1 parent 6b6345e commit 80b2459
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ describe('user profile directive', function () {
});

describe('saveUser', function () {
describe('with a successfull backend call', function () {
describe('with a successful backend call', function () {
beforeEach(function () {
spyOn(UserEndpoint, 'update').and.callThrough();
spyOn(Session, 'setSessionDataEntries').and.callThrough();
spyOn(Notify, 'apiErrors')
spyOn(Notify, 'notify').and.callThrough();
});

describe('after changed values of user', function () {
beforeEach(function () {
isolateScope.user.realname = 'Changed name';
isolateScope.user.email = 'changed@ushahidi.com';
});

describe('after calling saveUser', function () {
Expand All @@ -60,19 +64,54 @@ describe('user profile directive', function () {
});

it('should call "update" on the UserEndpoint with id=me and the changed user profile values', function () {
expect(UserEndpoint.update).toHaveBeenCalled();
expect(UserEndpoint.update).toHaveBeenCalledWith(
{id: 'me'},
jasmine.objectContaining({
'email': 'changed@ushahidi.com',
'realname': 'Changed name'
}
)
);
expect(isolateScope.user.realname).toBe('Changed name');
expect(isolateScope.user.email).toBe('changed@ushahidi.com');
expect(Notify.notify).toHaveBeenCalledWith('user_profile.update_success');
expect(Notify.apiErrors).toHaveBeenCalledTimes(0)
expect(Session.setSessionDataEntries).toHaveBeenCalledWith(
{'email': 'changed@ushahidi.com', 'realname': 'Changed name'}
);
});

it('should set user to the new data', function () {
expect(isolateScope.user.someField).toBe('addedByServer');
});
});
});

describe('after changed the password of the user', function () {
beforeEach(function () {
isolateScope.user.password = 'changed';
});

describe('after calling saveUser', function () {
beforeEach(function () {
isolateScope.saveUser(isolateScope.user);
});

it('should call "update" on the UserEndpoint with the changed password', function () {
expect(UserEndpoint.update).toHaveBeenCalledWith(
{id: 'me'},
jasmine.objectContaining({
'password': 'changed'
}
)
);
expect(Notify.apiErrors).toHaveBeenCalledTimes(0)
});
});
});
});

describe('with an error on the backend call', function () {

var errorResponse = {
status: 400,
data: {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/mock/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module.exports = [function () {
successCallback({
realname: 'Changed name',
id: 1,
someField: 'addedByServer'
someField: 'addedByServer',
email: 'changed@ushahidi.com'
});
} else {
failCallback({
Expand Down

0 comments on commit 80b2459

Please sign in to comment.