diff --git a/src/RoomsSDKAdapter.js b/src/RoomsSDKAdapter.js index 0447953c..10d21c30 100644 --- a/src/RoomsSDKAdapter.js +++ b/src/RoomsSDKAdapter.js @@ -32,7 +32,8 @@ import cache from './cache'; export const ROOM_UPDATED_EVENT = 'updated'; export const CONVERSATION_ACTIVITY_EVENT = 'event:conversation.activity'; -const sortByPublished = (arr) => arr.sort((a, b) => new Date(b.published) - new Date(a.published)); +// eslint-disable-next-line max-len +export const sortByPublished = (arr) => arr.sort((a, b) => new Date(a.published) - new Date(b.published)); // TODO: Need to remove this once we figure out why we need to pre-cache conversations let FETCHED_CONVERSATIONS = false; diff --git a/src/RoomsSDKAdapter.test.js b/src/RoomsSDKAdapter.test.js index a1fbd773..7d720cc8 100644 --- a/src/RoomsSDKAdapter.test.js +++ b/src/RoomsSDKAdapter.test.js @@ -1,6 +1,6 @@ import {isObservable} from 'rxjs'; -import RoomsSDKAdapter from './RoomsSDKAdapter'; +import RoomsSDKAdapter, {sortByPublished} from './RoomsSDKAdapter'; import mockActivities from './mockActivities'; import createMockSDK, {mockSDKActivity, mockSDKRoom} from './mockSdk'; import {fromSDKActivity} from './ActivitiesSDKAdapter'; @@ -19,6 +19,26 @@ describe('Rooms SDK Adapter', () => { roomsSDKAdapter = new RoomsSDKAdapter(mockSDK); }); + describe('sortByPublished', () => { + it('should sort oldest to newest', () => { + const input = [ + {published: '2021-06-22T00:00:00.007Z'}, + {published: '2021-06-25T00:00:00.007Z'}, + {published: '2021-06-24T00:00:00.007Z'}, + {published: '2021-06-21T00:00:00.007Z'}, + ]; + + const output = [ + {published: '2021-06-21T00:00:00.007Z'}, + {published: '2021-06-22T00:00:00.007Z'}, + {published: '2021-06-24T00:00:00.007Z'}, + {published: '2021-06-25T00:00:00.007Z'}, + ]; + + expect(sortByPublished(input)).toStrictEqual(output); + }); + }); + describe('getRoom() functionality', () => { test('returns an observable', () => { expect(isObservable(roomsSDKAdapter.getRoom())).toBeTruthy();