From 7b4865145dc941499c6e06fd8fd4664aecd46d13 Mon Sep 17 00:00:00 2001 From: Raya Straus Date: Mon, 15 Jun 2020 16:18:11 +0300 Subject: [PATCH 1/2] add test for context metadata as user variables --- test/utils/utils_spec.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/utils/utils_spec.js b/test/utils/utils_spec.js index 14f2804a..26bbc24a 100644 --- a/test/utils/utils_spec.js +++ b/test/utils/utils_spec.js @@ -18,6 +18,7 @@ const { clone, isString, merge, pickOnlyExistingValues } = utils; const { sharedExamples, itBehavesLike, test_cloudinary_url } = helper; const TEST_TAG = helper.TEST_TAG; +const CONTEXT_PUBLIC_ID = helper.IMAGE_URL const createTestConfig = require('../testUtils/createTestConfig'); // Defined globals var cloud_name = ''; @@ -1019,6 +1020,32 @@ describe("utils", function () { }); }); }); + describe('Context metadata to user variables', function (){ + this.timeout(TIMEOUT.MEDIUM); + before(function() { + return cloudinary.v2.uploader.upload(CONTEXT_PUBLIC_ID, + {public_id: 'CONTEXT_PUBLIC_ID', context: 'x=50|y=500'}) + .then((uploadResponse) => { + expect(uploadResponse).not.to.be(null); + }); + }); + after(function(){ + return cloudinary.v2.api.delete_resources('CONTEXT_PUBLIC_ID') + .then((deleteResponse) => { + expect(deleteResponse).not.to.be(null); + }); + }); + it('should use context value as user variables', function(){ + const options = { + variables: [["$xpos", "ctx:!x_pos!_to_f"], ["$ypos", "ctx:!y_pos!_to_f"]], + crop: "crop", + x: "$xpos * w", + y: "$ypos * h" + } + expect(cloudinary.image('CONTEXT_PUBLIC_ID', options)) + .to.contain('$xpos_ctx:!x_pos!_to_f,$ypos_ctx:!y_pos!_to_f,c_crop,x_$xpos_mul_w,y_$ypos_mul_h/CONTEXT_PUBLIC_ID') + }); + }); describe('User Define Variables', function () { it("array should define a set of variables", function () { var options, t; From 8473c0dd972a0db779f2e5e1a45b29c14f5c3006 Mon Sep 17 00:00:00 2001 From: Raya Straus Date: Mon, 15 Jun 2020 18:23:09 +0300 Subject: [PATCH 2/2] updated test --- test/utils/utils_spec.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/test/utils/utils_spec.js b/test/utils/utils_spec.js index 26bbc24a..d70f709f 100644 --- a/test/utils/utils_spec.js +++ b/test/utils/utils_spec.js @@ -18,7 +18,6 @@ const { clone, isString, merge, pickOnlyExistingValues } = utils; const { sharedExamples, itBehavesLike, test_cloudinary_url } = helper; const TEST_TAG = helper.TEST_TAG; -const CONTEXT_PUBLIC_ID = helper.IMAGE_URL const createTestConfig = require('../testUtils/createTestConfig'); // Defined globals var cloud_name = ''; @@ -1021,20 +1020,6 @@ describe("utils", function () { }); }); describe('Context metadata to user variables', function (){ - this.timeout(TIMEOUT.MEDIUM); - before(function() { - return cloudinary.v2.uploader.upload(CONTEXT_PUBLIC_ID, - {public_id: 'CONTEXT_PUBLIC_ID', context: 'x=50|y=500'}) - .then((uploadResponse) => { - expect(uploadResponse).not.to.be(null); - }); - }); - after(function(){ - return cloudinary.v2.api.delete_resources('CONTEXT_PUBLIC_ID') - .then((deleteResponse) => { - expect(deleteResponse).not.to.be(null); - }); - }); it('should use context value as user variables', function(){ const options = { variables: [["$xpos", "ctx:!x_pos!_to_f"], ["$ypos", "ctx:!y_pos!_to_f"]], @@ -1042,8 +1027,8 @@ describe("utils", function () { x: "$xpos * w", y: "$ypos * h" } - expect(cloudinary.image('CONTEXT_PUBLIC_ID', options)) - .to.contain('$xpos_ctx:!x_pos!_to_f,$ypos_ctx:!y_pos!_to_f,c_crop,x_$xpos_mul_w,y_$ypos_mul_h/CONTEXT_PUBLIC_ID') + expect(cloudinary.utils.generate_transformation_string(options)) + .to.contain('$xpos_ctx:!x_pos!_to_f,$ypos_ctx:!y_pos!_to_f,c_crop,x_$xpos_mul_w,y_$ypos_mul_h') }); }); describe('User Define Variables', function () {