Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 856b1c4

Browse files
committed
Add test case #63
1 parent 468f0d7 commit 856b1c4

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

test/test-0.5.1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ describe('Upload and download at the same time', (report, done) => {
175175
actual += chunk
176176
})
177177
stream.onEnd(() => {
178+
console.log('###',actual)
178179
report(
179180
<Assert
180181
key="response data should be the filename"

test/test-0.5.2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ describe('POST request with params', (report, done) => {
7070
result += chunk
7171
})
7272
stream.onEnd(() => {
73+
console.log(result)
7374
result = JSON.parse(result)
7475
report(<Assert key="param#1 should correct"
7576
expect={parseInt(time)}

test/test-0.8.0.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const describe = RNTest.config({
2020
expand : true,
2121
timeout : 10000,
2222
})
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()
2424
const dirs = RNFetchBlob.fs.dirs
2525

2626
let prefix = ((Platform.OS === 'android') ? 'file://' : '')
@@ -56,7 +56,71 @@ describe('fs URI encoding support', (report, done) => {
5656
})
5757

5858
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+
})
60124
})
61125

62126
function getASCIIArray(str) {

0 commit comments

Comments
 (0)