From 67098382705afbc0af1dd9c2dcf2c2fd2f1ae1d9 Mon Sep 17 00:00:00 2001 From: Arash Koushkebaghi Date: Fri, 13 Dec 2019 18:02:45 -0800 Subject: [PATCH] feat(PeopleSdkAdapter): implement getMe --- src/PeopleSDKAdapter.js | 12 ++++++++++++ src/PeopleSDKAdapter.test.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/PeopleSDKAdapter.js b/src/PeopleSDKAdapter.js index 7079283e..32bf125c 100644 --- a/src/PeopleSDKAdapter.js +++ b/src/PeopleSDKAdapter.js @@ -53,6 +53,18 @@ export default class PeopleSDKAdapter extends PeopleAdapter { }; } + /** + * Returns an observable that emits person data of the access token bearer. + * + * @public + * @returns {Observable.} + * @memberof PeopleSDKAdapter + */ + getMe() { + // person ID must be retrieved in order to invoke `getPerson` method properly. + return from(this.datasource.people.get('me')).pipe(flatMap(({id}) => this.getPerson(id))); + } + /** * Returns an observable that emits person data of the given ID. * diff --git a/src/PeopleSDKAdapter.test.js b/src/PeopleSDKAdapter.test.js index 36ba3ed0..8e00f125 100644 --- a/src/PeopleSDKAdapter.test.js +++ b/src/PeopleSDKAdapter.test.js @@ -12,6 +12,24 @@ describe('People SDK Adapter', () => { personID = 'personID'; }); + describe('getMe()', () => { + test('returns a person in a proper shape', (done) => { + peopleSDKAdapter.getMe().subscribe((person) => { + expect(person).toMatchObject({ + ID: 'id', + emails: ['email@cisco.com'], + displayName: 'Webex Components', + firstName: 'Webex', + lastName: 'Components', + avatar: 'avatar', + orgID: 'orgID', + status: 'ACTIVE', + }); + done(); + }); + }); + }); + describe('getPerson()', () => { test('returns an observable', () => { expect(isObservable(peopleSDKAdapter.getPerson(personID))).toBeTruthy();