Skip to content

Commit f4d7ebf

Browse files
Merge pull request #625 from cloudinary/on-success-script-for-upload
feat: added support for on_success script for uploader_spec.js
2 parents 242ac45 + a367036 commit f4d7ebf

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ function build_upload_params(options) {
371371
quality_override: options.quality_override,
372372
accessibility_analysis: utils.as_safe_bool(options.accessibility_analysis),
373373
use_asset_folder_as_public_id_prefix: utils.as_safe_bool(options.use_asset_folder_as_public_id_prefix),
374-
visual_search: utils.as_safe_bool(options.visual_search)
374+
visual_search: utils.as_safe_bool(options.visual_search),
375+
on_success: options.on_success
375376
};
376377
return utils.updateable_resource_params(options, params);
377378
}

test/integration/api/uploader/uploader_spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,30 @@ describe("uploader", function () {
652652
});
653653
});
654654

655+
describe('when passing on_success in parameters', () => {
656+
var spy, xhr;
657+
spy = void 0;
658+
xhr = void 0;
659+
before(function () {
660+
xhr = sinon.useFakeXMLHttpRequest();
661+
spy = sinon.spy(ClientRequest.prototype, 'write');
662+
});
663+
after(function () {
664+
spy.restore();
665+
return xhr.restore();
666+
});
667+
668+
it('should pass its value to the upload api', () => {
669+
cloudinary.v2.uploader.upload(IMAGE_FILE, {
670+
on_success: 'current_asset.update({tags: ["autocaption"]});'
671+
});
672+
673+
expect(spy.calledWith(sinon.match((arg) => {
674+
return arg.toString().match(/on_success='current_asset.update({tags: ["autocaption"]});'/);
675+
})));
676+
});
677+
});
678+
655679
describe("upload_chunked", function () {
656680
this.timeout(TIMEOUT.LONG * 10);
657681
it("should specify chunk size", function (done) {

0 commit comments

Comments
 (0)