import RNTest from './react-native-testkit/' import React from 'react' import RNFetchBlob from 'react-native-fetch-blob' import { StyleSheet, Text, View, ScrollView, Dimensions, Image, } from 'react-native'; const { Assert, Comparer, Info, prop } = RNTest const describe = RNTest.config({ group : '0.1.x - 0.4.x', expand : false, run : true }) let { TEST_SERVER_URL, FILENAME, DROPBOX_TOKEN, styles, image } = prop() describe('The check if it follows 301/302 redirection', (report, done) => { image = RNTest.prop('image') RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/redirect`) .then((resp) => { report( , ) done() }) }) describe('Upload octet-stream image to Dropbox', (report, done) => { RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', { Authorization : `Bearer ${DROPBOX_TOKEN}`, 'Dropbox-API-Arg': '{\"path\": \"/rn-upload/'+FILENAME+'\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}', 'Content-Type' : 'application/octet-stream', }, image) .then((resp) => { resp = resp.json() report( ) done() }) }) describe('Upload multipart/form-data', (report, done) => { RNFetchBlob.fetch('POST', `${TEST_SERVER_URL}/upload-form`, { Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz", 'Content-Type' : 'multipart/form-data', }, [ { name : 'test-img', filename : 'test-img.png', data: image}, { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')}, { name : 'field1', data : 'hello !!'}, { name : 'field2', data : 'hello2 !!'} ]) .then((resp) => { resp = resp.json() report( , , ) done() }) }) describe('Compare uploaded multipart image', (report, done) => { let r1 = null RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-img.png`) .then((resp) => { r1 = resp return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/test-text.txt`) }) .then((resp) => { report( , ) done() }) }) // added after 0.4.2 describe('Progress report test', (report, done) => { let received = 0 RNFetchBlob .fetch('GET', `${TEST_SERVER_URL}/public/1mb-dummy`, { Authorization : 'Bearer abde123eqweje' }) .progress((written, total) => { // report() if(written === total) report() }) .then((resp) => { report() done() }) }) describe('PUT request test', (report, done) => { RNFetchBlob.fetch('PUT', `${TEST_SERVER_URL}/upload-form`, { Authorization : "Bearer fsXcpmKPrHgAAAAAAAAAEGxFXwhejXM_E8fznZoXPhHbhbNhA-Lytbe6etp1Jznz", 'Content-Type' : 'multipart/form-data', }, [ { name : 'test-img', filename : 'test-img.png', data: image}, { name : 'test-text', filename : 'test-text.txt', data: RNFetchBlob.base64.encode('hello.txt')}, { name : 'field1', data : 'hello !!'}, { name : 'field2', data : 'hello2 !!'} ]) .then((resp) => { resp = resp.json() report( , , ) done() }) }) describe('DELETE request test', (report, done) => { RNFetchBlob.fetch('DELETE', `${TEST_SERVER_URL}/hey`) .then((resp) => { report( ) done() }) })