Browse Source

Fix test cases

Ben Hsieh 7 years ago
parent
commit
7253f5e4dc
2 changed files with 132 additions and 115 deletions
  1. 17
    0
      test/test-0.9.4.js
  2. 115
    115
      test/test-firebase.js

+ 17
- 0
test/test-0.9.4.js View File

@@ -61,3 +61,20 @@ describe('issue #106', (report, done) => {
61 61
     })
62 62
 
63 63
 })
64
+
65
+describe('issue #111 get redirect destination', (report, done) => {
66
+  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
67
+  .then((res) => {
68
+    report(
69
+      <Assert key="redirect history should tracable"
70
+        expect={2}
71
+        actual={res.info().redirects.length}/>,
72
+      <Assert key="redirect history verify"
73
+        expect={[`${TEST_SERVER_URL}/redirect`, `${TEST_SERVER_URL}/public/github.png`]}
74
+        comparer={Comparer.equalToArray}
75
+        actual={res.info().redirects}/>,
76
+    )
77
+    done()
78
+  })
79
+
80
+})

+ 115
- 115
test/test-firebase.js View File

@@ -61,120 +61,120 @@ describe('firebase login', (report, done) => {
61 61
   })
62 62
 })
63 63
 
64
-// describe('upload file to firebase', (report, done) => {
65
-//
66
-//   let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
67
-//   RNTest.prop('firebase-image', testImage)
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')
73
-//     let task = storage
74
-//       .child(RNTest.prop('firebase-image'))
75
-//       .put(blob, { contentType : 'image/png' })
76
-//       .then((snapshot) => {
77
-//         console.log(snapshot.metadata)
78
-//         report(<Assert key="upload success"
79
-//           expect={true}
80
-//           actual={true}/>,
81
-//         <Info key="uploaded file stat" >
82
-//           <Text>{snapshot.totalBytes}</Text>
83
-//           <Text>{JSON.stringify(snapshot.metadata)}</Text>
84
-//         </Info>)
85
-//         done()
86
-//       })
87
-//   })
88
-// })
89
-//
90
-// describe('download firebase storage item', (report, done) => {
91
-//   let storage = firebase.storage().ref('rnfbtest/' + RNTest.prop('firebase-image'))
92
-//   storage.getDownloadURL().then((url) => {
93
-//     console.log(url)
94
-//     report(<Info key="image viewer">
95
-//       <Image style={styles.image} source={{uri : url}}/>
96
-//     </Info>)
97
-//     done()
98
-//   })
99
-// })
100
-//
101
-// let tier2FileName = `firebase-test-${Platform.OS}-github2.jpg`
102
-//
103
-// describe('upload using file path', (report, done) => {
104
-//   RNFetchBlob
105
-//     .config({ fileCache : true, appendExt : 'jpg' })
106
-//     .fetch('GET', `${TEST_SERVER_URL}/public/500k-img-dummy.jpg`)
107
-//     .then((resp) => {
108
-//       report(<Info key="test image">
109
-//         <Image style={styles.image} source={{uri : prefix + resp.path()}}/>
110
-//       </Info>)
111
-//       let blob = new Blob(RNFetchBlob.wrap(resp.path()), { type : 'image/jpg' })
112
-//       blob.onCreated(() => {
113
-//         firebase.storage().ref('rnfbtest')
114
-//           .child(tier2FileName)
115
-//           .put(blob, { contentType : 'image/jpg' })
116
-//           .then(() => {
117
-//             report(<Assert key="upload finished" />)
118
-//             done()
119
-//           })
120
-//       })
121
-//     })
122
-// })
123
-//
124
-// let directURL = null
125
-//
126
-// describe('verify uploaded file', (report, done) => {
127
-//   firebase.storage().ref('rnfbtest/' + tier2FileName)
128
-//     .getDownloadURL()
129
-//     .then((url) => {
130
-//       directURL = url
131
-//       report(
132
-//         <Info key="image viewer">
133
-//           <Image style={styles.image} source={{uri : url}}/>
134
-//         </Info>)
135
-//       done()
136
-//     })
137
-// })
138
-//
139
-// describe('download to base64', (report, done) => {
140
-//   RNFetchBlob.fetch('GET', directURL).then((resp) => {
141
-//     report(
142
-//       <Info key="image data">
143
-//         <Image
144
-//           style={styles.image}
145
-//           source={{uri : 'data:image/jpg;base64 ,'+ resp.base64()}}/>
146
-//       </Info>)
147
-//     done()
148
-//   })
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
-// })
64
+describe('upload file to firebase', (report, done) => {
65
+
66
+  let testImage = `firebase-test-${Platform.OS}-${Date.now()}.png`
67
+  RNTest.prop('firebase-image', testImage)
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')
73
+    let task = storage
74
+      .child(RNTest.prop('firebase-image'))
75
+      .put(blob, { contentType : 'image/png' })
76
+      .then((snapshot) => {
77
+        console.log(snapshot.metadata)
78
+        report(<Assert key="upload success"
79
+          expect={true}
80
+          actual={true}/>,
81
+        <Info key="uploaded file stat" >
82
+          <Text>{snapshot.totalBytes}</Text>
83
+          <Text>{JSON.stringify(snapshot.metadata)}</Text>
84
+        </Info>)
85
+        done()
86
+      })
87
+  })
88
+})
89
+
90
+describe('download firebase storage item', (report, done) => {
91
+  let storage = firebase.storage().ref('rnfbtest/' + RNTest.prop('firebase-image'))
92
+  storage.getDownloadURL().then((url) => {
93
+    console.log(url)
94
+    report(<Info key="image viewer">
95
+      <Image style={styles.image} source={{uri : url}}/>
96
+    </Info>)
97
+    done()
98
+  })
99
+})
100
+
101
+let tier2FileName = `firebase-test-${Platform.OS}-github2.jpg`
102
+
103
+describe('upload using file path', (report, done) => {
104
+  RNFetchBlob
105
+    .config({ fileCache : true, appendExt : 'jpg' })
106
+    .fetch('GET', `${TEST_SERVER_URL}/public/500k-img-dummy.jpg`)
107
+    .then((resp) => {
108
+      report(<Info key="test image">
109
+        <Image style={styles.image} source={{uri : prefix + resp.path()}}/>
110
+      </Info>)
111
+      return Blob.build(RNFetchBlob.wrap(resp.path()), { type : 'image/jpg' })
112
+    })
113
+    .then((blob) => {
114
+      return firebase.storage().ref('rnfbtest')
115
+        .child(tier2FileName)
116
+        .put(blob, { contentType : 'image/jpg' })
117
+    })
118
+    .then(() => {
119
+      report(<Assert key="upload finished" />)
120
+      done()
121
+    })
122
+})
123
+
124
+let directURL = null
125
+
126
+describe('verify uploaded file', (report, done) => {
127
+  firebase.storage().ref('rnfbtest/' + tier2FileName)
128
+    .getDownloadURL()
129
+    .then((url) => {
130
+      directURL = url
131
+      report(
132
+        <Info key="image viewer">
133
+          <Image style={styles.image} source={{uri : url}}/>
134
+        </Info>)
135
+      done()
136
+    })
137
+})
138
+
139
+describe('download to base64', (report, done) => {
140
+  RNFetchBlob.fetch('GET', directURL).then((resp) => {
141
+    report(
142
+      <Info key="image data">
143
+        <Image
144
+          style={styles.image}
145
+          source={{uri : 'data:image/jpg;base64 ,'+ resp.base64()}}/>
146
+      </Info>)
147
+    done()
148
+  })
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
+})
178 178
 
179 179
 describe('upload from CameraRoll', (report, done) => {
180 180
   let tmp = fs.dirs.DocumentDir + '/tmp'+Date.now()
@@ -192,7 +192,7 @@ describe('upload from CameraRoll', (report, done) => {
192 192
     .then((b) => {
193 193
       blob = b
194 194
       return firebase.storage()
195
-        .ref('rnfbtest').child('camra-roll.jpg')
195
+        .ref('rnfbtest').child(`camra-roll-${Platform.OS}-${Date.now()}.jpg`)
196 196
         .put(b, {contentType : 'image/jpg'})
197 197
     })
198 198
     .then((snapshot) => {