From 71418903c44f2d662194edce1f172223f9abff0b Mon Sep 17 00:00:00 2001 From: "Zixi Xu (zixxu)" Date: Tue, 30 Jun 2020 10:19:12 -0700 Subject: [PATCH] feat(memberships): add memberships adapter interface --- src/MembershipsAdapter.js | 49 ++++++++++++++++++++++++++++++++++ src/MembershipsAdapter.test.js | 33 +++++++++++++++++++++++ src/index.js | 1 + 3 files changed, 83 insertions(+) create mode 100644 src/MembershipsAdapter.js create mode 100644 src/MembershipsAdapter.test.js diff --git a/src/MembershipsAdapter.js b/src/MembershipsAdapter.js new file mode 100644 index 0000000..f549ffa --- /dev/null +++ b/src/MembershipsAdapter.js @@ -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.} 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.} + * @memberof MembershipAdapter + */ + getMembersFromDestination(destinationID, destinationType) { + return throwError( + new Error('getMembersFromDestination(destinationID, destinationType) must be defined in MembershipsAdapter') + ); + } +} diff --git a/src/MembershipsAdapter.test.js b/src/MembershipsAdapter.test.js new file mode 100644 index 0000000..6c9022c --- /dev/null +++ b/src/MembershipsAdapter.test.js @@ -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(); + } + ); + }); + }); +}); diff --git a/src/index.js b/src/index.js index 288fc12..939d1c5 100644 --- a/src/index.js +++ b/src/index.js @@ -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';