From d7ead01180bf70887734a36dda621d0718dbd356 Mon Sep 17 00:00:00 2001 From: David Jay Date: Tue, 8 Nov 2016 17:53:38 -0500 Subject: [PATCH] Expecting stream endpoint to return items broken out by type. --- client/coral-framework/store/actions/items.js | 13 ++++++++++--- tests/models/action.js | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/coral-framework/store/actions/items.js b/client/coral-framework/store/actions/items.js index 8b30e2548..956b70350 100644 --- a/client/coral-framework/store/actions/items.js +++ b/client/coral-framework/store/actions/items.js @@ -89,12 +89,19 @@ export function getStream (assetId) { ) .then((json) => { + /* Add items to the store */ + const itemTypes = Object.keys(json); + for (let i=0; i < itemTypes.length; i++ ) { + for (var j=0; j < json[itemTypes[i]].length; j++ ) { + dispatch(addItem(json[itemTypes[i]][j])); + } + } + /* Sort comments by date*/ let rootComments = [] let childComments = {} - json.sort((a,b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) - json.reduce((prev, item) => { - dispatch(addItem(item)) + json.comments.sort((a,b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()) + json.comments.reduce((prev, item) => { /* Check for root and child comments. */ if ( diff --git a/tests/models/action.js b/tests/models/action.js index 95d8dc29b..e3ead7047 100644 --- a/tests/models/action.js +++ b/tests/models/action.js @@ -45,6 +45,8 @@ describe('Action: models', () => { return Action.getActionSummaries(['123', '789']).then((result) => { expect(result).to.have.length(2); const sorted = result.sort((a, b) => a.count - b.count); + delete sorted[0].id; + delete sorted[1].id; expect(sorted[0]).to.deep.equal({ type: 'like', count: 1,