Ben Hsieh преди 8 години
родител
ревизия
856b1c4027
променени са 3 файла, в които са добавени 68 реда и са изтрити 2 реда
  1. 1
    0
      test/test-0.5.1.js
  2. 1
    0
      test/test-0.5.2.js
  3. 66
    2
      test/test-0.8.0.js

+ 1
- 0
test/test-0.5.1.js Целия файл

@@ -175,6 +175,7 @@ describe('Upload and download at the same time', (report, done) => {
175 175
         actual += chunk
176 176
       })
177 177
       stream.onEnd(() => {
178
+        console.log('###',actual)
178 179
         report(
179 180
           <Assert
180 181
             key="response data should be the filename"

+ 1
- 0
test/test-0.5.2.js Целия файл

@@ -70,6 +70,7 @@ describe('POST request with params', (report, done) => {
70 70
         result += chunk
71 71
       })
72 72
       stream.onEnd(() => {
73
+        console.log(result)
73 74
         result = JSON.parse(result)
74 75
         report(<Assert key="param#1 should correct"
75 76
           expect={parseInt(time)}

+ 66
- 2
test/test-0.8.0.js Целия файл

@@ -20,7 +20,7 @@ const describe = RNTest.config({
20 20
   expand : true,
21 21
   timeout : 10000,
22 22
 })
23
-const { TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
23
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
24 24
 const  dirs = RNFetchBlob.fs.dirs
25 25
 
26 26
 let prefix = ((Platform.OS === 'android') ? 'file://' : '')
@@ -56,7 +56,71 @@ describe('fs URI encoding support', (report, done) => {
56 56
 })
57 57
 
58 58
 describe('request timeout working properly', (report, done) => {
59
-  done()
59
+  RNFetchBlob.config({ timeout : 1 })
60
+  .fetch('GET', `${TEST_SERVER_URL}/timeout`)
61
+  .then(() => {
62
+    report(
63
+      <Assert
64
+        key="should not execute successfully"
65
+        expect={true}
66
+        actual={false}/>)
67
+    done()
68
+  })
69
+  .catch((err) => {
70
+    report(
71
+      <Assert
72
+        key="expect timeout error"
73
+        expect={true}
74
+        actual={/timed out/ig.test(err)}/>)
75
+    done()
76
+  })
77
+})
78
+
79
+describe('regular request should have correct body', (report, done) => {
80
+  RNFetchBlob
81
+  .fetch('POST', `${TEST_SERVER_URL}/echo`, {
82
+    'content-type' :  'text/foo',
83
+    foo : 'bar'
84
+  }, 'foo is bar')
85
+  .then((res) => {
86
+    report(
87
+      <Assert key="check headers"
88
+        expect={'bar'}
89
+        actual={res.json().headers.foo}/>,
90
+      <Assert key="check content type"
91
+        expect={'text/foo'}
92
+        actual={res.json().headers['content-type']}/>,
93
+      <Assert key="check body"
94
+        expect={'foo is bar'}
95
+        actual={res.json().body}/>)
96
+    done()
97
+  })
98
+})
99
+
100
+describe('automatic content conversion test', (report, done) => {
101
+    let expect1 = `test-alpha-${Date.now()}`
102
+    let expect2 = `test-beta-${Date.now()}`
103
+
104
+    RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/echo`, {
105
+      'Content-Type' : 'application/octet-foo',
106
+    }, RNFetchBlob.base64.encode(expect1))
107
+    .then((res) => {
108
+      report(
109
+        <Assert key="request body should be decoded by BASE64 decoder"
110
+          expect={expect1}
111
+          actual={res.json().body}/>)
112
+      return fs.writeFile(dirs.DocumentDir + '/test-0.8.0-auto', expect2, 'utf8')
113
+    })
114
+    .then(() => RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/echo`, {
115
+        /* what ever the header is */
116
+    }, RNFetchBlob.wrap(dirs.DocumentDir + '/test-0.8.0-auto')))
117
+    .then((resp) => {
118
+      report(
119
+        <Assert key="request body should send from storage"
120
+          expect={expect2}
121
+          actual={resp.json().body}/>)
122
+      done()
123
+    })
60 124
 })
61 125
 
62 126
 function getASCIIArray(str) {