Skip to content

Commit eb55c11

Browse files
feat: update folders endpoint (#660)
1 parent 9c0c177 commit eb55c11

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

lib/api.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ exports.delete_folder = function delete_folder(path, callback, options = {}) {
339339
return call_api("delete", uri, {}, callback, options);
340340
};
341341

342+
exports.update_folder = function delete_folderupdate_folder(old_path, new_path, callback, options = {}) {
343+
let uri;
344+
uri = ['folders', old_path];
345+
let update_folder_params = {
346+
to_folder: new_path
347+
};
348+
options.content_type = 'json';
349+
return call_api('put', uri, update_folder_params, callback, options);
350+
};
351+
342352
exports.upload_mappings = function upload_mappings(callback, options = {}) {
343353
let params;
344354
params = pickOnlyExistingValues(options, "next_cursor", "max_results");

lib/v2/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ v1_adapters(exports, api, {
3535
root_folders: 0,
3636
sub_folders: 1,
3737
delete_folder: 1,
38+
update_folder: 2,
3839
create_folder: 1,
3940
upload_mappings: 0,
4041
upload_mapping: 1,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const assert = require('assert');
2+
const sinon = require('sinon');
3+
4+
const cloudinary = require('../../../../lib/cloudinary');
5+
const createTestConfig = require('../../../testUtils/createTestConfig');
6+
const helper = require('../../../spechelper');
7+
const api_http = require("https");
8+
const ClientRequest = require('_http_client').ClientRequest;
9+
10+
describe('Admin API - Folders', () => {
11+
const mocked = {};
12+
13+
beforeEach(function () {
14+
mocked.xhr = sinon.useFakeXMLHttpRequest();
15+
mocked.write = sinon.spy(ClientRequest.prototype, 'write');
16+
mocked.request = sinon.spy(api_http, 'request');
17+
});
18+
19+
afterEach(function () {
20+
mocked.request.restore();
21+
mocked.write.restore();
22+
mocked.xhr.restore();
23+
});
24+
25+
describe('update_folder', () => {
26+
it('should send a request with correct parameters', () => {
27+
cloudinary.v2.api.update_folder('old/path', 'new/path');
28+
29+
// sinon.assert.calledWith(xhr, sinon.match({
30+
// pathname: sinon.match('old/path'),
31+
// method: sinon.match('PUT')
32+
// }));
33+
sinon.assert.calledWith(mocked.write, sinon.match(helper.apiJsonParamMatcher('to_folder', 'new/path')));
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)