Skip to content

Commit

Permalink
test: fixed custom regions
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudinary-pkoniu committed Feb 23, 2024
1 parent 8acc6b2 commit 66eabf8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 99 deletions.
21 changes: 0 additions & 21 deletions lib/utils/encoding/encodeRegions.js

This file was deleted.

3 changes: 1 addition & 2 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const consumeOption = require('./parsing/consumeOption');
const toArray = require('./parsing/toArray');
let {base64EncodeURL} = require('./encoding/base64EncodeURL');
const encodeDoubleArray = require('./encoding/encodeDoubleArray');
const encodeRegions = require('./encoding/encodeRegions');

const config = require("../config");
const generate_token = require("../auth_token");
Expand Down Expand Up @@ -723,7 +722,7 @@ function updateable_resource_params(options, params = {}) {
params.visual_search = options.visual_search;
}
if (options.regions != null) {
params.regions = encodeRegions(options.regions);
params.regions = JSON.stringify(options.regions);
}
return params;
}
Expand Down
54 changes: 16 additions & 38 deletions test/integration/api/uploader/custom_region_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,83 +22,61 @@ describe('Uploader', () => {

describe('upload', () => {
it('should send a request with encoded custom region gravity that represents a box', () => {
const boxRegionGravityEncoded = '{box_1}1,2,3,4|{box_2}5,6,7,8';

cloudinary.v2.uploader.upload('irrelevant', {
regions: {
'box_1': [[1, 2], [3, 4]],
'box_2': [[5, 6], [7, 8]]
}
});

sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', boxRegionGravityEncoded)));
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', JSON.stringify({
'box_1': [[1, 2], [3, 4]],
'box_2': [[5, 6], [7, 8]]
}))));
});

it('should send a request with encoded custom region gravity that represents a custom shape', () => {
const customRegionGravityEncoded = '{custom_1}1,2,3,4,5,6,7,8|{custom_2}10,11,12,13,14,15';

cloudinary.v2.uploader.upload('irrelevant', {
regions: {
'custom_1': [[1, 2], [3, 4], [5, 6], [7, 8]],
'custom_2': [[10, 11], [12, 13], [14, 15]]
}
});

sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', customRegionGravityEncoded)));
});

it('should throw an error when insufficient custom region gravity details', () => {
assert.throws(() => {
cloudinary.v2.uploader.upload('irrelevant', {
regions: {
'error_1': [[1, 2]]
}
})
}, {
name: 'TypeError',
message: 'Regions should contain at least two arrays with two coordinates'
});
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', JSON.stringify({
'custom_1': [[1, 2], [3, 4], [5, 6], [7, 8]],
'custom_2': [[10, 11], [12, 13], [14, 15]]
}))));
});
});

describe('explicit', () => {
it('should send a request with encoded custom region gravity that represents a box', () => {
const boxRegionGravityEncoded = '{box_1}1,2,3,4|{box_2}5,6,7,8';

cloudinary.v2.uploader.explicit('irrelevant', {
regions: {
'box_1': [[1, 2], [3, 4]],
'box_2': [[5, 6], [7, 8]]
}
});

sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', boxRegionGravityEncoded)));
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', JSON.stringify({
'box_1': [[1, 2], [3, 4]],
'box_2': [[5, 6], [7, 8]]
}))));
});

it('should send a request with encoded custom region gravity that represents a custom shape', () => {
const customRegionGravityEncoded = '{custom_1}1,2,3,4,5,6,7,8|{custom_2}10,11,12,13,14,15';

cloudinary.v2.uploader.explicit('irrelevant', {
regions: {
'custom_1': [[1, 2], [3, 4], [5, 6], [7, 8]],
'custom_2': [[10, 11], [12, 13], [14, 15]]
}
});

sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', customRegionGravityEncoded)));
});

it('should throw an error when insufficient custom region gravity details', () => {
assert.throws(() => {
cloudinary.v2.uploader.upload('irrelevant', {
regions: {
'error_1': [[1, 2]]
}
})
}, {
name: 'TypeError',
message: 'Regions should contain at least two arrays with two coordinates'
});
sinon.assert.calledWith(spy, sinon.match(helper.uploadParamMatcher('regions', JSON.stringify({
'custom_1': [[1, 2], [3, 4], [5, 6], [7, 8]],
'custom_2': [[10, 11], [12, 13], [14, 15]]
}))));
});
});
});
38 changes: 0 additions & 38 deletions test/unit/cloudinaryUtils/encodeRegions.spec.js

This file was deleted.

0 comments on commit 66eabf8

Please sign in to comment.