Skip to content

Commit 8e9a78b

Browse files
committed
test: implement tests for #495
1 parent 4ef17d1 commit 8e9a78b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/e2e-specs.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,34 @@ const tests = [
11781178
result.data.should.be.eql({ status: -2, error: messageFactory.handshakeFailed() });
11791179
}
11801180
},
1181+
{
1182+
description: 'should upload a file in binary mode from given path in local filesystem to given URL #495',
1183+
expected: 'resolved: {"status": 200, "data": "files": {"test-file.txt": "I am a dummy file. I am used ...',
1184+
func: function (resolve, reject) {
1185+
var fileName = 'test-file.txt';
1186+
var fileContent = 'I am a dummy file. I am used for testing purposes!';
1187+
var sourcePath = cordova.file.cacheDirectory + fileName;
1188+
var targetUrl = 'http://httpbin.org/post';
1189+
1190+
var options = { method: 'upload', transmitFileAs: 'BINARY', filePath: sourcePath, name: fileName };
1191+
1192+
helpers.writeToFile(function () {
1193+
cordova.plugin.http.sendRequest(targetUrl, options, resolve, reject);
1194+
}, fileName, fileContent);
1195+
},
1196+
validationFunc: function (driver, result) {
1197+
var fileName = 'test-file.txt';
1198+
var fileContent = 'I am a dummy file. I am used for testing purposes!';
1199+
1200+
result.type.should.be.equal('resolved');
1201+
result.data.data.should.be.a('string');
1202+
1203+
JSON
1204+
.parse(result.data.data)
1205+
.data
1206+
.should.be.equal(fileContent);
1207+
}
1208+
},
11811209
];
11821210

11831211
if (typeof module !== 'undefined' && module.exports) {

0 commit comments

Comments
 (0)