@@ -19,102 +19,102 @@ 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) => {
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
- // })
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
+ } )
118
118
119
119
120
120
describe ( 'PUT request test' , ( report , done ) => {
0 commit comments