|
@@ -55,124 +55,124 @@ 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
|
+
|
|
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
|
+})
|
176
|
176
|
|
177
|
177
|
describe('Check custom MIME type correctness',(report, done) => {
|
178
|
178
|
RNFetchBlob
|