Skip to content

Commit bf23c5f

Browse files
feat: rename folder endpoint (#661)
1 parent eb55c11 commit bf23c5f

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

lib/api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,14 @@ 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 = {}) {
342+
exports.rename_folder = function rename_folder(old_path, new_path, callback, options = {}) {
343343
let uri;
344344
uri = ['folders', old_path];
345-
let update_folder_params = {
345+
let rename_folder_params = {
346346
to_folder: new_path
347347
};
348348
options.content_type = 'json';
349-
return call_api('put', uri, update_folder_params, callback, options);
349+
return call_api('put', uri, rename_folder_params, callback, options);
350350
};
351351

352352
exports.upload_mappings = function upload_mappings(callback, options = {}) {

lib/v2/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ v1_adapters(exports, api, {
3535
root_folders: 0,
3636
sub_folders: 1,
3737
delete_folder: 1,
38-
update_folder: 2,
38+
rename_folder: 2,
3939
create_folder: 1,
4040
upload_mappings: 0,
4141
upload_mapping: 1,

test/integration/api/admin/folders_api_spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ describe('Admin API - Folders', () => {
2222
mocked.xhr.restore();
2323
});
2424

25-
describe('update_folder', () => {
26-
it('should send a request with correct parameters', () => {
27-
cloudinary.v2.api.update_folder('old/path', 'new/path');
25+
describe('rename_folder', () => {
26+
it('should send a request to update folder endpoint with correct parameters', () => {
27+
cloudinary.v2.api.rename_folder('old/path', 'new/path');
2828

29-
// sinon.assert.calledWith(xhr, sinon.match({
30-
// pathname: sinon.match('old/path'),
31-
// method: sinon.match('PUT')
32-
// }));
29+
sinon.assert.calledWith(mocked.request, sinon.match({
30+
pathname: sinon.match('old%2Fpath'),
31+
method: sinon.match('PUT')
32+
}));
3333
sinon.assert.calledWith(mocked.write, sinon.match(helper.apiJsonParamMatcher('to_folder', 'new/path')));
3434
});
3535
});

types/cloudinary_ts_spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,9 @@ cloudinary.v2.api.delete_folder('foo', {
11791179
agent: new Http.Agent()
11801180
});
11811181

1182+
// $ExpectType Promise<RenameFolderResponse>
1183+
cloudinary.v2.api.rename_folder('old/path', 'new/path');
1184+
11821185
// $ExpectType Promise<NewAssetRelationResponse>
11831186
cloudinary.v2.api.add_related_assets('public-id', 'public-id-to-relate');
11841187

types/index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,17 @@ declare module 'cloudinary' {
859859
request_id: string,
860860
}
861861

862+
export interface RenameFolderResponse {
863+
from: {
864+
name: string,
865+
path: string,
866+
}
867+
to: {
868+
name: string,
869+
path: string,
870+
}
871+
}
872+
862873
export namespace v2 {
863874

864875
/****************************** Global Utils *************************************/
@@ -1160,6 +1171,8 @@ declare module 'cloudinary' {
11601171

11611172
function delete_folder(path: string, options?: AdminApiOptions, callback?: ResponseCallback): Promise<any>;
11621173

1174+
function rename_folder(old_path: string, new_path: string, options?: AdminApiOptions, callback?: ResponseCallback): Promise<RenameFolderResponse>;
1175+
11631176
function add_related_assets(public_id: string, public_ids_to_relate: string | Array<string>, options?: AdminApiOptions, callback?: ResponseCallback): Promise<NewAssetRelationResponse>;
11641177

11651178
function add_related_assets_by_asset_id(asset_id: string, public_ids_to_relate: string | Array<string>, options?: AdminApiOptions, callback?: ResponseCallback): Promise<NewAssetRelationResponse>;

0 commit comments

Comments
 (0)