|
1 | 1 | const cloudinary = require("../../cloudinary"); |
2 | 2 | const createTestConfig = require('../testUtils/createTestConfig'); |
| 3 | +const helper = require("../spechelper"); |
| 4 | +const { SIMPLE_PARAMS } = require(`../../${helper.libPath}/utils/consts`); |
3 | 5 |
|
4 | 6 | describe("normalize_expression tests", function () { |
5 | 7 | beforeEach(function () { |
@@ -54,4 +56,31 @@ describe("normalize_expression tests", function () { |
54 | 56 | expect(cloudinary.utils.normalize_expression(input)).to.equal(expected); |
55 | 57 | }); |
56 | 58 | }); |
| 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 | + }); |
57 | 86 | }); |
0 commit comments