Skip to content

Commit d82b80c

Browse files
committed
feat(tests): unit test added for populateByKey - #349
1 parent c4dab59 commit d82b80c

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

test/mockData.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const exampleData = {
2525
collaborators: {
2626
ABC: true,
2727
abc: true
28+
},
29+
nonKeyTrue: {
30+
ABC: 10,
31+
abc: 'testing'
2832
}
2933
},
3034
QRS: {
@@ -77,6 +81,10 @@ export const exampleData = {
7781
tester: {
7882
somePermission: true
7983
}
84+
},
85+
nonKeyTrue: {
86+
ABC: 10,
87+
abc: 'testing'
8088
}
8189
},
8290
ordered: {

test/unit/helpers.spec.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { get } from 'lodash'
22
import { exampleData } from '../mockData'
33
import * as helpers from '../../src/helpers'
4+
45
let path
56
let valName
67
let rootName
78
let populates
9+
let child
810

911
describe('Helpers:', () => {
1012
describe('getVal', () => {
@@ -290,6 +292,64 @@ describe('Helpers:', () => {
290292
exampleData.data[rootName].ABC.displayName
291293
)
292294
})
295+
296+
describe('populateByKey', () => {
297+
it('populates non key true', () => {
298+
path = 'projects'
299+
rootName = 'users'
300+
valName = 'OKF'
301+
let child = 'nonKeyTrue'
302+
populates = [
303+
{
304+
child,
305+
root: rootName,
306+
populateByKey: true
307+
}
308+
]
309+
// Non matching collaborator
310+
expect(
311+
helpers.populate(exampleData, path, populates)
312+
).to.have.deep.property(
313+
`${valName}.${child}.abc`,
314+
exampleData.data[path][valName][child].abc
315+
)
316+
// Matching collaborator
317+
expect(
318+
helpers.populate(exampleData, path, populates)
319+
).to.have.deep.property(
320+
`${valName}.${child}.ABC.displayName`,
321+
exampleData.data[rootName].ABC.displayName
322+
)
323+
})
324+
325+
it('does not populate if false', () => {
326+
path = 'projects'
327+
rootName = 'users'
328+
valName = 'OKF'
329+
child = 'nonKeyTrue'
330+
populates = [
331+
{
332+
child,
333+
root: rootName,
334+
populateByKey: false
335+
}
336+
]
337+
// Non matching collaborator
338+
expect(
339+
helpers.populate(exampleData, path, populates)
340+
).to.have.deep.property(
341+
`${valName}.${child}.abc`,
342+
exampleData.data[path][valName][child].abc
343+
)
344+
// Matching collaborator
345+
expect(
346+
helpers.populate(exampleData, path, populates)
347+
).to.have.deep.property(
348+
`${valName}.${child}.ABC`,
349+
exampleData.data[path][valName][child].ABC
350+
)
351+
})
352+
})
293353
})
294354

295355
describe('config as function', () => {

0 commit comments

Comments
 (0)