Skip to content

Commit

Permalink
feat(PeopleSdkAdapter): getMe() fetches and emits the person data once
Browse files Browse the repository at this point in the history
  • Loading branch information
akoushke committed Dec 17, 2019
1 parent 7e2362e commit d056f2c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/PeopleSDKAdapter.integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ describe('People SDK Adapter', () => {
}
});

describe('getMe()', () => {
test('returns person data of the access token bearer in a proper shape', (done) => {
subscription = webexSDKAdapter.peopleAdapter.getMe().subscribe((person) => {
expect(person).toMatchObject({
ID: userID,
emails: [user.emailAddress],
displayName: user.displayName,
});
done();
});
});
});

describe('getPerson() returns', () => {
beforeEach(() => {
getPerson$ = webexSDKAdapter.peopleAdapter.getPerson(userID);
Expand Down
13 changes: 10 additions & 3 deletions src/PeopleSDKAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {concat, from, fromEvent} from 'rxjs';
import {flatMap, filter, finalize, map, publishReplay, refCount} from 'rxjs/operators';
import {flatMap, filter, finalize, map, publishReplay, refCount, take} from 'rxjs/operators';
import {deconstructHydraId} from '@webex/common';
import {PeopleAdapter, PersonStatus} from '@webex/component-adapter-interfaces';

Expand Down Expand Up @@ -55,14 +55,21 @@ export default class PeopleSDKAdapter extends PeopleAdapter {

/**
* Returns an observable that emits person data of the access token bearer.
* The observable will emit once and then complete.
*
* @public
* @returns {Observable.<Person>}
* @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)));
return from(this.fetchPerson('me')).pipe(
flatMap((person) =>
from(this.datasource.internal.presence.get([person.id])).pipe(
map(({status}) => ({...person, status: this.getStatus(status)}))
)
),
take(1)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/__mocks__/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function createMockSDK() {
off: jest.fn(),
},
presence: {
get: jest.fn(),
get: jest.fn(() => Promise.resolve({status: 'active'})),
subscribe: jest.fn(() => Promise.resolve({responses: [{status: {status: 'active'}}]})),
unsubscribe: jest.fn(() => Promise.resolve()),
},
Expand Down

0 comments on commit d056f2c

Please sign in to comment.