Skip to content

Commit 53b2350

Browse files
nadavofirtocker
authored andcommitted
Added new parameters to generate-archive api + tests
1 parent c6aa42b commit 53b2350

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/utils.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,15 +895,17 @@ process_video_params = (param) ->
895895
# @private
896896
###
897897
exports.archive_params = (options = {})->
898+
allow_missing: exports.as_safe_bool(options.allow_missing)
898899
async: exports.as_safe_bool(options.async)
899900
flatten_folders: exports.as_safe_bool(options.flatten_folders)
900901
flatten_transformations: exports.as_safe_bool(options.flatten_transformations)
901902
keep_derived: exports.as_safe_bool(options.keep_derived)
902903
mode: options.mode
903904
notification_url: options.notification_url
904905
prefixes: options.prefixes && exports.build_array(options.prefixes)
905-
transformations: utils.build_eager(options.transformations)
906906
public_ids: options.public_ids && exports.build_array(options.public_ids)
907+
skip_transformation_name: exports.as_safe_bool(options.skip_transformation_name)
908+
transformations: utils.build_eager(options.transformations)
907909
tags: options.tags && exports.build_array(options.tags)
908910
target_format: options.target_format
909911
target_public_id: options.target_public_id

test/archivespec.coffee

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ api = cloudinary.v2.api
88
uploader = cloudinary.v2.uploader
99
zlib = require('zlib')
1010
sinon = require("sinon")
11+
ClientRequest = require('_http_client').ClientRequest
1112

1213
exec = require('child_process').exec
1314
execSync = require('child_process').execSync
@@ -27,6 +28,7 @@ ARCHIVE_TAG = TEST_TAG + "_archive"
2728

2829
publicId1 = ARCHIVE_TAG + "_1"
2930
publicId2 = ARCHIVE_TAG + "_2"
31+
publicIdRaw = ARCHIVE_TAG + "_3"
3032

3133
sharedExamples '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

Comments
 (0)