@@ -8,6 +8,7 @@ api = cloudinary.v2.api
88uploader = cloudinary .v2 .uploader
99zlib = require (' zlib' )
1010sinon = require (" sinon" )
11+ ClientRequest = require (' _http_client' ).ClientRequest
1112
1213exec = require (' child_process' ).exec
1314execSync = require (' child_process' ).execSync
@@ -27,6 +28,7 @@ ARCHIVE_TAG = TEST_TAG + "_archive"
2728
2829publicId1 = ARCHIVE_TAG + " _1"
2930publicId2 = ARCHIVE_TAG + " _2"
31+ publicIdRaw = ARCHIVE_TAG + " _3"
3032
3133sharedExamples ' archive' , ->
3234
@@ -35,7 +37,7 @@ sharedExamples 'archive', ->
3537 if (! (config .api_key && config .api_secret ))
3638 expect ().fail (" Missing key and secret. Please set CLOUDINARY_URL." )
3739
38- before ( done ) ->
40+ before ->
3941 @ timeout helper .TIMEOUT_LONG
4042
4143 Q .all [
@@ -53,10 +55,13 @@ sharedExamples 'archive', ->
5355 transformation : {
5456 effect : " blackwhite"
5557 }
58+ )
59+ uploader .upload (
60+ IMAGE_URL,
61+ public_id : publicIdRaw
62+ resource_type : " raw"
63+ tags : helper .UPLOAD_TAGS .concat ([ARCHIVE_TAG])
5664 )]
57- .finally ->
58- done ()
59-
6065 after ->
6166 cloudinary .v2 .api .delete_resources_by_tag (ARCHIVE_TAG) unless cloudinary .config ().keep_test_products
6267
@@ -108,18 +113,18 @@ describe "uploader", ->
108113 @ timeout helper .TIMEOUT_LONG
109114 archive_result = undefined
110115
111- before ( done ) ->
116+ before ->
112117 @ timeout helper .TIMEOUT_LONG
113118 uploader .create_archive (
114119 target_public_id : ' gem_archive_test'
115120 public_ids : [publicId2, publicId1]
116121 target_tags : [TEST_TAG, ARCHIVE_TAG]
117122 mode : ' create'
123+ skip_transformation_name : true
118124 ,
119125 (error , result )->
120- return done ( new Error error .message ) if error?
126+ new Error error .message if error?
121127 archive_result = result
122- done ()
123128 )
124129 it ' should return a Hash' , ->
125130 expect (archive_result).to .be .an (Object )
@@ -142,11 +147,18 @@ describe "uploader", ->
142147 expect (archive_result).to .have .keys (expected_keys)
143148 describe ' .create_zip' , ->
144149 @ timeout helper .TIMEOUT_LONG
145- spy = undefined
150+ spy1 = undefined
151+ spy2 = undefined
152+ xhr = undefined
146153 before ->
147- spy = sinon .spy cloudinary .uploader , " create_archive"
154+ spy1 = sinon .spy cloudinary .uploader , " create_archive"
155+ spy2 = sinon .spy ClientRequest .prototype , ' write'
156+ xhr = sinon .useFakeXMLHttpRequest ()
148157 after ->
149- spy .reset ()
150- it ' should call create_archive with "zip" format' , ->
151- uploader .create_zip ({tags : TEST_TAG})
152- expect (spy .calledWith (null , {tags : TEST_TAG}, " zip" )).to .be .ok ()
158+ spy1 .restore ()
159+ spy2 .restore ()
160+ xhr .restore ()
161+ it ' should call create_archive with "zip" format and ignore missing resources' , ->
162+ uploader .create_zip ({tags : TEST_TAG, public_ids : [publicIdRaw, " non-existing-resource" ], resource_type : " raw" , allow_missing : true })
163+ expect (spy1 .calledWith (null , {tags : TEST_TAG, public_ids : [publicIdRaw, " non-existing-resource" ], resource_type : " raw" , allow_missing : true }, " zip" )).to .be .ok ()
164+ sinon .assert .calledWith (spy2, sinon .match ((arg )-> arg .toString ().match (/ name="allow_missing"\s * 1/ )))
0 commit comments