1+ const assert = require ( 'assert' ) ;
12const fs = require ( 'fs' ) ;
23const os = require ( 'os' ) ;
34const defaults = require ( 'lodash/defaults' ) ;
@@ -7,14 +8,27 @@ const TIMEOUT = require('../testUtils/testConstants').TIMEOUT;
78const describe = require ( '../testUtils/suite' ) ;
89const wait = require ( '../testUtils/helpers/wait' ) ;
910const generateBreakpoints = require ( `../../${ helper . libPath } /utils/generateBreakpoints` ) ;
10- const { srcsetUrl, generateSrcsetAttribute } = require ( `../../${ helper . libPath } /utils/srcsetUtils` ) ;
11+ const {
12+ srcsetUrl,
13+ generateSrcsetAttribute
14+ } = require ( `../../${ helper . libPath } /utils/srcsetUtils` ) ;
1115
1216const utils = cloudinary . utils ;
13- const { clone, isString, merge, pickOnlyExistingValues } = utils ;
14- const { sharedExamples, itBehavesLike, test_cloudinary_url } = helper ;
17+ const {
18+ clone,
19+ isString,
20+ merge,
21+ pickOnlyExistingValues
22+ } = utils ;
23+ const {
24+ sharedExamples,
25+ itBehavesLike,
26+ test_cloudinary_url
27+ } = helper ;
1528
1629const TEST_TAG = helper . TEST_TAG ;
1730const createTestConfig = require ( '../testUtils/createTestConfig' ) ;
31+ const { clear_blank} = require ( "../../lib/utils" ) ;
1832// Defined globals
1933var cloud_name = '' ;
2034
@@ -782,10 +796,13 @@ describe("utils", function () {
782796 param : 'underlay' ,
783797 letter : 'u'
784798 }
785- ] . forEach ( function ( { param, letter } ) {
799+ ] . forEach ( function ( {
800+ param,
801+ letter
802+ } ) {
786803 layers_options . forEach ( function ( [ name , layer , result ] ) {
787804 it ( `should support ${ name } ${ param } ` , function ( ) {
788- expect ( [ "test" , { [ param ] : layer } ] ) . to . produceUrl ( `http://res.cloudinary.com/${ cloud_name } /image/upload/${ letter } _${ result } /test` ) . and . emptyOptions ( ) ;
805+ expect ( [ "test" , { [ param ] : layer } ] ) . to . produceUrl ( `http://res.cloudinary.com/${ cloud_name } /image/upload/${ letter } _${ result } /test` ) . and . emptyOptions ( ) ;
789806 } ) ;
790807 } ) ;
791808 it ( `should not pass width/height to html for ${ param } ` , function ( ) {
@@ -833,12 +850,12 @@ describe("utils", function () {
833850 } ) ;
834851 describe ( 'fps' , function ( ) {
835852 [
836- [ { fps : "24-29.97" } , "fps_24-29.97" ] ,
837- [ { fps : 24 } , "fps_24" ] ,
838- [ { fps : 24.5 } , "fps_24.5" ] ,
839- [ { fps : "24" } , "fps_24" ] ,
840- [ { fps : "-24" } , "fps_-24" ] ,
841- [ { fps : [ 24 , 29.97 ] } , "fps_24-29.97" ]
853+ [ { fps : "24-29.97" } , "fps_24-29.97" ] ,
854+ [ { fps : 24 } , "fps_24" ] ,
855+ [ { fps : 24.5 } , "fps_24.5" ] ,
856+ [ { fps : "24" } , "fps_24" ] ,
857+ [ { fps : "-24" } , "fps_-24" ] ,
858+ [ { fps : [ 24 , 29.97 ] } , "fps_24-29.97" ]
842859 ] . forEach ( function ( [ option , expected ] ) {
843860 expect ( cloudinary . utils . generate_transformation_string ( option ) ) . to . eql ( expected ) ;
844861 } ) ;
@@ -1034,8 +1051,8 @@ describe("utils", function () {
10341051 } ) ;
10351052 } ) ;
10361053
1037- describe ( 'Context metadata to user variables' , function ( ) {
1038- it ( 'should use context value as user variables' , function ( ) {
1054+ describe ( 'Context metadata to user variables' , function ( ) {
1055+ it ( 'should use context value as user variables' , function ( ) {
10391056 const options = {
10401057 variables : [ [ "$xpos" , "ctx:!x_pos!_to_f" ] , [ "$ypos" , "ctx:!y_pos!_to_f" ] ] ,
10411058 crop : "crop" ,
@@ -1253,7 +1270,7 @@ describe("utils", function () {
12531270 expect ( [ "sample" , opt ] ) . to . produceUrl ( `http://res.cloudinary.com/${ cloud_name } /image/upload/l_${ result } /sample` ) . and . emptyOptions ( ) . and . beServedByCloudinary ( done ) ;
12541271 } ) ;
12551272 if ( ! isString ( options ) ) {
1256- itBehavesLike ( "a signed url" , { overlay : options } , `l_${ result } ` ) ;
1273+ itBehavesLike ( "a signed url" , { overlay : options } , `l_${ result } ` ) ;
12571274 }
12581275 } ) ;
12591276 it ( "should not pass width/height to html for overlay" , function ( ) {
@@ -1308,19 +1325,19 @@ describe("utils", function () {
13081325 [ scaled ( ) , sepia ( ) ] ,
13091326 'c_scale,h_200,w_100|c_lfill,e_sepia,w_400' ] ,
13101327 [ 'should support transformations with multiple components' ,
1311- [ { transformation : [ scaled ( ) , sepia ( ) ] } , sepia ( ) ] ,
1328+ [ { transformation : [ scaled ( ) , sepia ( ) ] } , sepia ( ) ] ,
13121329 'c_scale,h_200,w_100/c_lfill,e_sepia,w_400|c_lfill,e_sepia,w_400' ] ,
13131330 [ 'should concatenate format at the end of the transformation' ,
1314- ( [ scaled ( { format : 'gif' } ) , sepia ( ) ] ) ,
1331+ ( [ scaled ( { format : 'gif' } ) , sepia ( ) ] ) ,
13151332 'c_scale,h_200,w_100/gif|c_lfill,e_sepia,w_400' ] ,
13161333 [ 'should support an empty format' ,
1317- ( [ scaled ( { format : '' } ) , sepia ( ) ] ) ,
1334+ ( [ scaled ( { format : '' } ) , sepia ( ) ] ) ,
13181335 'c_scale,h_200,w_100/|c_lfill,e_sepia,w_400' ] ,
13191336 [ 'should treat a null format as none' ,
1320- ( [ scaled ( { format : null } ) , sepia ( ) ] ) ,
1337+ ( [ scaled ( { format : null } ) , sepia ( ) ] ) ,
13211338 'c_scale,h_200,w_100|c_lfill,e_sepia,w_400' ] ,
13221339 [ 'should concatenate format at the end of the transformation' ,
1323- ( [ scaled ( { format : 'gif' } ) , sepia ( { format : 'jpg' } ) ] ) ,
1340+ ( [ scaled ( { format : 'gif' } ) , sepia ( { format : 'jpg' } ) ] ) ,
13241341 'c_scale,h_200,w_100/gif|c_lfill,e_sepia,w_400/jpg' ] ,
13251342 [ 'should support transformations with multiple components and format' ,
13261343 [ {
@@ -1399,7 +1416,7 @@ describe("utils", function () {
13991416 test_cloudinary_url ( "folder/test" , { } ,
14001417 `http://res.cloudinary.com/${ cloud_name } /image/upload/v1/folder/test` , { } ) ;
14011418 test_cloudinary_url ( "folder/test" ,
1402- { force_version : false } , `http://res.cloudinary.com/${ cloud_name } /image/upload/folder/test` , { } ) ;
1419+ { force_version : false } , `http://res.cloudinary.com/${ cloud_name } /image/upload/folder/test` , { } ) ;
14031420 } ) ;
14041421 it ( "explicitly set version is always passed" , function ( ) {
14051422 test_cloudinary_url ( "test" ,
@@ -1414,14 +1431,14 @@ describe("utils", function () {
14141431 } , `http://res.cloudinary.com/${ cloud_name } /image/upload/v1234/folder/test` , { } ) ;
14151432 } ) ;
14161433 it ( "should use force_version from config" , function ( ) {
1417- cloudinary . config ( { force_version : false } ) ;
1434+ cloudinary . config ( { force_version : false } ) ;
14181435 test_cloudinary_url ( "folder/test" ,
14191436 { } , `http://res.cloudinary.com/${ cloud_name } /image/upload/folder/test` , { } ) ;
14201437 } ) ;
14211438 it ( "should override config with options" , function ( ) {
1422- cloudinary . config ( { force_version : false } ) ;
1439+ cloudinary . config ( { force_version : false } ) ;
14231440 test_cloudinary_url ( "folder/test" ,
1424- { force_version : true } , `http://res.cloudinary.com/${ cloud_name } /image/upload/v1/folder/test` , { } ) ;
1441+ { force_version : true } , `http://res.cloudinary.com/${ cloud_name } /image/upload/v1/folder/test` , { } ) ;
14251442 } ) ;
14261443 it ( "should allow to shorted image/upload urls" , function ( ) {
14271444 test_cloudinary_url ( "test" , {
@@ -1459,8 +1476,8 @@ describe("utils", function () {
14591476 'width' : 100 ,
14601477 'height' : 100
14611478 } ;
1462- valid_response_timestamp = ( Date . now ( ) / 1000 ) - 5000 ;
1463- invalid_response_timestamp = ( Date . now ( ) / 1000 ) - 10000 ;
1479+ valid_response_timestamp = ( Date . now ( ) / 1000 ) - 5000 ;
1480+ invalid_response_timestamp = ( Date . now ( ) / 1000 ) - 10000 ;
14641481 response_json = JSON . stringify ( expected_parameters ) ;
14651482 unexpected_response_json = JSON . stringify ( unexpected_parameters ) ;
14661483 } ) ;
@@ -1703,4 +1720,34 @@ describe("utils", function () {
17031720 expect ( utils . isRemoteUrl ( helper . IMAGE_FILE ) ) . not . to . be . ok ( ) ;
17041721 } ) ;
17051722 } ) ;
1723+
1724+ describe ( 'clear_blank' , ( ) => {
1725+ it ( 'should remove properties with nulls' , ( ) => {
1726+ const input = {
1727+ key1 : 'test' ,
1728+ key2 : null ,
1729+ key3 : false ,
1730+ key4 : 0
1731+ } ;
1732+ const clearedInput = clear_blank ( input ) ;
1733+ assert . deepStrictEqual ( clearedInput , {
1734+ key1 : 'test' ,
1735+ key3 : false ,
1736+ key4 : 0
1737+ } ) ;
1738+ } ) ;
1739+
1740+ it ( 'should remove nested null values' , ( ) => {
1741+ const input = {
1742+ key1 : 'test' ,
1743+ key2 : [ null ] ,
1744+ key3 : [ 1 , null ]
1745+ } ;
1746+ const clearedInput = clear_blank ( input ) ;
1747+ assert . deepStrictEqual ( clearedInput , {
1748+ key1 : 'test' ,
1749+ key3 : [ 1 ]
1750+ } ) ;
1751+ } ) ;
1752+ } )
17061753} ) ;
0 commit comments