Browse Source

Change test cases

Ben Hsieh 8 years ago
parent
commit
1653a0198f
3 changed files with 110 additions and 192 deletions
  1. 106
    100
      test/test-0.1.x-0.4.x.js
  2. 0
    87
      test/test-0.5.3.js
  3. 4
    5
      test/test-init.js

+ 106
- 100
test/test-0.1.x-0.4.x.js View File

@@ -19,44 +19,107 @@ const describe = RNTest.config({
19 19
 
20 20
 let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop()
21 21
 
22
-describe('The check if it follows 301/302 redirection', (report, done) => {
22
+// describe('The check if it follows 301/302 redirection', (report, done) => {
23
+//
24
+//   image = RNTest.prop('image')
25
+//
26
+//   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
27
+//   .then((resp) => {
28
+//     report(
29
+//       <Assert key="check image size" expect={image.length} actual={resp.base64().length}/>,
30
+//       <Info key="Response image">
31
+//         <Image
32
+//           style={{width:Dimensions.get('window').width*0.9, height : Dimensions.get('window').width*0.9,margin :16}}
33
+//           source={{uri : `data:image/png;base64, ${image}`}}/>
34
+//       </Info>)
35
+//       done()
36
+//   })
37
+//
38
+// })
39
+//
40
+// describe('Upload octet-stream image to Dropbox', (report, done) => {
41
+//
42
+//   RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
43
+//     Authorization : `Bearer ${DROPBOX_TOKEN}`,
44
+//     'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
45
+//     'Content-Type' : 'application/octet-stream',
46
+//   }, image)
47
+//   .then((resp) => {
48
+//     resp = resp.json()
49
+//     report(
50
+//       <Assert key="confirm the file has been uploaded" expect={FILENAME} actual={resp.name}/>
51
+//     )
52
+//     done()
53
+//   })
54
+//
55
+// })
56
+//
57
+// describe('Upload multipart/form-data', (report, done) => {
58
+//
59
+//   RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
60
+//       Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
61
+//       'Content-Type' : 'multipart/form-data',
62
+//     }, [
63
+//       { name : 'test-img', filename : 'test-img.png', data: image},
64
+//       { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
65
+//       { name : 'field1', data : 'hello !!'},
66
+//       { name : 'field2', data : 'hello2 !!'}
67
+//     ])
68
+//   .then((resp) => {
69
+//     resp = resp.json()
70
+//     report(
71
+//       <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
72
+//       <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
73
+//     )
74
+//     done()
75
+//   })
76
+//
77
+//
78
+// })
79
+//
80
+// describe('Compare uploaded multipart image', (report, done) => {
81
+//   let r1 = null
82
+//   RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
83
+//     .then((resp) => {
84
+//       r1 = resp
85
+//       return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
86
+//     })
87
+//     .then((resp) => {
88
+//       report(
89
+//         <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
90
+//         <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
91
+//       )
92
+//       done()
93
+//     })
94
+//
95
+// })
96
+//
97
+// // added after 0.4.2
98
+//
99
+// describe('Progress report test', (report, done) => {
100
+//   let actual = 0, expect = -1
101
+//   RNFetchBlob
102
+//     .fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
103
+//       Authorization : 'Bearer abde123eqweje'
104
+//     })
105
+//     .progress((received, total) => {
106
+//       actual = received
107
+//       expect = total
108
+//     })
109
+//     .then((resp) => {
110
+//       report(
111
+//         <Assert key="download progress correct" expect={expect} actual={actual}/>,
112
+//         <Assert key="response data should be correct event with progress listener"
113
+//           expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
114
+//       done()
115
+//     })
116
+//
117
+// })
23 118
 
24
-  image = RNTest.prop('image')
25 119
 
26
-  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`)
27
-  .then((resp) => {
28
-    report(
29
-      <Assert key="check image size" expect={image.length} actual={resp.base64().length}/>,
30
-      <Info key="Response image">
31
-        <Image
32
-          style={{width:Dimensions.get('window').width*0.9, height : Dimensions.get('window').width*0.9,margin :16}}
33
-          source={{uri : `data:image/png;base64, ${image}`}}/>
34
-      </Info>)
35
-      done()
36
-  })
37
-
38
-})
39
-
40
-describe('Upload octet-stream image to Dropbox', (report, done) => {
41
-
42
-  RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
43
-    Authorization : `Bearer ${DROPBOX_TOKEN}`,
44
-    'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
45
-    'Content-Type' : 'application/octet-stream',
46
-  }, image)
47
-  .then((resp) => {
48
-    resp = resp.json()
49
-    report(
50
-      <Assert key="confirm the file has been uploaded" expect={FILENAME} actual={resp.name}/>
51
-    )
52
-    done()
53
-  })
54
-
55
-})
56
-
57
-describe('Upload multipart/form-data', (report, done) => {
58
-
59
-  RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
120
+describe('PUT request test', (report, done) => {
121
+  let actual = 0, expect = -1
122
+  RNFetchBlob.fetch('PUT', `${TEST_SERVER_URL}/upload-form`, {
60 123
       Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
61 124
       'Content-Type' : 'multipart/form-data',
62 125
     }, [
@@ -65,76 +128,19 @@ describe('Upload multipart/form-data', (report, done) => {
65 128
       { name : 'field1', data : 'hello !!'},
66 129
       { name : 'field2', data : 'hello2 !!'}
67 130
     ])
68
-  .then((resp) => {
69
-    resp = resp.json()
70
-    report(
71
-      <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
72
-      <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
73
-    )
74
-    done()
75
-  })
76
-
77
-
78
-})
79
-
80
-describe('Compare uploaded multipart image', (report, done) => {
81
-  let r1 = null
82
-  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`)
83
-    .then((resp) => {
84
-      r1 = resp
85
-      return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`)
131
+    .progress((written, total) => {
132
+      actual = written
133
+      expect = total
86 134
     })
87 135
     .then((resp) => {
136
+      resp = resp.json()
88 137
       report(
89
-        <Assert key="check file length" expect={image.length} actual={r1.base64().length}/>,
90
-        <Assert key="check file content" expect={'hello.txt'} actual={resp.text()}/>
138
+        <Assert key="upload progress correct" expect={expect} actual={actual}/>,
139
+        <Assert key="check put form data #1" expect="hello !!" actual={resp.fields.field1}/>,
140
+        <Assert key="check put form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
91 141
       )
92 142
       done()
93 143
     })
94
-
95
-})
96
-
97
-// added after 0.4.2
98
-
99
-describe('Progress report test', (report, done) => {
100
-  let received = 0
101
-  RNFetchBlob
102
-    .fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, {
103
-      Authorization : 'Bearer abde123eqweje'
104
-    })
105
-    .progress((written, total) => {
106
-      // report(<Info key={`progress = ${written} bytes / ${total} bytes`}/>)
107
-      if(written === total)
108
-        report(<Assert key="progress goes to 100%" expect={written} actual={total}/>)
109
-    })
110
-    .then((resp) => {
111
-      report(<Assert key="response data should be correct event with progress listener"
112
-        expect={resp.text().substr(0,10)} actual={"1234567890"}/>)
113
-      done()
114
-    })
115
-
116
-})
117
-
118
-
119
-describe('PUT request test', (report, done) => {
120
-
121
-  RNFetchBlob.fetch('PUT', `${TEST_SERVER_URL}/upload-form`, {
122
-      Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz",
123
-      'Content-Type' : 'multipart/form-data',
124
-    }, [
125
-      { name : 'test-img', filename : 'test-img.png', data: image},
126
-      { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
127
-      { name : 'field1', data : 'hello !!'},
128
-      { name : 'field2', data : 'hello2 !!'}
129
-    ])
130
-  .then((resp) => {
131
-    resp = resp.json()
132
-    report(
133
-      <Assert key="check put form data #1" expect="hello !!" actual={resp.fields.field1}/>,
134
-      <Assert key="check put form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
135
-    )
136
-    done()
137
-  })
138 144
 })
139 145
 
140 146
 describe('DELETE request test', (report, done) => {

+ 0
- 87
test/test-0.5.3.js View File

@@ -1,87 +0,0 @@
1
-import RNTest from './react-native-testkit/'
2
-import React from 'react'
3
-import RNFetchBlob from 'react-native-fetch-blob'
4
-
5
-import {
6
-  StyleSheet,
7
-  Text,
8
-  View,
9
-  ScrollView,
10
-  Platform,
11
-  Dimensions,
12
-  Image,
13
-} from 'react-native';
14
-
15
-const fs = RNFetchBlob.fs
16
-const { Assert, Comparer, Info, prop } = RNTest
17
-const describe = RNTest.config({
18
-  group : '0.5.3',
19
-  run : true,
20
-  expand : false,
21
-})
22
-const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
23
-
24
-let prefix = ((Platform.OS === 'android') ? 'file://' : '')
25
-
26
-
27
-describe('GET request with params', (report, done) => {
28
-  let time = Date.now()
29
-  RNFetchBlob
30
-  .config({ fileCache : true, trusty : true })
31
-    .fetch('GET', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
32
-    .then((resp) => {
33
-      let file = resp.path()
34
-      return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
35
-    })
36
-    .then((stream) => {
37
-      let result = ''
38
-      stream.open()
39
-      stream.onData((chunk) => {
40
-        result += chunk
41
-      })
42
-      stream.onEnd(() => {
43
-        result = JSON.parse(result)
44
-        report(<Assert key="param#1 should correct"
45
-          expect={parseInt(time)}
46
-          actual={parseInt(result.time)}/>,
47
-        <Assert key="param#2 should correct"
48
-          expect={'RNFetchBlobParams'}
49
-          actual={result.name}/>,
50
-        <Assert key="param contains unicode data should correct"
51
-          expect={'中文'}
52
-          actual={result.lang}/>)
53
-          done()
54
-      })
55
-    })
56
-})
57
-
58
-
59
-describe('POST request with params', (report, done) => {
60
-  let time = Date.now()
61
-  RNFetchBlob.config({ fileCache : true, trusty : true })
62
-    .fetch('POST', `${TEST_SERVER_URL_SSL}/params?time=${time}&name=RNFetchBlobParams&lang=中文`)
63
-    .then((resp) => {
64
-      let file = resp.path()
65
-      return RNFetchBlob.fs.readStream(resp.path(), 'utf8')
66
-    })
67
-    .then((stream) => {
68
-      let result = ''
69
-      stream.open()
70
-      stream.onData((chunk) => {
71
-        result += chunk
72
-      })
73
-      stream.onEnd(() => {
74
-        result = JSON.parse(result)
75
-        report(<Assert key="param#1 should correct"
76
-          expect={parseInt(time)}
77
-          actual={parseInt(result.time)}/>,
78
-        <Assert key="param#2 should correct"
79
-          expect={'RNFetchBlobParams'}
80
-          actual={result.name}/>,
81
-        <Assert key="param contains unicode data should correct"
82
-          expect={'中文'}
83
-          actual={result.lang}/>)
84
-          done()
85
-      })
86
-    })
87
-})

+ 4
- 5
test/test-init.js View File

@@ -17,9 +17,9 @@ const { Assert, Comparer, Info, describe, prop } = RNTest
17 17
 
18 18
 // test environment variables
19 19
 
20
-prop('FILENAME', `${Platform.OS}-0.6.0-${Date.now()}.png`)
21
-prop('TEST_SERVER_URL', 'http://192.168.16.70:8123')
22
-prop('TEST_SERVER_URL_SSL', 'https://192.168.16.70:8124')
20
+prop('FILENAME', `${Platform.OS}-0.7.0-${Date.now()}.png`)
21
+prop('TEST_SERVER_URL', 'http://192.168.0.11:8123')
22
+prop('TEST_SERVER_URL_SSL', 'https://192.168.0.11:8124')
23 23
 prop('DROPBOX_TOKEN', 'fsXcpmKPrHgAAAAAAAAAoXZhcXYWdgLpQMan6Tb_bzJ237DXhgQSev12hA-gUXt4')
24 24
 prop('styles', {
25 25
   image : {
@@ -54,7 +54,6 @@ describe('GET image from server', (report, done) => {
54 54
 require('./test-0.1.x-0.4.x')
55 55
 require('./test-0.5.1')
56 56
 require('./test-0.5.2')
57
-require('./test-0.5.3')
58 57
 require('./test-0.6.0')
59 58
 require('./test-fs')
60
-require('./test-android')
59
+// require('./test-android')