Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RoomsAdapter): fix sort order #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/RoomsSDKAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/RoomsSDKAdapter.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down