Skip to content

Commit 671effc

Browse files
author
Scott Prue
committed
Test files added to lint command. Storage action unit tests added.
1 parent dc937c8 commit 671effc

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"watch": "npm run build -- --watch",
1212
"clean": "rimraf dist",
1313
"prepublish": "npm run clean && npm run build",
14-
"lint": "eslint src/**",
14+
"lint": "eslint src/** test/**",
1515
"lint:fix": "npm run lint -- --fix",
1616
"test": "mocha -R spec --compilers js:babel-core/register ./test/setup.js ./test/**/*.spec.js",
1717
"test:cov": "istanbul cover ./node_modules/mocha/bin/_mocha -- ./test/** --recursive --report lcov --compilers js:babel-register --require babel-polyfill",

src/compose.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default (config, otherConfig) => next =>
113113
resetPassword,
114114
watchEvent,
115115
unWatchEvent,
116-
storage: Firebase.storage
116+
storage: () => Firebase.storage()
117117
}
118118

119119
authActions.init(dispatch, firebase)

test/unit/actions/storage.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* global describe expect it beforeEach sinon */
2+
import {
3+
uploadFileWithProgress,
4+
uploadFile,
5+
uploadFiles,
6+
deleteFile
7+
} from '../../../src/actions/storage'
8+
9+
let spy
10+
let unListen = sinon.spy()
11+
const dispatch = () => {}
12+
const fakeFirebase = {
13+
_: {
14+
authUid: '123',
15+
config: {
16+
userProfile: 'users'
17+
}
18+
},
19+
database: () => ({
20+
ref: () => ({
21+
child: () => ({
22+
on: () => Promise.resolve({ val: () => ({ some: 'obj' }) }),
23+
off: () => Promise.resolve({ val: () => ({ some: 'obj' }) }),
24+
once: () => Promise.resolve({ val: () => ({ some: 'obj' }) })
25+
})
26+
})
27+
}),
28+
storage: () => ({
29+
ref: () => ({
30+
put: () => ({
31+
on: (event, funcsObj) => {
32+
funcsObj.next({bytesTransferred: 12, totalBytes: 12})
33+
funcsObj.error()
34+
funcsObj.complete()
35+
return unListen
36+
}
37+
}),
38+
delete: () => Promise.resolve(({
39+
40+
}))
41+
})
42+
})
43+
}
44+
45+
fakeFirebase.storage.TaskEvent = { STATE_CHANGED: 'asdf' }
46+
47+
describe('Actions: Storage', () => {
48+
describe('uploadFileWithProgress', () => {
49+
beforeEach(() => {
50+
spy = sinon.spy(dispatch)
51+
})
52+
it('is exported', () => {
53+
expect(uploadFileWithProgress).to.be.a.function
54+
})
55+
it.skip('runs given basic params', () =>
56+
uploadFileWithProgress(dispatch, fakeFirebase, { path: 'projects', file: { name: 'test.png' } })
57+
.then((snap) => {
58+
expect(spy).to.have.been.calledOnce
59+
expect(snap).to.be.an.object
60+
})
61+
)
62+
})
63+
64+
describe('uploadFile', () => {
65+
beforeEach(() => {
66+
spy = sinon.spy(dispatch)
67+
})
68+
it('is exported', () => {
69+
expect(uploadFile).to.be.a.function
70+
})
71+
it.skip('runs given basic params', () =>
72+
uploadFile(dispatch, fakeFirebase, { path: 'projects', file: { name: 'test.png' } })
73+
.then((snap) => {
74+
expect(spy).to.have.been.calledOnce
75+
expect(snap).to.be.an.object
76+
})
77+
)
78+
})
79+
80+
describe('uploadFiles', () => {
81+
it('is exported', () => {
82+
expect(uploadFiles).to.be.a.function
83+
})
84+
it('runs given basic params', () =>
85+
uploadFiles(dispatch, fakeFirebase, { path: 'projects', file: { name: 'test.png' } })
86+
.then((snap) => {
87+
expect(snap).to.be.an.object
88+
})
89+
)
90+
})
91+
92+
describe('deleteFile', () => {
93+
it('is exported', () => {
94+
expect(deleteFile).to.be.a.function
95+
})
96+
it('runs given basic params', () =>
97+
deleteFile(dispatch, fakeFirebase, { path: 'projects', file: { name: 'test.png' } })
98+
.then((snap) => {
99+
expect(snap).to.be.an.object
100+
})
101+
)
102+
})
103+
})

0 commit comments

Comments
 (0)