Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Testing of applyParamsToQuery util improved to include cases caught by
  • Loading branch information
prescottprue committed Mar 25, 2017
commit 2bd1c90545bee2a48c84432d9ccb5facd83400ab
2 changes: 0 additions & 2 deletions tests/unit/helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ describe('Helpers:', () => {
{ child: 'collaborators', root: rootName },
]
// TODO: Test both children are populated
console.log('--------3', helpers.populatedDataToJS(exampleState, path, populates))
console.log('should have', exampleData.data[rootName])
expect(helpers.populatedDataToJS(exampleState, `/${path}`, populates))
.to
.have
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/utils/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
const method = () => Promise.resolve()
const failMethod = () => Promise.reject()
const dispatch = () => {
console.log('dispatch called')
// console.log('dispatch called')
}
describe('Utils: Auth', () => {
describe('wrapInDispatch', () => {
Expand Down
125 changes: 120 additions & 5 deletions tests/unit/utils/query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,47 @@ import {
getQueryIdFromPath,
applyParamsToQuery
} from '../../../src/utils/query'
const fakeFirebase = {
_: {
authUid: '123',
config: {
userProfile: 'users',
disableRedirectHandling: true,
},
},
database: () => ({
ref: () => ({
orderByValue: () => ({
on: () => ({ val: () => { some: 'obj' } }),
off: () => Promise.resolve({ val: () => { some: 'obj' }}),
once: () => Promise.resolve({ val: () => { some: 'obj' }})
}),
orderByPriority: () => ({
startAt: (startParam) => startParam,
toString: () => 'priority'
}),
orderByChild: (child) => ({
equalTo: (equalTo) => ({
child,
equalTo
}),
toString: () => child
}),
orderByKey: () => ({ }),
limitToFirst: () => ({ }),
limitToLast: () => ({ }),
equalTo: () => ({ }),
startAt: () => ({ }),
endAt: () => ({ }),
})
}),
}
let spy

let createQueryFromParams = (queryParams) =>
applyParamsToQuery(queryParams, Firebase.database().ref())
applyParamsToQuery(queryParams, fakeFirebase.database().ref())
const dispatch = () => {}
let ref
describe('Utils: Query', () => {
describe('getWatchPath', () => {
it('handles basic path', () => {
Expand Down Expand Up @@ -78,15 +116,92 @@ describe('Utils: Query', () => {
it('orderByValue', () => {
expect(createQueryFromParams(['orderByValue=uid'])).to.be.an.object
})
it('orderByPriority', () => {
expect(createQueryFromParams(['orderByPriority=uid'])).to.be.an.object

describe('orderByPriority', () => {
it('handles single parameter', () => {
expect(createQueryFromParams(['orderByPriority']).toString())
.to.equal('priority')
})

describe('with startAt', () => {
it ('string containing number', () => {
const startAt = '123abc'
expect(createQueryFromParams(['orderByPriority', `startAt=${startAt}`]).toString())
.to.equal(startAt)
})
})
})

it('orderByKey', () => {
expect(createQueryFromParams(['orderByKey'])).to.be.an.object
})
it('orderByChild', () => {
expect(createQueryFromParams(['orderByChild=uid'])).to.be.an.object

describe('orderByChild', () => {
it('handles single parameter', () => {
const queryParams = createQueryFromParams(['orderByChild=uid'])
expect(queryParams.toString()).to.equal('uid')
})

describe('with equalTo', () => {
it('number', () => {
const child = 'emailAddress'
const equalTo = 1
const queryParams = createQueryFromParams([`orderByChild=${child}`, `equalTo=${equalTo}`])
expect(queryParams.child)
.to
.equal(child)
expect(queryParams.equalTo)
.to
.equal(equalTo)
})
it('boolean', () => {
const child = 'completed'
const equalTo = false
const queryParams = createQueryFromParams([`orderByChild=${child}`, `equalTo=${equalTo}`])
expect(queryParams.child)
.to
.equal(child)
expect(queryParams.equalTo)
.to
.equal(equalTo)
})
it('string containing a boolean', () => {
const child = 'emailAddress'
const equalTo = 'true'
const queryParams = createQueryFromParams([`orderByChild=${child}`, `equalTo=${equalTo}`])
expect(queryParams.child)
.to
.equal(child)
expect(queryParams.equalTo)
.to
.equal(true)
})
it('string containing null', () => {
const child = 'emailAddress'
const equalTo = 'null'
const queryParams = createQueryFromParams([`orderByChild=${child}`, `equalTo=${equalTo}`])
expect(queryParams.child)
.to
.equal(child)
expect(queryParams.equalTo)
.to
.equal(null)
})
it('string containing a number', () => {
const child = 'emailAddress'
const equalTo = '[email protected]'
const queryParams = createQueryFromParams([`orderByChild=${child}`, `equalTo=${equalTo}`])
expect(queryParams.child)
.to
.equal(child)
expect(queryParams.equalTo)
.to
.equal(equalTo)
})
})

})

it('limitToFirst', () => {
expect(createQueryFromParams(['limitToFirst=1'])).to.be.an.object
})
Expand Down