Skip to content

Commit

Permalink
FEATURE: PR-298 Gets user's current profile
Browse files Browse the repository at this point in the history
  • Loading branch information
BugsBunny338 committed Aug 14, 2018
1 parent cd471dd commit 3e86de7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ export class UserModule {
}, (err: ApiResponseError) => Promise.reject(err));
}

/**
* Gets current user's profile
* @method getCurrentProfile
* @return {Promise} resolves with account setting object if user logged in, false otherwise
*/
public getCurrentProfile() {
return this.xhr.get('/gdc/account/profile/current')
.then(r => r.getData().accountSetting);
}

/**
* Updates user's profile settings
* @method updateProfileSettings
Expand Down
24 changes: 24 additions & 0 deletions test/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ describe('user', () => {
});
});

describe('getCurrentProfile', () => {
it('should get current user\'s profile', () => {
const profileUri = 'PROFILE_URI';

fetchMock.mock(
'/gdc/account/profile/current',
{
status: 200,
body: JSON.stringify({
accountSetting: {
links: {
self: profileUri
}
}
})
}
);

return createUser().getCurrentProfile().then((accountSetting) => {
expect(accountSetting.links.self).toEqual(profileUri);
});
});
});

describe('updateProfileSettings', () => {
it('should update user\'s settings', () => {
expect.assertions(1);
Expand Down

0 comments on commit 3e86de7

Please sign in to comment.