Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/sandbox/pmapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ function Postman (execution,
* @instance
* @param {String} requestId - The UUID of the request to execute.
* This can be found in the request's metadata or corresponding collection JSON.
* @param {Object} [options] - Configuration options for the request execution
* @param {Object} [options.variables] - Key-value pairs of variables to override during
* @param {Object} [runRequestOptions] - Configuration options for the request execution
* @param {Object} [runRequestOptions.variables] - Key-value pairs of variables to override during
* request execution. These will act as temporary
* overrides for the this specific request run.
* @returns {Promise<Response | null>} A Promise that resolves to:
Expand All @@ -412,15 +412,15 @@ function Postman (execution,
* console.error('Request failed:', error);
* }
*/
runRequest: function (requestId, options) {
runRequest: function (requestId, runRequestOptions) {
return new Promise(function (resolve, reject) {
if (!requestId) {
reject(new Error('runRequest: collection request id not provided'));

return;
}

onRunRequest(requestId, options || {},
onRunRequest(requestId, runRequestOptions || {},
function (err, resp, context) {
if (err) {
return reject(err);
Expand Down
32 changes: 20 additions & 12 deletions test/unit/sandbox-libraries/pm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,10 @@ describe('sandbox library - pm api', function () {
this.responseTime = response.responseTime;
this.isCustomGRPCResponseClass = true;
}

static isResponse (obj) {
return obj instanceof Response;
}
}

module.exports = { Response };
Expand All @@ -1497,6 +1501,20 @@ describe('sandbox library - pm api', function () {
}, (errorInitializingSandbox, sandboxContext) => {
if (errorInitializingSandbox) { return done(errorInitializingSandbox); }

let erroredTest = false;

sandboxContext.on(`execution.error.${executionId}`, (_exec, err) => {
erroredTest = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

done(new Error(err.message));
});

sandboxContext.on('console' + executionId, (_cursor, _level, grpcRequestResponse) => {
expect(grpcRequestResponse).to.have.property('statusCode', 0);
expect(grpcRequestResponse).to.have.property('responseTime', 100);
// Custom class property
expect(grpcRequestResponse).to.have.property('isCustomGRPCResponseClass', true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

});

sandboxContext.on('execution.run_collection_request.' + executionId,
function (_cursor, id, reqId) {
sandboxContext.dispatch(`execution.run_collection_request_response.${id}`,
Expand All @@ -1506,24 +1524,14 @@ describe('sandbox library - pm api', function () {
{ responseType: 'grpc' });
});

let consoleMessage = '';

sandboxContext.on('console', (_cursor, _level, message) => {
consoleMessage = message;
expect(consoleMessage).to.eql({
statusCode: 0,
responseTime: 100,
isCustomGRPCResponseClass: true
});
});

sandboxContext.execute(`
const grpcRequestResponse = await pm.execution.runRequest('sample-request-id');

console.log(grpcRequestResponse);`,
{ id: executionId, templateName: 'grpc' },
function (err) {
done(err);
sandboxContext.dispose();
if (!erroredTest) { done(err); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (err) done (err)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

});
});
});
Expand Down
Loading