Quellcode durchsuchen

Add test cases for #33

Ben Hsieh vor 8 Jahren
Ursprung
Commit
881c8fb078
2 geänderte Dateien mit 42 neuen und 2 gelöschten Zeilen
  1. 11
    2
      test-server/server.js
  2. 31
    0
      test/test-0.1.x-0.4.x.js

+ 11
- 2
test-server/server.js Datei anzeigen

@@ -79,8 +79,17 @@ app.all('/params', function(req, res) {
79 79
 app.all('/empty', function(req, res) {
80 80
   res.send('')
81 81
 })
82
+
83
+app.delete('/hey', function(req, res) {
84
+  res.send('man')
85
+})
86
+
82 87
 // handle multipart/form-data request
83
-app.post('/upload-form', function(req, res) {
88
+app.post('/upload-form', formUpload)
89
+
90
+app.put('/upload-form', formUpload)
91
+
92
+function formUpload(req, res) {
84 93
   console.log(req.headers)
85 94
   console.log(req.body)
86 95
   console.log(req.files)
@@ -94,7 +103,7 @@ app.post('/upload-form', function(req, res) {
94 103
     fields : req.body,
95 104
     files : req.files
96 105
   })
97
-})
106
+}
98 107
 
99 108
 function watch(source, dest, ignore) {
100 109
   // watch files in  test folder

+ 31
- 0
test/test-0.1.x-0.4.x.js Datei anzeigen

@@ -114,3 +114,34 @@ describe('Progress report test', (report, done) => {
114 114
     })
115 115
 
116 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
+})
139
+
140
+describe('DELETE request test', (report, done) => {
141
+  RNFetchBlob.fetch('DELETE', `${TEST_SERVER_URL}/hey`)
142
+  .then((resp) => {
143
+    report(
144
+      <Assert key="check DELETE request result" expect={'man'} actual={resp.text()}/>,
145
+      done()
146
+  })
147
+})