From d6647d55a518be96eaf675a9a30dfc1144e524cf Mon Sep 17 00:00:00 2001 From: rtlCoil Date: Tue, 9 Nov 2021 19:13:43 +0200 Subject: [PATCH] Add tests for expression normalization --- test/unit/normalize_expression_spec.js | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/unit/normalize_expression_spec.js b/test/unit/normalize_expression_spec.js index c2abe703..646a560c 100644 --- a/test/unit/normalize_expression_spec.js +++ b/test/unit/normalize_expression_spec.js @@ -1,5 +1,7 @@ const cloudinary = require("../../cloudinary"); const createTestConfig = require('../testUtils/createTestConfig'); +const helper = require("../spechelper"); +const { SIMPLE_PARAMS } = require(`../../${helper.libPath}/utils/consts`); describe("normalize_expression tests", function () { beforeEach(function () { @@ -54,4 +56,31 @@ describe("normalize_expression tests", function () { expect(cloudinary.utils.normalize_expression(input)).to.equal(expected); }); }); + describe('Normalize only specific parameters', () => { + const simpleTransformationParams = SIMPLE_PARAMS.map(param => param[0]); + const value = "width * 2"; + const normalizedValue = "w_mul_2"; + const normalizedParams = ["angle", "aspect_ratio", "dpr", "effect", "height", "opacity", "quality", "radius", + "width", "x", "y", "zoom"]; + const nonNormalizedParams = simpleTransformationParams.concat('overlay', 'underlay') + normalizedParams.forEach((param) => { + it(`should normalize value in ${param}`, () => { + // c_scale needed to test h_ and w_ parameters that are ignored without crop mode + const options = { + crop: "scale", + [param]: value + }; + const result = cloudinary.utils.generate_transformation_string(options); + expect(result).to.contain(normalizedValue); + expect(result).to.not.contain(value); + }); + }); + nonNormalizedParams.forEach((param) => { + it(`should not normalize value in ${param}`, () => { + const result = cloudinary.utils.generate_transformation_string({[param]: value}); + expect(result).to.contain(value); + expect(result).to.not.contain(normalizedValue); + }); + }); + }); });