Skip to content

Commit 33ffc99

Browse files
committed
feat(RoomsAdapter): add hasMoreActivities to interface
Additionally, getPreviousRoomActivities returns an array instead of an observable because previous data needs to be pulled instead pushed
1 parent f607520 commit 33ffc99

File tree

2 files changed

+62
-37
lines changed

2 files changed

+62
-37
lines changed

src/adapters/RoomsAdapter.js

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
/* eslint-disable valid-jsdoc */
2+
/* eslint-disable no-unused-vars */
13
import {throwError} from 'rxjs';
24

35
import WebexAdapter from './WebexAdapter';
46

7+
/**
8+
* A Room object with details about the room.
9+
*
10+
* @typedef {Object} Room
11+
* @property {string} ID The room identifier.
12+
* @property {string} title The room title.
13+
* @property {RoomType} type The type of the room. @see RoomType enum
14+
*/
15+
16+
/**
17+
* @typedef {Object} ActivityDate
18+
* @param {string} date Date that will render on a time ruler. Must be a valid date-time string.
19+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#Date_Time_String_Format
20+
*/
21+
522
/**
623
* Enum for room type values.
724
*
@@ -17,56 +34,57 @@ export const RoomType = {
1734
* This is a base class that defines the interface that maps room data.
1835
* Developers that want to extend `RoomsAdapter` must implement all of its methods,
1936
* adhering to the exact parameters and structure of the returned objects.
37+
*
38+
* `RoomsAdapter` handles data of a room such as details about that room but also
39+
* activities that happened/will happen within that room. Activities are expected
40+
* to be lazy loaded, and therefore, chunked.
2041
*/
2142
export default class RoomsAdapter extends WebexAdapter {
22-
/**
23-
* A Room object with details about the room.
24-
*
25-
* @typedef {Object} Room
26-
* @property {string} ID The room identifier.
27-
* @property {string} title The room title.
28-
* @property {RoomType} type The type of the room. @see RoomType enum
29-
*/
30-
31-
/**
32-
* @typedef {Object} ActivityData
33-
* @param {string} date The date to render a time ruler for. Must be a valid date-time string
34-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#Date_Time_String_Format
35-
*/
36-
3743
/**
3844
* Returns an observable that emits room data of the given ID.
3945
*
4046
* @param {string} ID ID of the room to get.
4147
* @returns {Observable.<Room>}
4248
* @memberof RoomsAdapter
4349
*/
44-
// eslint-disable-next-line no-unused-vars
4550
getRoom(ID) {
4651
return throwError(new Error('getRoom(ID) must be defined in RoomsAdapter'));
4752
}
4853

4954
/**
50-
* Returns an observable that emits an array of previous activity IDs of the given roomID.
55+
* Returns an observable that emits an array of current and future activities of the given roomID.
5156
*
52-
* @param {string} ID ID of the room to get.
53-
* @returns {Observable.<Array.<string>>}
57+
* @param {string} ID ID of the room for which to get activities.
58+
* @returns {Observable.<Array.<string|ActivityDate>>}
59+
* @memberof RoomsAdapter
60+
*/
61+
getRoomActivities(ID) {
62+
return throwError(new Error('getRoomActivities(ID) must be defined in RoomsAdapter'));
63+
}
64+
65+
/**
66+
* Returns an observable that emits an array of the next chunk of previous
67+
* activity data of the given roomID. If `hasMoreActivities` returns false,
68+
* the observable will complete.
69+
* **Previous activity data must be sorted oldest-to-latest.**
70+
*
71+
* @param {string} ID ID of the room for which to get activities.
72+
* @returns {Observable.<Array.<string|ActivityDate>>}
5473
* @memberof RoomsAdapter
5574
*/
56-
// eslint-disable-next-line no-unused-vars
5775
getPreviousRoomActivities(ID) {
5876
return throwError(new Error('getPreviousRoomActivities(ID) must be defined in RoomsAdapter'));
5977
}
6078

6179
/**
62-
* Returns an observable that emits an array of current activities of the given roomID.
80+
* Returns `true` if there are more activities to load from the room of the given ID.
81+
* Otherwise, it returns `false`.
6382
*
64-
* @param {string} ID ID of the room to get.
65-
* @returns {Observable.<Array.<string|ActivityData>>}
83+
* @param {string} ID ID of the room for which to verify activities.
84+
* @returns {boolean}
6685
* @memberof RoomsAdapter
6786
*/
68-
// eslint-disable-next-line no-unused-vars
69-
getRoomActivities(ID) {
70-
return throwError(new Error('getRoomActivities(ID) must be defined in RoomsAdapter'));
87+
hasMoreActivities(ID) {
88+
throw new Error('hasMoreActivities(ID) must be defined in RoomsAdapter');
7189
}
7290
}

src/adapters/RoomsAdapter.test.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe('Rooms Adapter Interface', () => {
1111
expect(rxjs.isObservable(roomsAdapter.getRoom())).toBeTruthy();
1212
});
1313

14-
test('getRoom() throws a proper error message', (done) => {
15-
roomsAdapter.getRoom('id').subscribe(
14+
test('getRoom() errors because it needs to be defined', (done) => {
15+
roomsAdapter.getRoom('ID').subscribe(
1616
() => {},
1717
(error) => {
1818
expect(error.message).toBe('getRoom(ID) must be defined in RoomsAdapter');
@@ -21,34 +21,41 @@ describe('Rooms Adapter Interface', () => {
2121
);
2222
});
2323

24-
test('getPreviousRoomActivities() returns an observable', () => {
25-
expect(rxjs.isObservable(roomsAdapter.getPreviousRoomActivities())).toBeTruthy();
24+
test('getRoomActivities() returns an observable', () => {
25+
expect(rxjs.isObservable(roomsAdapter.getRoomActivities())).toBeTruthy();
2626
});
2727

28-
test('getPreviousRoomActivities() throws a proper error message', (done) => {
29-
roomsAdapter.getPreviousRoomActivities('id').subscribe(
28+
test('getRoomActivities() errors because it needs to be defined', (done) => {
29+
roomsAdapter.getRoomActivities('id').subscribe(
3030
() => {},
3131
(error) => {
32-
expect(error.message).toBe('getPreviousRoomActivities(ID) must be defined in RoomsAdapter');
32+
expect(error.message).toBe('getRoomActivities(ID) must be defined in RoomsAdapter');
3333
done();
3434
}
3535
);
3636
});
3737

38-
test('getRoomActivities() returns an observable', () => {
38+
test('getPreviousRoomActivities() returns an observable', () => {
3939
expect(rxjs.isObservable(roomsAdapter.getRoomActivities())).toBeTruthy();
4040
});
4141

42-
test('getRoomActivities() throws a proper error message', (done) => {
43-
roomsAdapter.getRoomActivities('id').subscribe(
42+
test('getPreviousRoomActivities() errors because it needs to be defined', (done) => {
43+
roomsAdapter.getPreviousRoomActivities('id').subscribe(
4444
() => {},
4545
(error) => {
46-
expect(error.message).toBe('getRoomActivities(ID) must be defined in RoomsAdapter');
46+
expect(error.message).toBe('getPreviousRoomActivities(ID) must be defined in RoomsAdapter');
4747
done();
4848
}
4949
);
5050
});
5151

52+
test('hasMoreActivities() errors because it needs to be defined', () => {
53+
try {
54+
expect(roomsAdapter.hasMoreActivities('ID')).toThrowError();
55+
// eslint-disable-next-line no-empty
56+
} catch (error) {}
57+
});
58+
5259
afterEach(() => {
5360
roomsAdapter = null;
5461
});

0 commit comments

Comments
 (0)