Skip to content
Merged
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/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion test/mockData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const exampleData = {
collaborators: {
ABC: true,
abc: true
}
},
userRank: ['user2', 'ABC']
},
GHI: {
owner: 'ABC',
Expand Down Expand Up @@ -59,6 +60,9 @@ export const exampleData = {
users: {
ABC: {
displayName: 'scott'
},
user2: {
displayName: 'User2Name'
}
},
categories: {
Expand Down
13 changes: 12 additions & 1 deletion test/unit/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 -', () => {
Expand Down