Skip to content

Commit

Permalink
feat(memberships): add memberships adapter interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Zixi Xu (zixxu) authored and lalli-flores committed Jul 6, 2020
1 parent fa3963f commit 7141890
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/MembershipsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {throwError} from 'rxjs';

import WebexAdapter from './WebexAdapter';

/**
* A Membership object with details about the member.
*
* @typedef {Object} Membership
* @property {string} ID The member identifier.
* @property {string} destinationID ID of the destination for which to get members.
* @property {string} destinationType type of the membership destination.
* @property {Array.<Object>} members An array of members information.
*/

/**
* Enum for types of destinations.
*
* @readonly
* @enum {string}
*/
export const DestinationType = {
ROOM: 'room',
MEETING: 'meeting',
};

/**
* This is a base class that defines the interface that maps membership data.
* Developers that want to extend `MembershipsAdapter` must implement all of its methods,
* adhering to the exact parameters and structure of the returned objects.
*
* @interface
*/
export default class MembershipsAdapter extends WebexAdapter {
/**
* Returns an observable that emits a Membership object.
* Whenever there is an update to the membership, the observable
* will emit a new updated Membership object, if datasource permits.
*
* @param {string} destinationID ID of the destination for which to get members.
* @param {DestinationType} destinationType type of the membership destination.
* @returns {Observable.<Membership>}
* @memberof MembershipAdapter
*/
getMembersFromDestination(destinationID, destinationType) {
return throwError(
new Error('getMembersFromDestination(destinationID, destinationType) must be defined in MembershipsAdapter')
);
}
}
33 changes: 33 additions & 0 deletions src/MembershipsAdapter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {isObservable} from 'rxjs';

import MembershipsAdapter from './MembershipsAdapter';

describe('Memberships Adapter Interface', () => {
let membershipsAdapter;

beforeEach(() => {
membershipsAdapter = new MembershipsAdapter();
});

afterEach(() => {
membershipsAdapter = null;
});

describe('getMembership()', () => {
test('returns an observable', () => {
expect(isObservable(membershipsAdapter.getMembersFromDestination())).toBeTruthy();
});

test('errors because it needs to be defined', (done) => {
membershipsAdapter.getMembersFromDestination('meetingID', 'meetingType').subscribe(
() => {},
(error) => {
expect(error.message).toBe(
'getMembersFromDestination(destinationID, destinationType) must be defined in MembershipsAdapter'
);
done();
}
);
});
});
});
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {default as WebexAdapter} from './WebexAdapter';
export {default as ActivitiesAdapter} from './ActivitiesAdapter';
export {default as MeetingsAdapter, MeetingControlState} from './MeetingsAdapter';
export {default as MembershipsAdapter, DestinationType} from './MembershipsAdapter';
export {default as PeopleAdapter, PersonStatus} from './PeopleAdapter';
export {default as RoomsAdapter, RoomType} from './RoomsAdapter';

0 comments on commit 7141890

Please sign in to comment.