Skip to content

Commit

Permalink
Fix request test final.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Jan 23, 2023
1 parent 5406dd9 commit 29ffd1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/http/request.js
Expand Up @@ -4,7 +4,6 @@ const https = require('https');
const dns = require('dns');
const HttpUtil = require('./http.js');
const HttpOptions = require('./options.js');
const fs = require('fs');
const path = require('path');
const Auth = require('./auth.js');
const Formatter = require('./formatter.js');
Expand Down Expand Up @@ -418,8 +417,9 @@ class HttpRequest extends EventEmitter {
bufferArray.push(Buffer.from(delimiter + crlf + header + crlf + crlf));

// set data
const {readFileSync} = require('fs');
if (fieldValue.filePath) {
bufferArray.push(fs.readFileSync(fieldValue.filePath));
bufferArray.push(readFileSync(fieldValue.filePath));
} else {
bufferArray.push(Buffer.from(fieldValue.data));
}
Expand Down
Expand Up @@ -52,6 +52,7 @@ class AppAutomate extends BrowserStack {
url: 'https://api-cloud.browserstack.com/app-automate/upload',
method: 'POST',
use_ssl: true,
port: 443,
auth: {
user: this.username,
pass: this.accessKey
Expand Down
14 changes: 6 additions & 8 deletions test/src/index/testRequest.js
Expand Up @@ -415,11 +415,11 @@ describe('test HttpRequest', function() {
});

it('send POST request with multi-part form data', function(done) {
const appPath = path.resolve(__dirname, '../../extra/output/app.apk');
const appDir = path.dirname(appPath);

fs.mkdirSync(appDir, {recursive: true});
fs.writeFileSync(appPath, 'app-data');
mockery.registerMock('fs', {
readFileSync() {
return Buffer.from('app-data');
}
});

const options = {
method: 'POST',
Expand All @@ -428,7 +428,7 @@ describe('test HttpRequest', function() {
port: 443,
multiPartFormData: {
file: {
filePath: appPath
filePath: 'some/path/app.apk'
},
custom_id: {
data: 'some_app'
Expand All @@ -438,8 +438,6 @@ describe('test HttpRequest', function() {

const request = new HttpRequest(options);
request.on('success', function () {
fs.rmSync(appPath);

done();
}).send();

Expand Down

0 comments on commit 29ffd1b

Please sign in to comment.