Skip to content

Commit

Permalink
feat(ActivitiesAdapter): implement adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
akoushke committed Oct 25, 2019
1 parent 26fcab4 commit 1e3a672
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ActivitiesAdapter.js
Original file line number Diff line number Diff line change
@@ -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.<Activity>}
* @memberof ActivityAdapter
*/
getActivity(ID) {
return throwError(new Error('getActivity(ID) must be defined in ActivitiesAdapter'));
}
}
29 changes: 29 additions & 0 deletions src/ActivitiesAdapter.test.js
Original file line number Diff line number Diff line change
@@ -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;
});
});

0 comments on commit 1e3a672

Please sign in to comment.