mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-06-19 00:00:08 +08:00
implement e2e tests for #101
This commit is contained in:
Generated
-6345
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
+49
-18
@@ -75,6 +75,13 @@ const helpers = {
|
||||
}
|
||||
|
||||
return hash;
|
||||
},
|
||||
checkResult: function (result, expected) {
|
||||
if (result.type === 'throwed' && expected !== 'throwed') {
|
||||
throw new Error('Expected function not to throw: ' + result.message);
|
||||
}
|
||||
|
||||
result.type.should.be.equal(expected);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -791,26 +798,50 @@ const tests = [
|
||||
result.data.error.should.be.equal("\n -=[ teapot ]=-\n\n _...._\n .' _ _ `.\n | .\"` ^ `\". _,\n \\_;`\"---\"`|//\n | ;/\n \\_ _/\n `\"\"\"`\n");
|
||||
}
|
||||
},
|
||||
{
|
||||
description: 'should serialize FormData instance correctly when it contains string value',
|
||||
expected: 'resolved: {"status": 200, ...',
|
||||
before: helpers.setMultipartSerializer,
|
||||
func: function (resolve, reject) {
|
||||
var formData = new FormData();
|
||||
formData.append('myString', 'This is a test!');
|
||||
|
||||
// TODO: not ready yet
|
||||
// {
|
||||
// description: 'should serialize FormData instance correctly when it contains string value',
|
||||
// expected: 'resolved: {"status": 200, ...',
|
||||
// before: helpers.setMultipartSerializer,
|
||||
// func: function (resolve, reject) {
|
||||
// var formData = new FormData();
|
||||
// formData.append('myString', 'This is a test!');
|
||||
var url = 'https://httpbin.org/anything';
|
||||
var options = { method: 'post', data: formData };
|
||||
cordova.plugin.http.sendRequest(url, options, resolve, reject);
|
||||
},
|
||||
validationFunc: function (driver, result) {
|
||||
helpers.checkResult(result, 'resolved');
|
||||
result.data.status.should.be.equal(200);
|
||||
JSON.parse(result.data.data).form.should.be.eql({ myString: 'This is a test!' });
|
||||
}
|
||||
},
|
||||
{
|
||||
description: 'should serialize FormData instance correctly when it contains blob value',
|
||||
expected: 'resolved: {"status": 200, ...',
|
||||
before: helpers.setMultipartSerializer,
|
||||
func: function (resolve, reject) {
|
||||
helpers.getWithXhr(function(blob) {
|
||||
var formData = new FormData();
|
||||
formData.append('CordovaLogo', blob);
|
||||
|
||||
// var url = 'https://httpbin.org/anything';
|
||||
// var options = { method: 'post', data: formData };
|
||||
// cordova.plugin.http.sendRequest(url, options, resolve, reject);
|
||||
// },
|
||||
// validationFunc: function (driver, result) {
|
||||
// console.log(result.data);
|
||||
// result.type.should.be.equal('resolved');
|
||||
// result.data.status.should.be.equal(200);
|
||||
// }
|
||||
// }
|
||||
var url = 'https://httpbin.org/anything';
|
||||
var options = { method: 'post', data: formData };
|
||||
cordova.plugin.http.sendRequest(url, options, resolve, reject);
|
||||
}, './res/cordova_logo.png', 'blob');
|
||||
},
|
||||
validationFunc: function (driver, result) {
|
||||
helpers.checkResult(result, 'resolved');
|
||||
result.data.status.should.be.equal(200);
|
||||
|
||||
// httpbin.org encodes posted binaries in base64 and echoes them back
|
||||
// therefore we need to check for base64 string with mime type prefix
|
||||
const fs = require('fs');
|
||||
const rawLogo = fs.readFileSync('./test/e2e-app-template/www/res/cordova_logo.png');
|
||||
const b64Logo = rawLogo.toString('base64');
|
||||
JSON.parse(result.data.data).files.CordovaLogo.should.be.equal('data:image/png;base64,' + b64Logo);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: not ready yet
|
||||
// {
|
||||
|
||||
@@ -5,6 +5,7 @@ const should = chai.should();
|
||||
|
||||
const BlobMock = require('./mocks/Blob.mock');
|
||||
const ConsoleMock = require('./mocks/Console.mock');
|
||||
const FileMock = require('./mocks/File.mock');
|
||||
const FileReaderMock = require('./mocks/FileReader.mock');
|
||||
const FormDataMock = require('./mocks/FormData.mock');
|
||||
|
||||
@@ -518,6 +519,7 @@ describe('Common helpers', function () {
|
||||
describe('processData()', function () {
|
||||
const mockWindow = {
|
||||
Blob: BlobMock,
|
||||
File: FileMock,
|
||||
FileReader: FileReaderMock,
|
||||
FormData: FormDataMock,
|
||||
TextEncoder: util.TextEncoder,
|
||||
|
||||
+1
-1
@@ -427,7 +427,7 @@ module.exports = function init(global, jsUtil, cookieHandler, messages, base64,
|
||||
return onFinished(result);
|
||||
}
|
||||
|
||||
if (entry.value[1] instanceof global.Blob) {
|
||||
if (entry.value[1] instanceof global.Blob || entry.value[1] instanceof global.File) {
|
||||
var reader = new global.FileReader();
|
||||
|
||||
reader.onload = function() {
|
||||
|
||||
Reference in New Issue
Block a user