@@ -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 commit comments