|  | @@ -21,24 +21,23 @@ const describe = RNTest.config({
 | 
	
		
			
			| 21 | 21 |    expand : false,
 | 
	
		
			
			| 22 | 22 |    timeout : 12000,
 | 
	
		
			
			| 23 | 23 |  })
 | 
	
		
			
			| 24 |  | -const { TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
 | 
	
		
			
			|  | 24 | +const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, DROPBOX_TOKEN, styles } = prop()
 | 
	
		
			
			| 25 | 25 |  const  dirs = RNFetchBlob.fs.dirs
 | 
	
		
			
			| 26 | 26 |  
 | 
	
		
			
			| 27 | 27 |  let prefix = ((Platform.OS === 'android') ? 'file://' : '')
 | 
	
		
			
			|  | 28 | +let photo = null
 | 
	
		
			
			| 28 | 29 |  
 | 
	
		
			
			| 29 | 30 |  describe('upload asset from camera roll', (report, done) => {
 | 
	
		
			
			| 30 | 31 |    let imgName = `image-from-camera-roll-${Platform.OS}.jpg`
 | 
	
		
			
			| 31 | 32 |    CameraRoll.getPhotos({first : 10})
 | 
	
		
			
			| 32 | 33 |      .then((resp) => {
 | 
	
		
			
			| 33 | 34 |        let url = resp.edges[0].node.image.uri
 | 
	
		
			
			| 34 |  | -      return fs.readFile(url, 'base64')
 | 
	
		
			
			| 35 |  | -    })
 | 
	
		
			
			| 36 |  | -    .then((data) => {
 | 
	
		
			
			|  | 35 | +      photo = url
 | 
	
		
			
			| 37 | 36 |        return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
 | 
	
		
			
			| 38 | 37 |          Authorization : `Bearer ${DROPBOX_TOKEN}`,
 | 
	
		
			
			| 39 | 38 |          'Dropbox-API-Arg': `{\"path\": \"/rn-upload/${imgName}\",\"mode\": \"add\",\"autorename\": false,\"mute\": false}`,
 | 
	
		
			
			| 40 | 39 |          'Content-Type' : 'application/octet-stream',
 | 
	
		
			
			| 41 |  | -      }, data)
 | 
	
		
			
			|  | 40 | +      }, RNFetchBlob.wrap(url))
 | 
	
		
			
			| 42 | 41 |      })
 | 
	
		
			
			| 43 | 42 |      .then((resp) => {
 | 
	
		
			
			| 44 | 43 |        resp = resp.json()
 | 
	
	
		
			
			|  | @@ -47,76 +46,104 @@ describe('upload asset from camera roll', (report, done) => {
 | 
	
		
			
			| 47 | 46 |        )
 | 
	
		
			
			| 48 | 47 |        done()
 | 
	
		
			
			| 49 | 48 |      })
 | 
	
		
			
			| 50 |  | -
 | 
	
		
			
			| 51 | 49 |  })
 | 
	
		
			
			| 52 | 50 |  
 | 
	
		
			
			| 53 |  | -describe('access assets from camera roll', (report, done) => {
 | 
	
		
			
			| 54 |  | -  let photo = null
 | 
	
		
			
			| 55 |  | -  CameraRoll.getPhotos({first : 10})
 | 
	
		
			
			|  | 51 | +describe('Upload multipart data with file from CameraRoll', (report, done) => {
 | 
	
		
			
			|  | 52 | +    let filename = 'test-from-storage-img-'+Date.now()+'.png'
 | 
	
		
			
			|  | 53 | +    RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, {
 | 
	
		
			
			|  | 54 | +        'Content-Type' : 'multipart/form-data',
 | 
	
		
			
			|  | 55 | +      }, [
 | 
	
		
			
			|  | 56 | +        { name : 'test-img', filename : filename, data: RNFetchBlob.wrap(photo)},
 | 
	
		
			
			|  | 57 | +        { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')},
 | 
	
		
			
			|  | 58 | +        { name : 'field1', data : 'hello !!'},
 | 
	
		
			
			|  | 59 | +        { name : 'field2', data : 'hello2 !!'}
 | 
	
		
			
			|  | 60 | +      ])
 | 
	
		
			
			| 56 | 61 |      .then((resp) => {
 | 
	
		
			
			| 57 |  | -      photo = resp.edges[0].node.image.uri
 | 
	
		
			
			| 58 |  | -      report(<Info key="items">
 | 
	
		
			
			| 59 |  | -        <Text>{photo}</Text>
 | 
	
		
			
			| 60 |  | -      </Info>)
 | 
	
		
			
			| 61 |  | -      return fs.readFile(photo, 'base64')
 | 
	
		
			
			|  | 62 | +      resp = resp.json()
 | 
	
		
			
			|  | 63 | +      report(
 | 
	
		
			
			|  | 64 | +        <Assert key="check posted form data #1" expect="hello !!" actual={resp.fields.field1}/>,
 | 
	
		
			
			|  | 65 | +        <Assert key="check posted form data #2" expect="hello2 !!" actual={resp.fields.field2}/>,
 | 
	
		
			
			|  | 66 | +      )
 | 
	
		
			
			|  | 67 | +      return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/${filename}`)
 | 
	
		
			
			| 62 | 68 |      })
 | 
	
		
			
			| 63 |  | -    .then((data) => {
 | 
	
		
			
			| 64 |  | -      report(<Info key="asset image">
 | 
	
		
			
			|  | 69 | +    .then((resp) => {
 | 
	
		
			
			|  | 70 | +      report(<Info key="uploaded image">
 | 
	
		
			
			| 65 | 71 |          <Image
 | 
	
		
			
			| 66 | 72 |            style={styles.image}
 | 
	
		
			
			| 67 |  | -          source={{uri: `data:image/png;base64, ${data}`}}/>
 | 
	
		
			
			|  | 73 | +          source={{ uri : 'data:image/png;base64, '+ resp.base64()}}/>
 | 
	
		
			
			| 68 | 74 |        </Info>)
 | 
	
		
			
			| 69 | 75 |        done()
 | 
	
		
			
			| 70 | 76 |      })
 | 
	
		
			
			| 71 | 77 |  })
 | 
	
		
			
			| 72 | 78 |  
 | 
	
		
			
			| 73 |  | -describe('read asset in app bundle',(report, done) => {
 | 
	
		
			
			| 74 |  | -  let target = fs.asset('test-asset2.png')
 | 
	
		
			
			| 75 |  | -  fs.readFile(target, 'base64')
 | 
	
		
			
			| 76 |  | -  .then((data) => {
 | 
	
		
			
			| 77 |  | -    report(<Info key="asset image">
 | 
	
		
			
			| 78 |  | -      <Image
 | 
	
		
			
			| 79 |  | -        style={styles.image}
 | 
	
		
			
			| 80 |  | -        source={{uri: `data:image/png;base64, ${data}`}}/>
 | 
	
		
			
			| 81 |  | -    </Info>)
 | 
	
		
			
			| 82 |  | -    return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
 | 
	
		
			
			| 83 |  | -  })
 | 
	
		
			
			| 84 |  | -  .then((resp) => {
 | 
	
		
			
			| 85 |  | -    report(
 | 
	
		
			
			| 86 |  | -      <Assert key="asset content verify"
 | 
	
		
			
			| 87 |  | -        expect="asset#1"
 | 
	
		
			
			| 88 |  | -        actual={JSON.parse(resp).secret}/>)
 | 
	
		
			
			| 89 |  | -      done()
 | 
	
		
			
			| 90 |  | -  })
 | 
	
		
			
			| 91 |  | -})
 | 
	
		
			
			| 92 |  | -
 | 
	
		
			
			| 93 |  | -describe('stat assets in app', (report, done) => {
 | 
	
		
			
			| 94 |  | -  fs.stat(fs.asset('test-asset2.png'))
 | 
	
		
			
			| 95 |  | -    .then((data) => {
 | 
	
		
			
			| 96 |  | -      report(<Info key="list of assets">
 | 
	
		
			
			| 97 |  | -        <Text>{JSON.stringify(data)}</Text>
 | 
	
		
			
			| 98 |  | -      </Info>)
 | 
	
		
			
			| 99 |  | -      done()
 | 
	
		
			
			| 100 |  | -    })
 | 
	
		
			
			| 101 |  | -})
 | 
	
		
			
			| 102 |  | -
 | 
	
		
			
			| 103 |  | -describe('copy asset', (report, done) => {
 | 
	
		
			
			| 104 |  | -  let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
 | 
	
		
			
			| 105 |  | -  fs.cp(fs.asset('test-asset1.json'), dest)
 | 
	
		
			
			| 106 |  | -    .then(() => fs.readFile(dest, 'utf8'))
 | 
	
		
			
			| 107 |  | -    .then((data) => {
 | 
	
		
			
			| 108 |  | -      report(<Assert key="asset copied correctly"
 | 
	
		
			
			| 109 |  | -        expect={'asset#1'}
 | 
	
		
			
			| 110 |  | -        actual={JSON.parse(data).secret}/>)
 | 
	
		
			
			| 111 |  | -      return fs.stat(fs.asset('test-asset1.json'))
 | 
	
		
			
			| 112 |  | -    })
 | 
	
		
			
			| 113 |  | -    .then((stat) => {
 | 
	
		
			
			| 114 |  | -      report(<Assert key="file size check"
 | 
	
		
			
			| 115 |  | -        expect={27}
 | 
	
		
			
			| 116 |  | -        actual={Math.floor(stat.size)}/>,
 | 
	
		
			
			| 117 |  | -      <Info key="dest file info">
 | 
	
		
			
			| 118 |  | -        <Text>{JSON.stringify(stat)}</Text>
 | 
	
		
			
			| 119 |  | -      </Info>)
 | 
	
		
			
			| 120 |  | -      done()
 | 
	
		
			
			| 121 |  | -    })
 | 
	
		
			
			| 122 |  | -})
 | 
	
		
			
			|  | 79 | +//
 | 
	
		
			
			|  | 80 | +// describe('access assets from camera roll', (report, done) => {
 | 
	
		
			
			|  | 81 | +//   let photo = null
 | 
	
		
			
			|  | 82 | +//   CameraRoll.getPhotos({first : 10})
 | 
	
		
			
			|  | 83 | +//     .then((resp) => {
 | 
	
		
			
			|  | 84 | +//       photo = resp.edges[0].node.image.uri
 | 
	
		
			
			|  | 85 | +//       report(<Info key="items">
 | 
	
		
			
			|  | 86 | +//         <Text>{photo}</Text>
 | 
	
		
			
			|  | 87 | +//       </Info>)
 | 
	
		
			
			|  | 88 | +//       return fs.readFile(photo, 'base64')
 | 
	
		
			
			|  | 89 | +//     })
 | 
	
		
			
			|  | 90 | +//     .then((data) => {
 | 
	
		
			
			|  | 91 | +//       report(<Info key="asset image">
 | 
	
		
			
			|  | 92 | +//         <Image
 | 
	
		
			
			|  | 93 | +//           style={styles.image}
 | 
	
		
			
			|  | 94 | +//           source={{uri: `data:image/png;base64, ${data}`}}/>
 | 
	
		
			
			|  | 95 | +//       </Info>)
 | 
	
		
			
			|  | 96 | +//       done()
 | 
	
		
			
			|  | 97 | +//     })
 | 
	
		
			
			|  | 98 | +// })
 | 
	
		
			
			|  | 99 | +//
 | 
	
		
			
			|  | 100 | +// describe('read asset in app bundle',(report, done) => {
 | 
	
		
			
			|  | 101 | +//   let target = fs.asset('test-asset2.png')
 | 
	
		
			
			|  | 102 | +//   fs.readFile(target, 'base64')
 | 
	
		
			
			|  | 103 | +//   .then((data) => {
 | 
	
		
			
			|  | 104 | +//     report(<Info key="asset image">
 | 
	
		
			
			|  | 105 | +//       <Image
 | 
	
		
			
			|  | 106 | +//         style={styles.image}
 | 
	
		
			
			|  | 107 | +//         source={{uri: `data:image/png;base64, ${data}`}}/>
 | 
	
		
			
			|  | 108 | +//     </Info>)
 | 
	
		
			
			|  | 109 | +//     return fs.readFile(fs.asset('test-asset1.json'), 'utf8')
 | 
	
		
			
			|  | 110 | +//   })
 | 
	
		
			
			|  | 111 | +//   .then((resp) => {
 | 
	
		
			
			|  | 112 | +//     report(
 | 
	
		
			
			|  | 113 | +//       <Assert key="asset content verify"
 | 
	
		
			
			|  | 114 | +//         expect="asset#1"
 | 
	
		
			
			|  | 115 | +//         actual={JSON.parse(resp).secret}/>)
 | 
	
		
			
			|  | 116 | +//       done()
 | 
	
		
			
			|  | 117 | +//   })
 | 
	
		
			
			|  | 118 | +// })
 | 
	
		
			
			|  | 119 | +//
 | 
	
		
			
			|  | 120 | +// describe('stat assets in app', (report, done) => {
 | 
	
		
			
			|  | 121 | +//   fs.stat(fs.asset('test-asset2.png'))
 | 
	
		
			
			|  | 122 | +//     .then((data) => {
 | 
	
		
			
			|  | 123 | +//       report(<Info key="list of assets">
 | 
	
		
			
			|  | 124 | +//         <Text>{JSON.stringify(data)}</Text>
 | 
	
		
			
			|  | 125 | +//       </Info>)
 | 
	
		
			
			|  | 126 | +//       done()
 | 
	
		
			
			|  | 127 | +//     })
 | 
	
		
			
			|  | 128 | +// })
 | 
	
		
			
			|  | 129 | +//
 | 
	
		
			
			|  | 130 | +// describe('copy asset', (report, done) => {
 | 
	
		
			
			|  | 131 | +//   let dest = `${dirs.DocumentDir}/test-asset-1-${Date.now()}.json`
 | 
	
		
			
			|  | 132 | +//   fs.cp(fs.asset('test-asset1.json'), dest)
 | 
	
		
			
			|  | 133 | +//     .then(() => fs.readFile(dest, 'utf8'))
 | 
	
		
			
			|  | 134 | +//     .then((data) => {
 | 
	
		
			
			|  | 135 | +//       report(<Assert key="asset copied correctly"
 | 
	
		
			
			|  | 136 | +//         expect={'asset#1'}
 | 
	
		
			
			|  | 137 | +//         actual={JSON.parse(data).secret}/>)
 | 
	
		
			
			|  | 138 | +//       return fs.stat(fs.asset('test-asset1.json'))
 | 
	
		
			
			|  | 139 | +//     })
 | 
	
		
			
			|  | 140 | +//     .then((stat) => {
 | 
	
		
			
			|  | 141 | +//       report(<Assert key="file size check"
 | 
	
		
			
			|  | 142 | +//         expect={27}
 | 
	
		
			
			|  | 143 | +//         actual={Math.floor(stat.size)}/>,
 | 
	
		
			
			|  | 144 | +//       <Info key="dest file info">
 | 
	
		
			
			|  | 145 | +//         <Text>{JSON.stringify(stat)}</Text>
 | 
	
		
			
			|  | 146 | +//       </Info>)
 | 
	
		
			
			|  | 147 | +//       done()
 | 
	
		
			
			|  | 148 | +//     })
 | 
	
		
			
			|  | 149 | +// })
 |