Browse Source

Add firebase test case

Ben Hsieh 8 years ago
parent
commit
48d1c3f76e
2 changed files with 46 additions and 18 deletions
  1. 32
    4
      test/test-firebase.js
  2. 14
    14
      test/test-init.js

+ 32
- 4
test/test-firebase.js View File

63
 
63
 
64
 describe('upload file to firebase', (report, done) => {
64
 describe('upload file to firebase', (report, done) => {
65
 
65
 
66
-  // create Blob from BASE64 data
67
-  let blob = new Blob(RNTest.prop('image'), { type : 'image/png;BASE64'})
68
   let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
66
   let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
69
   RNTest.prop('firebase-image', testImage)
67
   RNTest.prop('firebase-image', testImage)
70
-  // start test after Blob created
71
-  blob.onCreated(() => {
68
+
69
+  // create Blob from BASE64 data
70
+  Blob.build(RNTest.prop('image'), { type : 'image/png;BASE64'})
71
+  .then((blob) => {
72
     let storage = firebase.storage().ref('rnfbtest')
72
     let storage = firebase.storage().ref('rnfbtest')
73
     let task = storage
73
     let task = storage
74
       .child(RNTest.prop('firebase-image'))
74
       .child(RNTest.prop('firebase-image'))
147
     done()
147
     done()
148
   })
148
   })
149
 })
149
 })
150
+
151
+describe('upload from storage', (report, done) => {
152
+  try {
153
+  let file = fs.dirs.DocumentDir + '/tempimg.png'
154
+  fs.writeFile(file, RNTest.prop('image'), 'base64')
155
+    .then(() => Blob.build(RNFetchBlob.wrap(file), {type : 'image/png'}))
156
+    .then((blob) => {
157
+      let storage = firebase.storage().ref('rnfbtest')
158
+      let task = storage
159
+        .child(`image-from-storage-${Platform.OS}-${Date.now()}.png`)
160
+        .put(blob, { contentType : 'image/png' })
161
+        .then((snapshot) => {
162
+          console.log(snapshot.metadata)
163
+          report(<Assert key="upload success"
164
+            expect={true}
165
+            actual={true}/>,
166
+          <Info key="uploaded file stat" >
167
+            <Text>{snapshot.totalBytes}</Text>
168
+            <Text>{JSON.stringify(snapshot.metadata)}</Text>
169
+          </Info>)
170
+          done()
171
+        })
172
+    })
173
+  }
174
+  catch(err) {
175
+    console.log(err)
176
+  }
177
+})

+ 14
- 14
test/test-init.js View File

59
 })
59
 })
60
 
60
 
61
 
61
 
62
-// require('./test-0.1.x-0.4.x')
63
-// require('./test-0.5.1')
64
-// require('./test-0.5.2')
65
-// require('./test-0.6.0')
66
-// require('./test-0.6.2')
67
-// require('./test-0.6.3')
68
-// require('./test-0.7.0')
69
-// require('./test-0.8.0')
70
-// require('./test-0.9.0')
71
-// require('./test-fetch')
72
-// require('./test-fs')
62
+require('./test-0.1.x-0.4.x')
63
+require('./test-0.5.1')
64
+require('./test-0.5.2')
65
+require('./test-0.6.0')
66
+require('./test-0.6.2')
67
+require('./test-0.6.3')
68
+require('./test-0.7.0')
69
+require('./test-0.8.0')
70
+require('./test-0.9.0')
71
+require('./test-fetch')
72
+require('./test-fs')
73
 require('./test-xmlhttp')
73
 require('./test-xmlhttp')
74
-// require('./test-blob')
75
-// require('./test-firebase')
76
-// require('./test-android')
74
+require('./test-blob')
75
+require('./test-firebase')
76
+require('./test-android')
77
 // require('./benchmark')
77
 // require('./benchmark')