Skip to content

Commit 3279be8

Browse files
authored
Add tests for expression normalization (#521)
1 parent c7d148c commit 3279be8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/unit/normalize_expression_spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const cloudinary = require("../../cloudinary");
22
const createTestConfig = require('../testUtils/createTestConfig');
3+
const helper = require("../spechelper");
4+
const { SIMPLE_PARAMS } = require(`../../${helper.libPath}/utils/consts`);
35

46
describe("normalize_expression tests", function () {
57
beforeEach(function () {
@@ -54,4 +56,31 @@ describe("normalize_expression tests", function () {
5456
expect(cloudinary.utils.normalize_expression(input)).to.equal(expected);
5557
});
5658
});
59+
describe('Normalize only specific parameters', () => {
60+
const simpleTransformationParams = SIMPLE_PARAMS.map(param => param[0]);
61+
const value = "width * 2";
62+
const normalizedValue = "w_mul_2";
63+
const normalizedParams = ["angle", "aspect_ratio", "dpr", "effect", "height", "opacity", "quality", "radius",
64+
"width", "x", "y", "zoom"];
65+
const nonNormalizedParams = simpleTransformationParams.concat('overlay', 'underlay')
66+
normalizedParams.forEach((param) => {
67+
it(`should normalize value in ${param}`, () => {
68+
// c_scale needed to test h_ and w_ parameters that are ignored without crop mode
69+
const options = {
70+
crop: "scale",
71+
[param]: value
72+
};
73+
const result = cloudinary.utils.generate_transformation_string(options);
74+
expect(result).to.contain(normalizedValue);
75+
expect(result).to.not.contain(value);
76+
});
77+
});
78+
nonNormalizedParams.forEach((param) => {
79+
it(`should not normalize value in ${param}`, () => {
80+
const result = cloudinary.utils.generate_transformation_string({[param]: value});
81+
expect(result).to.contain(value);
82+
expect(result).to.not.contain(normalizedValue);
83+
});
84+
});
85+
});
5786
});

0 commit comments

Comments
 (0)