|
| 1 | +import RNTest from './react-native-testkit/' |
| 2 | +import React from 'react' |
| 3 | +import _ from 'lodash' |
| 4 | +import RNFetchBlob from 'react-native-fetch-blob' |
| 5 | +import { |
| 6 | + StyleSheet, |
| 7 | + Text, |
| 8 | + View, |
| 9 | + ScrollView, |
| 10 | + Linking, |
| 11 | + Platform, |
| 12 | + Dimensions, |
| 13 | + BackAndroid, |
| 14 | + AsyncStorage, |
| 15 | + Image, |
| 16 | +} from 'react-native'; |
| 17 | + |
| 18 | +window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest |
| 19 | +window.Blob = RNFetchBlob.polyfill.Blob |
| 20 | + |
| 21 | +const JSONStream = RNFetchBlob.JSONStream |
| 22 | +const fs = RNFetchBlob.fs |
| 23 | +const { Assert, Comparer, Info, prop } = RNTest |
| 24 | +const describe = RNTest.config({ |
| 25 | + group : '0.10.3', |
| 26 | + run : true, |
| 27 | + expand : true, |
| 28 | + timeout : 20000, |
| 29 | +}) |
| 30 | +const { TEST_SERVER_URL, TEST_SERVER_URL_SSL, FILENAME, DROPBOX_TOKEN, styles } = prop() |
| 31 | +const dirs = RNFetchBlob.fs.dirs |
| 32 | +let prefix = ((Platform.OS === 'android') ? 'file://' : '') |
| 33 | +let begin = Date.now() |
| 34 | + |
| 35 | + |
| 36 | +describe('#230 #249 cookies manipulation', (report, done) => { |
| 37 | + |
| 38 | + RNFetchBlob |
| 39 | + .fetch('GET', `${TEST_SERVER_URL}/cookie/249230`) |
| 40 | + .then((res) => RNFetchBlob.net.getCookies()) |
| 41 | + .then((cookies) => { |
| 42 | + console.log(cookies) |
| 43 | + report(<Assert |
| 44 | + key="should set 10 cookies" |
| 45 | + expect={10} |
| 46 | + actual={cookies['localhost'].length}/>) |
| 47 | + return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`) |
| 48 | + }) |
| 49 | + .then((res) => { |
| 50 | + console.log(res.data) |
| 51 | + let cookies = String(res.data).split(';') |
| 52 | + report(<Assert |
| 53 | + key="should send 10 cookies" |
| 54 | + expect={10} |
| 55 | + actual={cookies.length}/>) |
| 56 | + return RNFetchBlob.net.removeCookies() |
| 57 | + }) |
| 58 | + .then(() => RNFetchBlob.net.getCookies('localhost')) |
| 59 | + .then((cookies) => { |
| 60 | + report(<Assert |
| 61 | + key="should have no cookies" |
| 62 | + expect={undefined} |
| 63 | + actual={cookies['localhost']}/>) |
| 64 | + return RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/cookie-echo`) |
| 65 | + }) |
| 66 | + .then((res) => { |
| 67 | + console.log(res.data) |
| 68 | + let cookies = String(res.data).split(';') |
| 69 | + cookies = _.reject(cookies, r => r.length < 2) |
| 70 | + report(<Assert |
| 71 | + key="should send no cookies" |
| 72 | + expect={0} |
| 73 | + actual={cookies.length}/>) |
| 74 | + done() |
| 75 | + }) |
| 76 | + |
| 77 | +}) |
0 commit comments