|
@@ -55,134 +55,149 @@ describe('upload asset from camera roll', (report, done) => {
|
55
|
55
|
done()
|
56
|
56
|
})
|
57
|
57
|
})
|
|
58
|
+//
|
|
59
|
+// describe('Upload multipart data with file from CameraRoll', (report, done) => {
|
|
60
|
+// let filename = 'test-from-storage-img-'+Date.now()+'.png'
|
|
61
|
+// RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
|
|
62
|
+// 'Content-Type' : 'multipart/form-data',
|
|
63
|
+// }, [
|
|
64
|
+// { name : 'test-img', filename : filename, data: RNFetchBlob.wrap(photo)},
|
|
65
|
+// { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
|
|
66
|
+// { name : 'field1', data : 'hello !!'},
|
|
67
|
+// { name : 'field2', data : 'hello2 !!'}
|
|
68
|
+// ])
|
|
69
|
+// .then((resp) => {
|
|
70
|
+// resp = resp.json()
|
|
71
|
+// report(
|
|
72
|
+// <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
|
|
73
|
+// <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
|
|
74
|
+// )
|
|
75
|
+// return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
|
|
76
|
+// })
|
|
77
|
+// .then((resp) => {
|
|
78
|
+// report(<Info key="uploaded image">
|
|
79
|
+// <Image
|
|
80
|
+// style={styles.image}
|
|
81
|
+// source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
|
|
82
|
+// </Info>)
|
|
83
|
+// done()
|
|
84
|
+// })
|
|
85
|
+// })
|
|
86
|
+//
|
|
87
|
+//
|
|
88
|
+// describe('access assets from camera roll', (report, done) => {
|
|
89
|
+// let photo = null
|
|
90
|
+// CameraRoll.getPhotos({first : 10})
|
|
91
|
+// .then((resp) => {
|
|
92
|
+// photo = resp.edges[0].node.image.uri
|
|
93
|
+// report(<Info key="items">
|
|
94
|
+// <Text>{photo}</Text>
|
|
95
|
+// </Info>)
|
|
96
|
+// return fs.readFile(photo, 'base64')
|
|
97
|
+// })
|
|
98
|
+// .then((data) => {
|
|
99
|
+// report(<Info key="asset image">
|
|
100
|
+// <Image
|
|
101
|
+// style={styles.image}
|
|
102
|
+// source={{uri: `data:image/png;base64, ${data}`}}/>
|
|
103
|
+// </Info>)
|
|
104
|
+// done()
|
|
105
|
+// })
|
|
106
|
+// })
|
|
107
|
+//
|
|
108
|
+// describe('read asset in app bundle',(report, done) => {
|
|
109
|
+// let target = fs.asset('test-asset2.png')
|
|
110
|
+// fs.readFile(target, 'base64')
|
|
111
|
+// .then((data) => {
|
|
112
|
+// report(<Info key="asset image">
|
|
113
|
+// <Image
|
|
114
|
+// style={styles.image}
|
|
115
|
+// source={{uri: `data:image/png;base64, ${data}`}}/>
|
|
116
|
+// </Info>)
|
|
117
|
+// return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
|
|
118
|
+// })
|
|
119
|
+// .then((resp) => {
|
|
120
|
+// report(
|
|
121
|
+// <Assert key="asset content verify"
|
|
122
|
+// expect="asset#1"
|
|
123
|
+// actual={JSON.parse(resp).secret}/>)
|
|
124
|
+// done()
|
|
125
|
+// })
|
|
126
|
+// })
|
|
127
|
+//
|
|
128
|
+// describe('stat assets in app', (report, done) => {
|
|
129
|
+// fs.stat(fs.asset('test-asset2.png'))
|
|
130
|
+// .then((data) => {
|
|
131
|
+// report(<Info key="list of assets">
|
|
132
|
+// <Text>{JSON.stringify(data)}</Text>
|
|
133
|
+// </Info>)
|
|
134
|
+// done()
|
|
135
|
+// })
|
|
136
|
+// })
|
|
137
|
+//
|
|
138
|
+// describe('copy asset', (report, done) => {
|
|
139
|
+// let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
|
|
140
|
+// fs.cp(fs.asset('test-asset1.json'), dest)
|
|
141
|
+// .then(() => fs.readFile(dest, 'utf8'))
|
|
142
|
+// .then((data) => {
|
|
143
|
+// report(<Assert key="asset copied correctly"
|
|
144
|
+// expect={'asset#1'}
|
|
145
|
+// actual={JSON.parse(data).secret}/>)
|
|
146
|
+// return fs.stat(fs.asset('test-asset1.json'))
|
|
147
|
+// })
|
|
148
|
+// .then((stat) => {
|
|
149
|
+// report(<Assert key="file size check"
|
|
150
|
+// expect={27}
|
|
151
|
+// actual={Math.floor(stat.size)}/>,
|
|
152
|
+// <Info key="dest file info">
|
|
153
|
+// <Text>{JSON.stringify(stat)}</Text>
|
|
154
|
+// </Info>)
|
|
155
|
+// done()
|
|
156
|
+// })
|
|
157
|
+// })
|
|
158
|
+//
|
|
159
|
+//
|
|
160
|
+// describe('upload file from assets',(report, done) => {
|
|
161
|
+// let assetName = fs.asset('test-asset1.json')
|
|
162
|
+// RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
|
163
|
+// Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
|
164
|
+// 'Dropbox-API-Arg': `{\"path\": \"/rn-upload/file-from-asset-${Platform.OS}.json\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
|
|
165
|
+// 'Content-Type' : 'application/octet-stream',
|
|
166
|
+// }, RNFetchBlob.wrap(assetName))
|
|
167
|
+// .then((resp) => {
|
|
168
|
+// resp = resp.json()
|
|
169
|
+// report(
|
|
170
|
+// <Assert key="file name check"
|
|
171
|
+// expect={`file-from-asset-${Platform.OS}.json`}
|
|
172
|
+// actual={resp.name}/>)
|
|
173
|
+// done()
|
|
174
|
+// })
|
|
175
|
+// })
|
58
|
176
|
|
59
|
|
-describe('Upload multipart data with file from CameraRoll', (report, done) => {
|
60
|
|
- let filename = 'test-from-storage-img-'+Date.now()+'.png'
|
61
|
|
- RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
|
62
|
|
- 'Content-Type' : 'multipart/form-data',
|
63
|
|
- }, [
|
64
|
|
- { name : 'test-img', filename : filename, data: RNFetchBlob.wrap(photo)},
|
65
|
|
- { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
|
66
|
|
- { name : 'field1', data : 'hello !!'},
|
67
|
|
- { name : 'field2', data : 'hello2 !!'}
|
68
|
|
- ])
|
69
|
|
- .then((resp) => {
|
70
|
|
- resp = resp.json()
|
71
|
|
- report(
|
72
|
|
- <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
|
73
|
|
- <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
|
74
|
|
- )
|
75
|
|
- return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
|
76
|
|
- })
|
77
|
|
- .then((resp) => {
|
78
|
|
- report(<Info key="uploaded image">
|
79
|
|
- <Image
|
80
|
|
- style={styles.image}
|
81
|
|
- source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
|
82
|
|
- </Info>)
|
83
|
|
- done()
|
84
|
|
- })
|
85
|
|
-})
|
86
|
|
-
|
87
|
|
-
|
88
|
|
-describe('access assets from camera roll', (report, done) => {
|
89
|
|
- let photo = null
|
90
|
|
- CameraRoll.getPhotos({first : 10})
|
91
|
|
- .then((resp) => {
|
92
|
|
- photo = resp.edges[0].node.image.uri
|
93
|
|
- report(<Info key="items">
|
94
|
|
- <Text>{photo}</Text>
|
95
|
|
- </Info>)
|
96
|
|
- return fs.readFile(photo, 'base64')
|
97
|
|
- })
|
98
|
|
- .then((data) => {
|
99
|
|
- report(<Info key="asset image">
|
100
|
|
- <Image
|
101
|
|
- style={styles.image}
|
102
|
|
- source={{uri: `data:image/png;base64, ${data}`}}/>
|
103
|
|
- </Info>)
|
104
|
|
- done()
|
105
|
|
- })
|
106
|
|
-})
|
107
|
|
-
|
108
|
|
-describe('read asset in app bundle',(report, done) => {
|
109
|
|
- let target = fs.asset('test-asset2.png')
|
110
|
|
- fs.readFile(target, 'base64')
|
111
|
|
- .then((data) => {
|
112
|
|
- report(<Info key="asset image">
|
113
|
|
- <Image
|
114
|
|
- style={styles.image}
|
115
|
|
- source={{uri: `data:image/png;base64, ${data}`}}/>
|
116
|
|
- </Info>)
|
117
|
|
- return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
|
118
|
|
- })
|
|
177
|
+describe('Check custom MIME type correctness',(report, done) => {
|
|
178
|
+ RNFetchBlob
|
|
179
|
+ .config({fileCache : true})
|
|
180
|
+ .fetch('GET', `${TEST_SERVER_URL}/public/beethoven.mp3`)
|
119
|
181
|
.then((resp) => {
|
120
|
|
- report(
|
121
|
|
- <Assert key="asset content verify"
|
122
|
|
- expect="asset#1"
|
123
|
|
- actual={JSON.parse(resp).secret}/>)
|
124
|
|
- done()
|
|
182
|
+ return RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/mime`, null, [
|
|
183
|
+ { name : 'image', filename : 'image', type : 'image/jpeg', data : RNFetchBlob.base64.encode('123456') },
|
|
184
|
+ { name : 'mp3', filename : 'mp3', type : 'application/mp3', data : RNFetchBlob.base64.encode('123456') },
|
|
185
|
+ { name : 'mp3', filename : 'mp3', data : RNFetchBlob.base64.encode('123456') },
|
|
186
|
+ { name : 'asset', filename : 'asset.json', type: 'application/json', data : RNFetchBlob.wrap(fs.asset('test-asset1.json')) },
|
|
187
|
+ { name : 'camera-roll', filename : 'cameraRoll.png', type: 'image/png', data : RNFetchBlob.wrap(photo) },
|
|
188
|
+ { name : 'storage', filename : 'storage.mp3', type: 'application/mp3', data : RNFetchBlob.wrap(resp.path()) },
|
|
189
|
+ ])
|
125
|
190
|
})
|
126
|
|
-})
|
127
|
|
-
|
128
|
|
-describe('stat assets in app', (report, done) => {
|
129
|
|
- fs.stat(fs.asset('test-asset2.png'))
|
130
|
|
- .then((data) => {
|
131
|
|
- report(<Info key="list of assets">
|
132
|
|
- <Text>{JSON.stringify(data)}</Text>
|
133
|
|
- </Info>)
|
134
|
|
- done()
|
135
|
|
- })
|
136
|
|
-})
|
137
|
|
-
|
138
|
|
-describe('copy asset', (report, done) => {
|
139
|
|
- let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
|
140
|
|
- fs.cp(fs.asset('test-asset1.json'), dest)
|
141
|
|
- .then(() => fs.readFile(dest, 'utf8'))
|
142
|
|
- .then((data) => {
|
143
|
|
- report(<Assert key="asset copied correctly"
|
144
|
|
- expect={'asset#1'}
|
145
|
|
- actual={JSON.parse(data).secret}/>)
|
146
|
|
- return fs.stat(fs.asset('test-asset1.json'))
|
147
|
|
- })
|
148
|
|
- .then((stat) => {
|
149
|
|
- report(<Assert key="file size check"
|
150
|
|
- expect={27}
|
151
|
|
- actual={Math.floor(stat.size)}/>,
|
152
|
|
- <Info key="dest file info">
|
153
|
|
- <Text>{JSON.stringify(stat)}</Text>
|
154
|
|
- </Info>)
|
155
|
|
- done()
|
156
|
|
- })
|
157
|
|
-})
|
158
|
|
-
|
159
|
|
-
|
160
|
|
-describe('upload file from assets',(report, done) => {
|
161
|
|
- let assetName = fs.asset('test-asset1.json')
|
162
|
|
- RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
|
163
|
|
- Authorization : `Bearer ${DROPBOX_TOKEN}`,
|
164
|
|
- 'Dropbox-API-Arg': `{\"path\": \"/rn-upload/file-from-asset-${Platform.OS}.json\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
|
165
|
|
- 'Content-Type' : 'application/octet-stream',
|
166
|
|
- }, RNFetchBlob.wrap(assetName))
|
167
|
191
|
.then((resp) => {
|
168
|
192
|
resp = resp.json()
|
169
|
193
|
report(
|
170
|
|
- <Assert key="file name check"
|
171
|
|
- expect={`file-from-asset-${Platform.OS}.json`}
|
172
|
|
- actual={resp.name}/>)
|
173
|
|
- done()
|
174
|
|
- })
|
175
|
|
-})
|
176
|
|
-
|
177
|
|
-describe('Check custom MIME type correctness',(report, done) => {
|
178
|
|
- RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/mime`, null, [
|
179
|
|
- { name : 'image', filename : 'image', type : 'image/jpeg', data : RNFetchBlob.base64.encode('123456') },
|
180
|
|
- { name : 'mp3', filename : 'mp3', type : 'application/mp3', data : RNFetchBlob.base64.encode('123456') },
|
181
|
|
- { name : 'mp3', filename : 'mp3', data : RNFetchBlob.base64.encode('123456') }
|
182
|
|
- ])
|
183
|
|
- .then((resp) => {
|
184
|
|
- resp = resp.json()
|
185
|
|
- report(<Assert key="check first mime" expect={'image/jpeg'} actual={resp[0]} />)
|
|
194
|
+ <Assert key="check #1 mime" expect={'image/jpeg'} actual={resp[0]} />,
|
|
195
|
+ <Assert key="check #2 mime" expect={'application/mp3'} actual={resp[1]} />,
|
|
196
|
+ <Assert key="check #3 mime" expect={'application/octet-stream'} actual={resp[2]} />,
|
|
197
|
+ <Assert key="check #4 mime" expect={'application/json'} actual={resp[3]} />,
|
|
198
|
+ <Assert key="check #5 mime" expect={'image/png'} actual={resp[4]} />,
|
|
199
|
+ <Assert key="check #6 mime" expect={'application/mp3'} actual={resp[5]} />,
|
|
200
|
+ )
|
186
|
201
|
done()
|
187
|
202
|
})
|
188
|
203
|
})
|