diff --git a/src/helpers.js b/src/helpers.js index 268cf5496..1f6f436d7 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -190,7 +190,8 @@ export function fixPath(path) { * @returns {object} List of child objects */ function buildChildList(state, list, p) { - return mapValues(list, (val, key) => { + const mapFn = Array.isArray(list) ? map : mapValues + return mapFn(list, (val, key) => { let getKey = val // Handle key: true lists if (val === true || p.populateByKey) { diff --git a/test/mockData.js b/test/mockData.js index 3bb295114..8bf459717 100644 --- a/test/mockData.js +++ b/test/mockData.js @@ -11,7 +11,8 @@ export const exampleData = { collaborators: { ABC: true, abc: true - } + }, + userRank: ['user2', 'ABC'] }, GHI: { owner: 'ABC', @@ -59,6 +60,9 @@ export const exampleData = { users: { ABC: { displayName: 'scott' + }, + user2: { + displayName: 'User2Name' } }, categories: { diff --git a/test/unit/helpers.spec.js b/test/unit/helpers.spec.js index e98788401..ce989af2d 100644 --- a/test/unit/helpers.spec.js +++ b/test/unit/helpers.spec.js @@ -153,7 +153,7 @@ describe('Helpers:', () => { rootName = 'users' }) - it('populates values', () => { + it('populates values by rtdb or firestore Map type', () => { path = 'projects/OKF' populates = [{ child: 'collaborators', root: rootName }] const populatedData = helpers.populate(exampleData, path, populates) @@ -162,6 +162,17 @@ describe('Helpers:', () => { exampleData.data[rootName].ABC.displayName ) }) + + it('populates values by firestore List type', () => { + path = 'projects/CDF' + populates = [{ child: 'userRank', root: rootName }] + const populatedData = helpers.populate(exampleData, path, populates) + expect(populatedData.userRank).to.be.instanceof(Array) + expect(populatedData).to.have.deep.property( + `userRank.0.displayName`, + exampleData.data[rootName].user2.displayName + ) + }) }) describe('config as function -', () => {