From 1e3a6724316f9cd8170158088c2f1b627da3a4b4 Mon Sep 17 00:00:00 2001 From: Arash Koushkebaghi Date: Fri, 25 Oct 2019 14:40:46 -0700 Subject: [PATCH] feat(ActivitiesAdapter): implement adapter --- src/ActivitiesAdapter.js | 33 +++++++++++++++++++++++++++++++++ src/ActivitiesAdapter.test.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/ActivitiesAdapter.js create mode 100644 src/ActivitiesAdapter.test.js diff --git a/src/ActivitiesAdapter.js b/src/ActivitiesAdapter.js new file mode 100644 index 0000000..2970a51 --- /dev/null +++ b/src/ActivitiesAdapter.js @@ -0,0 +1,33 @@ +import {throwError} from 'rxjs'; + +import WebexAdapter from './WebexAdapter'; + +/** + * An activity a person performs in Webex. + * + * @typedef {Object} Activity + * @property {string} ID The activity identifier. + * @property {string} roomID ID of the room where the activity happens. + * @property {string} text Any text the activity may contain. + * @property {string} personID ID of the person performing the activity. + * @property {Date} created Timestamp of the time when the activity happened. + * @property {Boolean} displayAuthor Whether to display author information or not. + */ + +/** + * This is a base class that defines the interface that maps activity data. + * Developers that want to extend `ActivitiesAdapter` must implement all of its methods, + * adhering to the exact parameters and structure of the returned objects. + */ +export default class ActivitiesAdapter extends WebexAdapter { + /** + * Returns an observable that emits activity data of the given ID. + * + * @param {string} ID ID of the activity to get. + * @returns {Observable.} + * @memberof ActivityAdapter + */ + getActivity(ID) { + return throwError(new Error('getActivity(ID) must be defined in ActivitiesAdapter')); + } +} diff --git a/src/ActivitiesAdapter.test.js b/src/ActivitiesAdapter.test.js new file mode 100644 index 0000000..fa3a959 --- /dev/null +++ b/src/ActivitiesAdapter.test.js @@ -0,0 +1,29 @@ +import {isObservable} from 'rxjs'; + +import ActivitiesAdapter from './ActivitiesAdapter'; + +describe('Activities Adapter Interface', () => { + let activitiesAdapter; + + beforeEach(() => { + activitiesAdapter = new ActivitiesAdapter(); + }); + + test('getActivity() returns an observable', () => { + expect(isObservable(activitiesAdapter.getActivity())).toBeTruthy(); + }); + + test('getActivity() errors because it needs to be defined', (done) => { + activitiesAdapter.getActivity('msgID').subscribe( + () => {}, + (error) => { + expect(error.message).toBe('getActivity(ID) must be defined in ActivitiesAdapter'); + done(); + } + ); + }); + + afterEach(() => { + activitiesAdapter = null; + }); +});