@@ -15,7 +15,8 @@ sharedExamples = helper.sharedExamples
1515itBehavesLike = helper .itBehavesLike
1616TEST_TAG = helper .TEST_TAG
1717IMAGE_FILE = helper .IMAGE_FILE
18- IMAGE_URL = " http://res.cloudinary.com/demo/image/upload/sample"
18+ IMAGE_URL = helper .IMAGE_URL
19+ UPLOAD_TAGS = helper .UPLOAD_TAGS
1920
2021sharedExamples " a list with a cursor" , (testFunc , args ... )->
2122 xhr = request = requestStub = requestSpy = writeSpy = undefined
@@ -60,27 +61,45 @@ sharedExamples "accepts next_cursor", (testFunc, args...)->
6061 sinon .assert .calledWith requestSpy, sinon .match (query : sinon .match (/ next_cursor=23452342/ ))
6162
6263
64+ getAllTags = (arr ) ->
65+ arr .resources .map ((e ) -> e .tags ).reduce (((a , b ) -> a .concat (b)), [])
6366describe " api" , ->
6467 before " Verify Configuration" , ->
6568 config = cloudinary .config (true )
6669 if (! (config .api_key && config .api_secret ))
6770 expect ().fail (" Missing key and secret. Please set CLOUDINARY_URL." )
6871
72+ before (done ) ->
73+ @ timeout helper .TIMEOUT_LONG
74+
75+ Q .allSettled [
76+ cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID, tags : UPLOAD_TAGS, context : " key=value" , eager : [EXPLICIT_TRANSFORMATION])
77+ cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID_2, tags : UPLOAD_TAGS, context : " key=value" , eager : [EXPLICIT_TRANSFORMATION])
78+ cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID_5, tags : UPLOAD_TAGS, context : " #{ contextKey} =test" , eager : [EXPLICIT_TRANSFORMATION])
79+ cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID_6, tags : UPLOAD_TAGS, context : " #{ contextKey} =alt-test" , eager : [EXPLICIT_TRANSFORMATION])]
80+ .finally ->
81+ done ()
82+
6983 after (done )->
84+ @ timeout helper .TIMEOUT_LONG
7085 if cloudinary .config ().keep_test_products
7186 done ()
7287 else
7388 config = cloudinary .config ()
7489 if (! (config .api_key && config .api_secret ))
7590 expect ().fail (" Missing key and secret. Please set CLOUDINARY_URL." )
7691
77- cloudinary .v2 .api .delete_resources_by_tag TEST_TAG, (error , result ) ->
78- if error?
79- done (new Error error .message )
80- else
81- done ()
92+ Q .allSettled [
93+ cloudinary .v2 .api .delete_resources_by_tag TEST_TAG
94+ cloudinary .v2 .api .delete_transformation (NAMED_TRANSFORMATION)
95+ cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET1)
96+ cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET2)
97+ cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET3)
98+ cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET4)]
99+ .finally ->
100+ done ()
82101
83- SUFFIX = process . env . TRAVIS_JOB_ID || Math . floor ( Math . random () * 99999 )
102+ SUFFIX = helper . SUFFIX
84103 PUBLIC_ID_PREFIX = " npm_api_test"
85104 PUBLIC_ID = PUBLIC_ID_PREFIX + SUFFIX
86105 PUBLIC_ID_1 = PUBLIC_ID_PREFIX + " _1_" + SUFFIX
@@ -96,9 +115,8 @@ describe "api", ->
96115 API_TEST_UPLOAD_PRESET3 = " api_test_upload_preset_3_" + SUFFIX
97116 API_TEST_UPLOAD_PRESET4 = " api_test_upload_preset_4_" + SUFFIX
98117
99- random_width = Math .floor (Math .random () * 9999 )
100- EXPLICIT_TRANSFORMATION_NAME = " c_scale,w_" + random_width
101- EXPLICIT_TRANSFORMATION = {width : random_width, crop : " scale" }
118+ EXPLICIT_TRANSFORMATION_NAME = " c_scale,l_text:Arial_60:#{ TEST_TAG} ,w_100"
119+ EXPLICIT_TRANSFORMATION = {width : 100 , crop : " scale" , overlay : " text:Arial_60:#{ TEST_TAG} " }
102120
103121 find_by_attr = (elements , attr , value ) ->
104122 for element in elements
@@ -115,30 +133,7 @@ describe "api", ->
115133 expect (result).to .be .an (Object )
116134 callback (result)
117135
118- before (done ) ->
119- @ timeout helper .TIMEOUT_LONG
120- @timestamp_tag = " #{ TEST_TAG} _#{ cloudinary .utils .timestamp ()} "
121-
122- Q .allSettled [
123- cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID, tags : [TEST_TAG, @timestamp_tag ], context : " key=value" , eager : [EXPLICIT_TRANSFORMATION])
124- cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID_2, tags : [TEST_TAG, @timestamp_tag ], context : " key=value" , eager : [EXPLICIT_TRANSFORMATION])
125- cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID_5, tags : [TEST_TAG, @timestamp_tag ], context : " test-key=test" , eager : [EXPLICIT_TRANSFORMATION])
126- cloudinary .v2 .uploader .upload (IMAGE_FILE, public_id : PUBLIC_ID_6, tags : [TEST_TAG, @timestamp_tag ], context : " test-key=alt-test" , eager : [EXPLICIT_TRANSFORMATION])]
127- .finally ->
128- done ()
129-
130- after (done ) ->
131- @ timeout helper .TIMEOUT_LONG
132- @timestamp_tag = " #{ TEST_TAG} _#{ cloudinary .utils .timestamp ()} "
133-
134- Q .all [
135- cloudinary .v2 .api .delete_transformation (NAMED_TRANSFORMATION)
136- cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET1)
137- cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET2)
138- cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET3)
139- cloudinary .v2 .api .delete_upload_preset (API_TEST_UPLOAD_PRESET4)]
140- .finally ->
141- done ()
136+ contextKey = " test-key#{ helper .SUFFIX } "
142137
143138 describe " resources" , ()->
144139 itBehavesLike " a list with a cursor" , cloudinary .v2 .api .resources
@@ -151,7 +146,7 @@ describe "api", ->
151146
152147 it " should allow listing resources" , (done ) ->
153148 @ timeout helper .TIMEOUT_MEDIUM
154- cloudinary .v2 .uploader .upload IMAGE_FILE, tags : [TEST_TAG, @timestamp_tag ] , (error , result )->
149+ cloudinary .v2 .uploader .upload IMAGE_FILE, tags : UPLOAD_TAGS , (error , result )->
155150 done (new Error error .message ) if error?
156151 public_id = result .public_id
157152 cloudinary .v2 .api .resources (error, result) ->
@@ -163,7 +158,7 @@ describe "api", ->
163158
164159 it " should allow listing resources by type" , (done ) ->
165160 @ timeout helper .TIMEOUT_MEDIUM
166- cloudinary .v2 .uploader .upload IMAGE_FILE, tags : [TEST_TAG, @timestamp_tag ] , (error , result )->
161+ cloudinary .v2 .uploader .upload IMAGE_FILE, tags : UPLOAD_TAGS , (error , result )->
167162 return done (new Error error .message ) if error?
168163 public_id = result .public_id
169164 cloudinary .v2 .api .resources type : " upload" , (error , result ) ->
@@ -189,21 +184,21 @@ describe "api", ->
189184 return done (new Error error .message ) if error?
190185 expect (result .resources .map ((e ) -> e .public_id )).to .contain (PUBLIC_ID)
191186 .and .contain (PUBLIC_ID_2)
192- expect (result . resources . map (( e ) -> e . tags [ 0 ] )).to .contain (TEST_TAG)
187+ expect (getAllTags (result )).to .contain (TEST_TAG)
193188 expect (result .resources .map ((e ) -> if e .context ? then e .context .custom .key else null )).to .contain (" value" )
194189 done ()
195190
196191
197192 it " should allow listing resources by context only" , (done ) ->
198193 @ timeout helper .TIMEOUT_MEDIUM
199- cloudinary .v2 .api .resources_by_context " test-key " ,null , (error , result ) ->
194+ cloudinary .v2 .api .resources_by_context contextKey ,null , (error , result ) ->
200195 return done (new Error error .message ) if error?
201196 expect (result .resources ).to .have .length (2 )
202197 done ()
203198
204199 it " should allow listing resources by context key and value" , (done ) ->
205200 @ timeout helper .TIMEOUT_MEDIUM
206- cloudinary .v2 .api .resources_by_context " test-key " ," test" , (error , result ) ->
201+ cloudinary .v2 .api .resources_by_context contextKey ," test" , (error , result ) ->
207202 return done (new Error error .message ) if error?
208203 expect (result .resources ).to .have .length (1 )
209204 done ()
@@ -214,16 +209,16 @@ describe "api", ->
214209 return done (new Error error .message ) if error?
215210 resource = find_by_attr (result .resources , " public_id" , PUBLIC_ID)
216211 expect (result .resources .map ((e ) -> e .public_id ).sort ()).to .eql ([PUBLIC_ID,PUBLIC_ID_2])
217- expect (result . resources . map (( e ) -> e . tags [ 0 ] )).to .contain (TEST_TAG)
212+ expect (getAllTags (result )).to .contain (TEST_TAG)
218213 expect (result .resources .map ((e ) -> e .context .custom .key )).to .contain (" value" )
219214 done ()
220215
221216 it " should allow listing resources specifying direction" , (done ) ->
222217 @ timeout helper .TIMEOUT_MEDIUM
223- cloudinary .v2 .api .resources_by_tag @timestamp_tag , type : " upload" , direction : " asc" , (error , result ) =>
218+ cloudinary .v2 .api .resources_by_tag TEST_TAG , type : " upload" , max_results : 500 , direction : " asc" , (error , result ) =>
224219 return done (new Error error .message ) if error?
225220 asc = (resource .public_id for resource in result .resources )
226- cloudinary .v2 .api .resources_by_tag @timestamp_tag , type : " upload" , direction : " desc" , (error , result ) ->
221+ cloudinary .v2 .api .resources_by_tag TEST_TAG , type : " upload" , max_results : 500 , direction : " desc" , (error , result ) ->
227222 return done (new Error error .message ) if error?
228223 desc = (resource .public_id for resource in result .resources )
229224 expect (asc .reverse ()).to .eql (desc)
@@ -251,7 +246,7 @@ describe "api", ->
251246
252247 it " should allow get resource metadata" , (done ) ->
253248 @ timeout helper .TIMEOUT_LONG
254- cloudinary .v2 .uploader .upload IMAGE_FILE, tags : [TEST_TAG, @timestamp_tag ] , eager : [EXPLICIT_TRANSFORMATION], (error , result )->
249+ cloudinary .v2 .uploader .upload IMAGE_FILE, tags : UPLOAD_TAGS , eager : [EXPLICIT_TRANSFORMATION], (error , result )->
255250 done (new Error error .message ) if error?
256251 public_id = result .public_id
257252 cloudinary .v2 .api .resource public_id, (error , resource ) ->
@@ -265,7 +260,7 @@ describe "api", ->
265260 describe " delete" , ()->
266261 it " should allow deleting derived resource" , (done ) ->
267262 @ timeout helper .TIMEOUT_MEDIUM
268- cloudinary .v2 .uploader .upload IMAGE_FILE, eager : [width : 101 , crop : " scale" ], (error , r ) ->
263+ cloudinary .v2 .uploader .upload IMAGE_FILE, tags : UPLOAD_TAGS, eager : [width : 101 , crop : " scale" ], (error , r ) ->
269264 return done (new Error error .message ) if error?
270265 public_id = r .public_id
271266 cloudinary .v2 .api .resource public_id, (error , resource ) ->
@@ -284,7 +279,7 @@ describe "api", ->
284279
285280 it " should allow deleting resources" , (done ) ->
286281 @ timeout helper .TIMEOUT_MEDIUM
287- cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : PUBLIC_ID_3, (error , r ) ->
282+ cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : PUBLIC_ID_3, tags : UPLOAD_TAGS, (error , r ) ->
288283 return done (new Error error .message ) if error?
289284 cloudinary .v2 .api .resource PUBLIC_ID_3, (error , resource ) ->
290285 expect (resource).not .to .eql (undefined )
@@ -299,7 +294,7 @@ describe "api", ->
299294 itBehavesLike " accepts next_cursor" , cloudinary .v2 .api .delete_resources_by_prefix , " prefix_foobar"
300295 it " should allow deleting resources by prefix" , (done ) ->
301296 @ timeout helper .TIMEOUT_MEDIUM
302- cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : " api_test_by_prefix" , (error , r ) ->
297+ cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : " api_test_by_prefix" , tags : UPLOAD_TAGS, (error , r ) ->
303298 return done (new Error error .message ) if error?
304299 cloudinary .v2 .api .resource " api_test_by_prefix" , (error , resource ) ->
305300 expect (resource).not .to .eql (undefined )
@@ -311,14 +306,15 @@ describe "api", ->
311306
312307
313308 describe " delete_resources_by_tag" , ->
314- itBehavesLike " accepts next_cursor" , cloudinary .v2 .api .delete_resources_by_prefix , " api_test_tag_for_delete"
309+ deleteTestTag = TEST_TAG + " _delete"
310+ itBehavesLike " accepts next_cursor" , cloudinary .v2 .api .delete_resources_by_prefix , deleteTestTag
315311 it " should allow deleting resources by tags" , (done ) ->
316312 @ timeout helper .TIMEOUT_MEDIUM
317- cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : PUBLIC_ID_4, tags : [ " api_test_tag_for_delete " ] , (error , result ) ->
313+ cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : PUBLIC_ID_4, tags : UPLOAD_TAGS . concat ([deleteTestTag]) , (error , result ) ->
318314 return done (new Error error .message ) if error?
319315 cloudinary .v2 .api .resource PUBLIC_ID_4, (error , resource ) ->
320316 expect (resource).to .be .ok ()
321- cloudinary .v2 .api .delete_resources_by_tag " api_test_tag_for_delete " , (error , result ) ->
317+ cloudinary .v2 .api .delete_resources_by_tag deleteTestTag , (error , result ) ->
322318 return done (new Error error .message ) if error?
323319 cloudinary .v2 .api .resource PUBLIC_ID_4, (error , result ) ->
324320 expect (error).to .be .an (Object )
@@ -336,7 +332,7 @@ describe "api", ->
336332
337333 it " should allow listing tag by prefix " , (done ) =>
338334 @ timeout helper .TIMEOUT_MEDIUM
339- cloudinary .v2 .api .tags prefix : TEST_TAG . slice ( 0 , 13 ) , (error , result ) =>
335+ cloudinary .v2 .api .tags prefix : TEST_TAG[ 0 .. - 5 ] , (error , result ) =>
340336 return done (new Error error .message ) if error?
341337 expect (result .tags ).to .contain (TEST_TAG)
342338 done ()
@@ -495,7 +491,7 @@ describe "api", ->
495491 describe " keep_original: yes" , ->
496492 it " should allow deleting all derived resources" , (done ) ->
497493 @ timeout helper .TIMEOUT_MEDIUM
498- cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : " api_test5" , eager : {transformation : {width : 101 , crop : " scale" }}, (error , upload_result ) ->
494+ cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : " api_test5" , eager : {transformation : {width : 101 , crop : " scale" }}, tags : UPLOAD_TAGS, (error , upload_result ) ->
499495 cloudinary .v2 .api .resource " api_test5" , (error , resource ) ->
500496 return done (new Error error .message ) if error?
501497 expect (resource).to .be .an (Object )
@@ -648,7 +644,7 @@ describe "api", ->
648644 describe ' .restore' , ->
649645 @ timeout helper .TIMEOUT_MEDIUM
650646 before (done )->
651- cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : " api_test_restore" , backup : true , tags : [TEST_TAG] , (error , result )->
647+ cloudinary .v2 .uploader .upload IMAGE_FILE, public_id : " api_test_restore" , backup : true , tags : UPLOAD_TAGS , (error , result )->
652648 return done (new Error error .message ) if error?
653649 cloudinary .v2 .api .resource " api_test_restore" , (error , resource )->
654650 return done (new Error error .message ) if error?
@@ -686,7 +682,7 @@ describe "api", ->
686682 itBehavesLike " a list with a cursor" , cloudinary .v2 .api .upload_mappings
687683 it ' should create mapping' , (done )->
688684 @ timeout helper .TIMEOUT_LONG
689- cloudinary .v2 .api .create_upload_mapping mapping, template : " http://cloudinary.com" , tags : [TEST_TAG] , (error , result )->
685+ cloudinary .v2 .api .create_upload_mapping mapping, template : " http://cloudinary.com" , tags : UPLOAD_TAGS , (error , result )->
690686 return done (new Error error .message ) if error?
691687 deleteMapping = true
692688 cloudinary .v2 .api .upload_mapping mapping, (error , result )->
@@ -711,20 +707,19 @@ describe "api", ->
711707 describe " publish" , ->
712708 @ timeout helper .TIMEOUT_LONG
713709 i = 0
714- suffix = ->
715- ++ i
716710
717711 publishTestId = " "
718712 publishTestTag = " "
719713 idsToDelete = []
720714 beforeEach (done )->
721- publishTestTag = TEST_TAG + suffix ()
722- cloudinary .v2 .uploader .upload IMAGE_FILE, type : " authenticated" , tags : [TEST_TAG, publishTestTag], (error , result )->
715+ publishTestTag = TEST_TAG + i ++
716+ cloudinary .v2 .uploader .upload IMAGE_FILE, type : " authenticated" , tags : UPLOAD_TAGS . concat ([ publishTestTag]) , (error , result )->
723717 return done (new Error error .message ) if error?
724718 publishTestId = result .public_id
725719 idsToDelete .push publishTestId
726720 done ()
727721 after (done )->
722+ # cleanup any resource that were not published
728723 cloudinary .v2 .api .delete_resources idsToDelete, type : " authenticated" , (error , result )->
729724 return done (new Error error .message ) if error?
730725 done ()
@@ -765,7 +760,7 @@ describe "api", ->
765760 access_mode_tag = ' '
766761 beforeEach (done )->
767762 access_mode_tag = TEST_TAG + " access_mode" + i++
768- cloudinary .v2 .uploader .upload IMAGE_FILE, access_mode : " authenticated" , tags : [TEST_TAG, access_mode_tag], (error , result )->
763+ cloudinary .v2 .uploader .upload IMAGE_FILE, access_mode : " authenticated" , tags : UPLOAD_TAGS . concat ([ access_mode_tag]) , (error , result )->
769764 return done (new Error error .message ) if error?
770765 publicId = result .public_id
771766 expect (result .access_mode ).to .be (" authenticated" )
0 commit comments