Przeglądaj źródła

Add test case and test server API fro #249 #230 cookie manipulation

Ben Hsieh 7 lat temu
rodzic
commit
bec79ef9c6
3 zmienionych plików z 86 dodań i 2 usunięć
  1. 7
    1
      test-server/server.js
  2. 77
    0
      test/test-0.10.3.js
  3. 2
    1
      test/test-init.js

+ 7
- 1
test-server/server.js Wyświetl plik

@@ -234,10 +234,16 @@ app.all('/long/', (req, res) => {  var count = 0;
234 234
 })
235 235
 
236 236
 app.all('/cookie/:data', (req, res) => {
237
-  res.cookie('cookieName', req.params.data);
237
+  for(var i =0;i<10;i++) {
238
+    res.cookie('cookie'+i, req.params.data);
239
+  }
238 240
   res.end()
239 241
 })
240 242
 
243
+app.all('/cookie-echo', (req, res) => {
244
+  res.send(req.headers.cookie)
245
+})
246
+
241 247
 app.all('/err-body', (req, res) => {
242 248
   res.status(400)
243 249
   res.write(JSON.stringify({ data : Date.now() }))

+ 77
- 0
test/test-0.10.3.js Wyświetl plik

@@ -0,0 +1,77 @@
1
+import RNTest from './react-native-testkit/'
2
+import React from 'react'
3
+import _ from 'lodash'
4
+import RNFetchBlob from 'react-native-fetch-blob'
5
+import {
6
+  StyleSheet,
7
+  Text,
8
+  View,
9
+  ScrollView,
10
+  Linking,
11
+  Platform,
12
+  Dimensions,
13
+  BackAndroid,
14
+  AsyncStorage,
15
+  Image,
16
+} from 'react-native';
17
+
18
+window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
19
+window.Blob = RNFetchBlob.polyfill.Blob
20
+
21
+const JSONStream = RNFetchBlob.JSONStream
22
+const fs = RNFetchBlob.fs
23
+const { Assert, Comparer, Info, prop } = RNTest
24
+const describe = RNTest.config({
25
+  group : '0.10.3',
26
+  run : true,
27
+  expand : true,
28
+  timeout : 20000,
29
+})
30
+const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop()
31
+const dirs = RNFetchBlob.fs.dirs
32
+let prefix = ((Platform.OS === 'android') ? 'file://' : '')
33
+let begin = Date.now()
34
+
35
+
36
+describe('#230 #249 cookies manipulation', (report, done) => {
37
+
38
+  RNFetchBlob
39
+  .fetch('GET', `${TEST_SERVER_URL}/cookie/249230`)
40
+  .then((res) => RNFetchBlob.net.getCookies())
41
+  .then((cookies) => {
42
+    console.log(cookies)
43
+    report(<Assert
44
+      key="should set 10 cookies"
45
+      expect={10}
46
+      actual={cookies['localhost'].length}/>)
47
+    return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
48
+  })
49
+  .then((res) => {
50
+    console.log(res.data)
51
+    let cookies = String(res.data).split(';')
52
+    report(<Assert
53
+      key="should send 10 cookies"
54
+      expect={10}
55
+      actual={cookies.length}/>)
56
+    return RNFetchBlob.net.removeCookies()
57
+  })
58
+  .then(() => RNFetchBlob.net.getCookies('localhost'))
59
+  .then((cookies) => {
60
+    report(<Assert
61
+      key="should have no cookies"
62
+      expect={undefined}
63
+      actual={cookies['localhost']}/>)
64
+    return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`)
65
+  })
66
+  .then((res) => {
67
+    console.log(res.data)
68
+    let cookies = String(res.data).split(';')
69
+    cookies = _.reject(cookies, r => r.length < 2)
70
+    report(<Assert
71
+      key="should send no cookies"
72
+      expect={0}
73
+      actual={cookies.length}/>)
74
+    done()
75
+  })
76
+
77
+})

+ 2
- 1
test/test-init.js Wyświetl plik

@@ -96,7 +96,8 @@ describe('GET image from server', (report, done) => {
96 96
 // require('./test-0.9.6')
97 97
 // require('./test-0.10.0')
98 98
 // require('./test-0.10.1')
99
-require('./test-0.10.2')
99
+// require('./test-0.10.2')
100
+require('./test-0.10.3')
100 101
 // require('./test-background.js')
101 102
 // require('./test-stream')
102 103
 // require('./test-fetch')