From 7e985964988aac9ba0ba80118bfb9fe07269d87c Mon Sep 17 00:00:00 2001 From: nadavofi Date: Wed, 29 Mar 2017 18:11:24 +0300 Subject: [PATCH 1/2] Added new parameters to generate-archive api + tests --- src/utils.coffee | 4 +++- test/archivespec.coffee | 38 +++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/utils.coffee b/src/utils.coffee index 76d34004..3d714678 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -886,6 +886,7 @@ process_video_params = (param) -> # @private ### exports.archive_params = (options = {})-> + allow_missing: exports.as_safe_bool(options.allow_missing) async: exports.as_safe_bool(options.async) flatten_folders: exports.as_safe_bool(options.flatten_folders) flatten_transformations: exports.as_safe_bool(options.flatten_transformations) @@ -893,8 +894,9 @@ exports.archive_params = (options = {})-> mode: options.mode notification_url: options.notification_url prefixes: options.prefixes && exports.build_array(options.prefixes) - transformations: utils.build_eager(options.transformations) public_ids: options.public_ids && exports.build_array(options.public_ids) + skip_transformation_name: exports.as_safe_bool(options.skip_transformation_name) + transformations: utils.build_eager(options.transformations) tags: options.tags && exports.build_array(options.tags) target_format: options.target_format target_public_id: options.target_public_id diff --git a/test/archivespec.coffee b/test/archivespec.coffee index 6957610c..88b1d824 100644 --- a/test/archivespec.coffee +++ b/test/archivespec.coffee @@ -8,6 +8,7 @@ api = cloudinary.v2.api uploader = cloudinary.v2.uploader zlib = require('zlib') sinon = require("sinon") +ClientRequest = require('_http_client').ClientRequest exec = require('child_process').exec execSync = require('child_process').execSync @@ -27,6 +28,7 @@ ARCHIVE_TAG = TEST_TAG + "_archive" publicId1 = ARCHIVE_TAG + "_1" publicId2 = ARCHIVE_TAG + "_2" +publicIdRaw = ARCHIVE_TAG + "_3" sharedExamples 'archive', -> @@ -35,7 +37,7 @@ sharedExamples 'archive', -> if(!(config.api_key && config.api_secret)) expect().fail("Missing key and secret. Please set CLOUDINARY_URL.") - before (done)-> + before -> @timeout helper.TIMEOUT_LONG Q.all [ @@ -53,10 +55,13 @@ sharedExamples 'archive', -> transformation: { effect: "blackwhite" } + ) + uploader.upload( + IMAGE_URL, + public_id: publicIdRaw + resource_type: "raw" + tags: helper.UPLOAD_TAGS.concat([ARCHIVE_TAG]) )] - .finally -> - done() - after -> cloudinary.v2.api.delete_resources_by_tag(ARCHIVE_TAG) unless cloudinary.config().keep_test_products @@ -108,18 +113,18 @@ describe "uploader", -> @timeout helper.TIMEOUT_LONG archive_result = undefined - before (done)-> + before -> @timeout helper.TIMEOUT_LONG uploader.create_archive( target_public_id: 'gem_archive_test' public_ids: [publicId2, publicId1] target_tags: [TEST_TAG, ARCHIVE_TAG] mode: 'create' + skip_transformation_name: true , (error, result)-> - return done(new Error error.message) if error? + new Error error.message if error? archive_result = result - done() ) it 'should return a Hash', -> expect(archive_result).to.be.an(Object) @@ -142,11 +147,18 @@ describe "uploader", -> expect(archive_result).to.have.keys(expected_keys) describe '.create_zip', -> @timeout helper.TIMEOUT_LONG - spy = undefined + spy1 = undefined + spy2 = undefined + xhr = undefined before -> - spy = sinon.spy cloudinary.uploader, "create_archive" + spy1 = sinon.spy cloudinary.uploader, "create_archive" + spy2 = sinon.spy ClientRequest.prototype, 'write' + xhr = sinon.useFakeXMLHttpRequest() after -> - spy.reset() - it 'should call create_archive with "zip" format', -> - uploader.create_zip({tags: TEST_TAG}) - expect(spy.calledWith(null, {tags: TEST_TAG}, "zip")).to.be.ok() + spy1.restore() + spy2.restore() + xhr.restore() + it 'should call create_archive with "zip" format and ignore missing resources', -> + uploader.create_zip({tags: TEST_TAG, public_ids: [publicIdRaw, "non-existing-resource"], resource_type: "raw", allow_missing: true}) + expect(spy1.calledWith(null, {tags: TEST_TAG, public_ids: [publicIdRaw, "non-existing-resource"], resource_type: "raw", allow_missing: true}, "zip")).to.be.ok() + sinon.assert.calledWith(spy2, sinon.match((arg)-> arg.toString().match(/name="allow_missing"\s*1/))) \ No newline at end of file From 199d78411aaf80532ccf6ce9c6d839cb19128eb2 Mon Sep 17 00:00:00 2001 From: nadavofi Date: Sun, 2 Apr 2017 13:06:51 +0300 Subject: [PATCH 2/2] Avoid returning promises when invoking done() in spec to support Mocha 3.X --- test/api_spec.coffee | 120 ++++++++++++++++++++++++++-- test/streaming_profiles_spec.coffee | 13 ++- test/uploader_spec.coffee | 78 +++++++++++++++++- test/utils_spec.coffee | 2 + 4 files changed, 205 insertions(+), 8 deletions(-) diff --git a/test/api_spec.coffee b/test/api_spec.coffee index f6d8a50c..c401a890 100644 --- a/test/api_spec.coffee +++ b/test/api_spec.coffee @@ -98,7 +98,7 @@ describe "api", -> cloudinary.v2.uploader.upload(IMAGE_FILE, public_id: PUBLIC_ID_6, tags: UPLOAD_TAGS, context: "#{contextKey}=alt-test", eager: [EXPLICIT_TRANSFORMATION])] .finally -> done() - + true after (done)-> @timeout helper.TIMEOUT_LONG if cloudinary.config().keep_test_products @@ -116,7 +116,8 @@ describe "api", -> cloudinary.v2.api.delete_upload_preset(API_TEST_UPLOAD_PRESET3) cloudinary.v2.api.delete_upload_preset(API_TEST_UPLOAD_PRESET4)] .finally -> - done() + done() + true find_by_attr = (elements, attr, value) -> for element in elements @@ -132,6 +133,7 @@ describe "api", -> expect(error).to.be undefined expect(result).to.be.an(Object) callback(result) + true contextKey = "test-key#{helper.SUFFIX}" @@ -143,6 +145,7 @@ describe "api", -> return done(new Error error.message) if error? expect(result.resource_types).to.contain("image") done() + true it "should allow listing resources", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -155,6 +158,8 @@ describe "api", -> expect(resource).not.to.eql(undefined) expect(resource.type).to.eql("upload") done() + true + true it "should allow listing resources by type", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -167,6 +172,8 @@ describe "api", -> expect(resource).to.be.an(Object) expect(resource.type).to.eql("upload") done() + true + true it "should allow listing resources by prefix", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -176,6 +183,7 @@ describe "api", -> expect(public_ids).to.contain(PUBLIC_ID) expect(public_ids).to.contain(PUBLIC_ID_2) done() + true itBehavesLike "a list with a cursor", cloudinary.v2.api.resources_by_tag, TEST_TAG it "should allow listing resources by tag", (done) -> @@ -187,6 +195,7 @@ describe "api", -> expect(getAllTags(result)).to.contain(TEST_TAG) expect(result.resources.map((e) -> if e.context? then e.context.custom.key else null)).to.contain("value") done() + true it "should allow listing resources by context only", (done) -> @@ -195,6 +204,7 @@ describe "api", -> return done(new Error error.message) if error? expect(result.resources).to.have.length(2) done() + true it "should allow listing resources by context key and value", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -202,6 +212,7 @@ describe "api", -> return done(new Error error.message) if error? expect(result.resources).to.have.length(1) done() + true it "should allow listing resources by public ids", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -212,9 +223,10 @@ describe "api", -> expect(getAllTags(result)).to.contain(TEST_TAG) expect(result.resources.map((e) -> e.context.custom.key)).to.contain("value") done() + true it "should allow listing resources specifying direction", (done) -> - @timeout helper.TIMEOUT_MEDIUM + @timeout helper.TIMEOUT_LONG cloudinary.v2.api.resources_by_tag TEST_TAG, type: "upload", max_results: 500, direction: "asc", (error, result) => return done(new Error error.message) if error? asc = (resource.public_id for resource in result.resources) @@ -223,6 +235,8 @@ describe "api", -> desc = (resource.public_id for resource in result.resources) expect(asc.reverse()).to.eql(desc) done() + true + true it "should allow listing resources by start_at", (done) -> xhr = sinon.useFakeXMLHttpRequest() @@ -242,6 +256,7 @@ describe "api", -> writeSpy.restore() requestSpy.restore() xhr.restore() + true it "should allow get resource metadata", (done) -> @@ -256,6 +271,8 @@ describe "api", -> expect(resource.bytes).to.eql(3381) expect(resource.derived).to.have.length(1) done() + true + true describe "delete", ()-> it "should allow deleting derived resource", (done) -> @@ -276,6 +293,10 @@ describe "api", -> expect(resource).not.to.eql(undefined) expect(resource.derived).to.have.length(0) done() + true + true + true + true it "should allow deleting resources", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -289,6 +310,10 @@ describe "api", -> expect(error).to.be.an(Object) expect(error.http_code).to.eql 404 done() + true + true + true + true describe "delete_resources_by_prefix", -> itBehavesLike "accepts next_cursor", cloudinary.v2.api.delete_resources_by_prefix, "prefix_foobar" @@ -303,6 +328,10 @@ describe "api", -> expect(error).to.be.an(Object) expect(error.http_code).to.eql 404 done() + true + true + true + true describe "delete_resources_by_tag", -> @@ -320,6 +349,10 @@ describe "api", -> expect(error).to.be.an(Object) expect(error.http_code).to.eql 404 done() + true + true + true + true describe "tags", ()-> itBehavesLike "a list with a cursor", cloudinary.v2.api.tags @@ -329,6 +362,7 @@ describe "api", -> return done(new Error error.message) if error? expect(result.tags).to.contain(TEST_TAG) done() + true it "should allow listing tag by prefix ", (done) => @timeout helper.TIMEOUT_MEDIUM @@ -336,6 +370,7 @@ describe "api", -> return done(new Error error.message) if error? expect(result.tags).to.contain(TEST_TAG) done() + true it "should allow listing tag by prefix if not found", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -343,6 +378,7 @@ describe "api", -> return done(new Error error.message) if error? expect(result.tags).to.be.empty() done() + true describe "transformations", ()-> itBehavesLike "a list with a cursor", cloudinary.v2.api.transformation, EXPLICIT_TRANSFORMATION_NAME @@ -356,6 +392,7 @@ describe "api", -> expect(transformation).not.to.eql(undefined) expect(transformation.used).to.be.ok done() + true it "should allow getting transformation metadata", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -363,6 +400,7 @@ describe "api", -> expect(transformation).not.to.eql(undefined) expect(transformation.info).to.eql([EXPLICIT_TRANSFORMATION]) done() + true it "should allow getting transformation metadata by info", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -370,6 +408,7 @@ describe "api", -> expect(transformation).not.to.eql(undefined) expect(transformation.info).to.eql([EXPLICIT_TRANSFORMATION]) done() + true it "should allow updating transformation allowed_for_strict", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -382,6 +421,10 @@ describe "api", -> expect(transformation).not.to.eql(undefined) expect(transformation.allowed_for_strict).not.to.be.ok done() + true + true + true + true it "should allow creating named transformation", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -392,6 +435,8 @@ describe "api", -> expect(transformation.info).to.eql([crop: "scale", width: 102]) expect(transformation.used).not.to.be.ok done() + true + true it "should allow unsafe update of named transformation", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -402,6 +447,9 @@ describe "api", -> expect(transformation.info).to.eql([crop: "scale", width: 103]) expect(transformation.used).not.to.be.ok done() + true + true + true it "should allow deleting named transformation", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -409,6 +457,8 @@ describe "api", -> cloudinary.v2.api.transformation NAMED_TRANSFORMATION, (error, transformation) -> expect(error.http_code).to.eql 404 done() + true + true it "should allow deleting implicit transformation", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -418,6 +468,9 @@ describe "api", -> cloudinary.v2.api.transformation EXPLICIT_TRANSFORMATION_NAME, (error, transformation) -> expect(error.http_code).to.eql 404 done() + true + true + true describe "upload_preset", ()-> itBehavesLike "a list with a cursor", cloudinary.v2.api.upload_presets @@ -428,21 +481,26 @@ describe "api", -> after_delete = -> delete_names.pop() done() if delete_names.length == 0 - + true validate_presets = -> cloudinary.v2.api.upload_presets (error, response) -> expect(response.presets.slice(0,3).map((p) -> p.name)).to.eql(delete_names) - delete_names.forEach((name) -> cloudinary.v2.api.delete_upload_preset name, after_delete) + delete_names.forEach (name) -> + cloudinary.v2.api.delete_upload_preset name, after_delete + true + true after_create = -> if create_names.length > 0 name = create_names.pop() delete_names.unshift(name) cloudinary.v2.api.create_upload_preset name: name , folder: "folder", after_create + true else validate_presets() after_create() + true it "should allow getting a single upload_preset", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -457,6 +515,9 @@ describe "api", -> expect(preset.settings.tags).to.eql(["a","b","c"]) cloudinary.v2.api.delete_upload_preset name, -> done() + true + true + true it "should allow deleting upload_presets", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -466,6 +527,10 @@ describe "api", -> cloudinary.v2.api.upload_preset API_TEST_UPLOAD_PRESET4, (error, result) -> expect(error.message).to.contain "Can't find" done() + true + true + true + true it "should allow updating upload_presets", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -479,12 +544,18 @@ describe "api", -> expect(preset.settings).to.eql(folder: "folder", colors: true, disallow_public_id: true) cloudinary.v2.api.delete_upload_preset name, -> done() + true + true + true + true + true it "should support the usage API call", (done) -> @timeout helper.TIMEOUT_MEDIUM cloudinary.v2.api.usage (error, usage) -> expect(usage.last_update).not.to.eql null done() + true describe "delete_all_resources", -> itBehavesLike "accepts next_cursor", cloudinary.v2.api.delete_all_resources @@ -512,14 +583,19 @@ describe "api", -> return done(new Error error.message) if error? expect(new_resource.derived).to.be.empty() done() + true + true + true describe "update", ()-> it "should support setting manual moderation status", (done) -> - @timeout helper.TIMEOUT_MEDIUM + @timeout helper.TIMEOUT_LONG cloudinary.v2.uploader.upload IMAGE_FILE, moderation: "manual", (error, upload_result) -> cloudinary.v2.api.update upload_result.public_id, moderation_status: "approved", (error, api_result) -> expect(api_result.moderation[0].status).to.eql("approved") done() + true + true it "should support requesting ocr info", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -527,6 +603,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, ocr: "illegal", (error, api_result) -> expect(error.message).to.contain "Illegal value" done() + true it "should support requesting raw conversion", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -534,6 +611,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, raw_convert: "illegal", (error, api_result) -> expect(error.message).to.contain "Illegal value" done() + true it "should support requesting categorization", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -541,6 +619,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, categorization: "illegal", (error, api_result) -> expect(error.message).to.contain "Illegal value" done() + true it "should support requesting detection", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -548,6 +627,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, detection: "illegal", (error, api_result) -> expect(error.message).to.contain "Illegal value" done() + true it "should support requesting background_removal", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -555,6 +635,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, background_removal: "illegal", (error, api_result) -> expect(error.message).to.contain "Illegal value" done() + true it "should support requesting similarity_search", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -562,6 +643,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, similarity_search: "illegal", (error, api_result) -> expect(error.message).to.contain "Illegal value" done() + true it "should support requesting auto_tagging", (done) -> @timeout helper.TIMEOUT_MEDIUM @@ -569,6 +651,7 @@ describe "api", -> cloudinary.v2.api.update upload_result.public_id, auto_tagging: "illegal", (error, api_result) -> expect(error.message).to.contain "Must use" done() + true it "should support listing by moderation kind and value", (done) -> itBehavesLike "a list with a cursor", cloudinary.v2.api.resources_by_moderation, "manual", "approved" @@ -608,6 +691,7 @@ describe "api", -> cloudinary.v2.uploader.upload(IMAGE_FILE, moderation: "manual", tags: UPLOAD_TAGS, after_upload) cloudinary.v2.uploader.upload(IMAGE_FILE, moderation: "manual", tags: UPLOAD_TAGS, after_upload) cloudinary.v2.uploader.upload(IMAGE_FILE, moderation: "manual", tags: UPLOAD_TAGS, after_upload) + true # For this test to work, "Auto-create folders" should be enabled in the Upload Settings. # Replace `it` with `it.skip` below if you want to disable it. @@ -640,6 +724,7 @@ describe "api", -> expect(err.error.message).to.eql('Can\'t find folder with path test_folder_not_exists') done() ) + true describe '.restore', -> @timeout helper.TIMEOUT_MEDIUM @@ -658,6 +743,10 @@ describe "api", -> expect(resource["bytes"]).to.eql(0) expect(resource["placeholder"]).to.eql(true) done() + true + true + true + true it 'should restore a deleted resource', (done)-> cloudinary.v2.api.restore "api_test_restore", (error, response)-> @@ -668,6 +757,8 @@ describe "api", -> expect(resource).not.to.be(null) expect(resource["bytes"]).to.eql(3381) done() + true + true describe 'mapping', -> @@ -677,6 +768,7 @@ describe "api", -> if(deleteMapping) cloudinary.v2.api.delete_upload_mapping mapping, (error, result)-> done() + true else done() itBehavesLike "a list with a cursor", cloudinary.v2.api.upload_mappings @@ -703,6 +795,13 @@ describe "api", -> return done(new Error error.message) if error? expect(_.find(result["mappings"], _.matchesProperty('folder', mapping))).not.to.be.ok() done() + true + true + true + true + true + true + true describe "publish", -> @timeout helper.TIMEOUT_LONG @@ -718,11 +817,13 @@ describe "api", -> publishTestId = result.public_id idsToDelete.push publishTestId done() + true after (done)-> # cleanup any resource that were not published cloudinary.v2.api.delete_resources idsToDelete, type: "authenticated", (error, result)-> return done(new Error error.message) if error? done() + true it "by public id", (done)-> @timeout helper.TIMEOUT_LONG cloudinary.v2.api.publish_by_ids [publishTestId], (error, result)-> @@ -733,6 +834,7 @@ describe "api", -> expect(published[0].public_id).to.eql(publishTestId) expect(published[0].url).to.match(/\/upload\//) done() + true it "by prefix", (done)-> @timeout helper.TIMEOUT_LONG cloudinary.v2.api.publish_by_prefix publishTestId[0..-2], (error, result)-> @@ -743,6 +845,7 @@ describe "api", -> expect(published[0].public_id).to.eql(publishTestId) expect(published[0].url).to.match(/\/upload\//) done() + true it "by tag", (done)-> @timeout helper.TIMEOUT_LONG cloudinary.v2.api.publish_by_tag publishTestTag, (error, result)-> @@ -753,6 +856,7 @@ describe "api", -> expect(published[0].public_id).to.eql(publishTestId) expect(published[0].url).to.match(/\/upload\//) done() + true describe "access_mode", -> i = 0 @timeout helper.TIMEOUT_LONG @@ -765,6 +869,7 @@ describe "api", -> publicId = result.public_id expect(result.access_mode).to.be("authenticated") done() + true it "should update access mode by ids", (done)-> cloudinary.v2.api.update_resources_access_mode_by_ids "public", [publicId], (error, result)-> return done(new Error error.message) if error? @@ -774,6 +879,7 @@ describe "api", -> expect(resource.public_id).to.be(publicId) expect(resource.access_mode).to.be('public') done() + true it "should update access mode by prefix", (done)-> cloudinary.v2.api.update_resources_access_mode_by_prefix "public", publicId[0..-3], (error, result)-> return done(new Error error.message) if error? @@ -783,6 +889,7 @@ describe "api", -> expect(resource.public_id).to.be(publicId) expect(resource.access_mode).to.be('public') done() + true it "should update access mode by tag", (done)-> cloudinary.v2.api.update_resources_access_mode_by_tag "public", access_mode_tag, (error, result)-> return done(new Error error.message) if error? @@ -792,3 +899,4 @@ describe "api", -> expect(resource.public_id).to.be(publicId) expect(resource.access_mode).to.be('public') done() + true diff --git a/test/streaming_profiles_spec.coffee b/test/streaming_profiles_spec.coffee index c8e169c5..1560b4a9 100644 --- a/test/streaming_profiles_spec.coffee +++ b/test/streaming_profiles_spec.coffee @@ -40,7 +40,8 @@ describe 'Cloudinary::Api', -> cloudinary.v2.api.delete_streaming_profile(test_id_1 + 'a') cloudinary.v2.api.delete_streaming_profile(test_id_3)] .finally -> - done() + done() + true describe 'create_streaming_profile', -> it 'should create a streaming profile with representations', (done)-> @@ -49,12 +50,14 @@ describe 'Cloudinary::Api', -> expect(error).to.be undefined expect(result).not.to.be(undefined) done() + true it 'should create a streaming profile with an array of transformation', (done)-> api.create_streaming_profile test_id_1 + 'a', {representations: [{transformation: [{crop: 'scale', width: '1200', height: '1200', bit_rate: '5m'}]}]}, (error, result)-> expect(error).to.be undefined expect(result).not.to.be(undefined) done() + true describe 'list_streaming_profile', -> it 'should list streaming profile', (done)-> @@ -64,6 +67,7 @@ describe 'Cloudinary::Api', -> for profile in PREDEFINED_PROFILES expect(result['data'].some((p)-> p.name == profile)).to.be.ok() done() + true describe 'delete_streaming_profile', -> it 'should delete a streaming profile', (done)-> @@ -81,6 +85,9 @@ describe 'Cloudinary::Api', -> api.list_streaming_profiles (error, result)-> expect(result['data'].map((p) -> p['name'])).not.to.contain(test_id_2) done() + true + true + true describe 'get_streaming_profile', -> it 'should get a specific streaming profile', (done)-> @@ -90,6 +97,7 @@ describe 'Cloudinary::Api', -> expect(_.keys(result['data'])).to.contain('display_name') expect(_.keys(result['data'])).to.contain('representations') done() + true describe 'update_streaming_profile', -> it 'should create a streaming profile with representations', (done)-> @@ -109,3 +117,6 @@ describe 'Cloudinary::Api', -> # Notice transformation is always returned as an array; numeric values represented as numbers, not strings expect(result['representations'][0]).to.eql({transformation: [crop: 'scale', width: 1000, height: 1000, bit_rate: '4m']}) done() + true + true + true diff --git a/test/uploader_spec.coffee b/test/uploader_spec.coffee index 553a5cbb..480097e2 100644 --- a/test/uploader_spec.coffee +++ b/test/uploader_spec.coffee @@ -25,13 +25,14 @@ describe "uploader", -> if(!(config.api_key && config.api_secret)) expect().fail("Missing key and secret. Please set CLOUDINARY_URL.") - @timeout helper.TIMEOUT_SHORT + @timeout helper.TIMEOUT_LONG after -> config = cloudinary.config(true) if(!(config.api_key && config.api_secret)) expect().fail("Missing key and secret. Please set CLOUDINARY_URL.") cloudinary.v2.api.delete_resources_by_tag(helper.TEST_TAG) unless cloudinary.config().keep_test_products + ###* # Upload an image to be tested on. # @callback the callback receives the public_id of the uploaded image @@ -45,12 +46,14 @@ describe "uploader", -> cloudinary.config(true) it "should successfully upload file", (done) -> + @timeout helper.TIMEOUT_LONG upload_image (result) -> expect(result.width).to.eql(241) expect(result.height).to.eql(51) expected_signature = cloudinary.utils.api_sign_request({public_id: result.public_id, version: result.version}, cloudinary.config().api_secret) expect(result.signature).to.eql(expected_signature) done() + true it "should successfully upload url", (done) -> cloudinary.v2.uploader.upload "http://cloudinary.com/images/old_logo.png", tags: UPLOAD_TAGS, (error, result) -> @@ -60,6 +63,7 @@ describe "uploader", -> expected_signature = cloudinary.utils.api_sign_request({public_id: result.public_id, version: result.version}, cloudinary.config().api_secret) expect(result.signature).to.eql(expected_signature) done() + true describe "rename", ()-> @timeout helper.TIMEOUT_LONG @@ -71,6 +75,9 @@ describe "uploader", -> cloudinary.v2.api.resource public_id+"2", (e2, r2) -> expect(e2).to.be undefined done() + true + true + true it "should not rename to an existing public_id", (done)-> upload_image (result)-> @@ -80,6 +87,9 @@ describe "uploader", -> cloudinary.v2.uploader.rename first_id, second_id, (e3, r3) -> expect(e3).not.to.be undefined done() + true + true + true it "should allow to rename to an existing ID, if overwrite is true", (done)-> upload_image (result)-> @@ -91,6 +101,10 @@ describe "uploader", -> cloudinary.v2.api.resource second_id, (error, result) -> expect(result.format).to.eql "png" done() + true + true + true + true context ":invalidate", -> spy = undefined @@ -105,6 +119,7 @@ describe "uploader", -> cloudinary.v2.uploader.rename "first_id", "second_id", invalidate: true, (error, result) -> expect(spy.calledWith(sinon.match((arg)-> arg.toString().match(/name="invalidate"/)))).to.be.ok() done() + true describe "destroy", ()-> @timeout helper.TIMEOUT_MEDIUM @@ -117,6 +132,9 @@ describe "uploader", -> cloudinary.v2.api.resource public_id, (error, result)-> expect(error).to.be.ok() done() + true + true + true it "should successfully call explicit api", (done) -> current = this @@ -138,23 +156,27 @@ describe "uploader", -> done() else done(new Error error.message) + true it "should support eager in upload", (done) -> @timeout helper.TIMEOUT_SHORT cloudinary.v2.uploader.upload IMAGE_FILE, eager: [crop: "scale", width: "2.0"], tags: UPLOAD_TAGS, (error, result) -> return done(new Error error.message) if error? done() + true describe "custom headers", ()-> it "should support custom headers in object format e.g. {Link: \"1\"}", (done) -> cloudinary.v2.uploader.upload IMAGE_FILE, headers: {Link: "1"}, tags: UPLOAD_TAGS, (error, result) -> return done(new Error error.message) if error? done() + true it "should support custom headers as array of strings e.g. [\"Link: 1\"]", (done) -> cloudinary.v2.uploader.upload IMAGE_FILE, headers: ["Link: 1"], tags: UPLOAD_TAGS, (error, result) -> return done(new Error error.message) if error? done() + true it "should successfully generate text image", (done) -> cloudinary.v2.uploader.text "hello world", tags: UPLOAD_TAGS, (error, result) -> @@ -162,6 +184,7 @@ describe "uploader", -> expect(result.width).to.within(50,70) expect(result.height).to.within(5,15) done() + true it "should successfully upload stream", (done) -> stream = cloudinary.v2.uploader.upload_stream tags: UPLOAD_TAGS, (error, result) -> @@ -171,6 +194,7 @@ describe "uploader", -> expected_signature = cloudinary.utils.api_sign_request({public_id: result.public_id, version: result.version}, cloudinary.config().api_secret) expect(result.signature).to.eql(expected_signature) done() + true file_reader = fs.createReadStream(IMAGE_FILE, {encoding: 'binary'}) file_reader.on 'data', (chunk)-> stream.write(chunk,'binary') file_reader.on 'end', -> stream.end() @@ -193,6 +217,12 @@ describe "uploader", -> expect(res["public_ids"]).to.not.contain('noSuchId') cloudinary.v2.api.delete_resources [first_id, second_id], (err, res)-> done() + true + true + true + true + true + true it "should keep existing tags when adding a new tag", (done)-> upload_image (result1)-> @@ -202,6 +232,10 @@ describe "uploader", -> cloudinary.v2.api.resource public_id, (e1, r1) -> expect(r1.tags).to.contain("tag1").and.contain( "tag2") done() + true + true + true + true it "should replace existing tag", (done)-> cloudinary.v2.uploader.upload IMAGE_FILE, tags: ["tag1", "tag2", TEST_TAG], (error, result)-> @@ -213,6 +247,9 @@ describe "uploader", -> return done(new Error error.message) if error? expect(result.tags).to.eql(["tag3Å"]) done() + true + true + true describe "context", ()-> second_id = first_id = '' @@ -228,6 +265,7 @@ describe "uploader", -> done() .fail (error)-> done(new Error(error.message)) + true it "should add context to existing resources", (done) -> cloudinary.v2.uploader.add_context 'alt=testAlt|custom=testCustom', [first_id, second_id], (et1, rt1) -> return done(new Error et1.message) if et1? @@ -250,6 +288,11 @@ describe "uploader", -> return done(new Error error.message) if error expect(r1.context).to.be undefined done() + true + true + true + true + true it "should support timeouts", (done) -> # testing a 1ms timeout, nobody is that fast. @@ -257,6 +300,7 @@ describe "uploader", -> expect(error.http_code).to.eql(499) expect(error.message).to.eql("Request Timeout") done() + true it "should upload a file and base public id on the filename if use_filename is set to true", (done) -> @@ -265,6 +309,7 @@ describe "uploader", -> return done(new Error error.message) if error? expect(result.public_id).to.match /logo_[a-zA-Z0-9]{6}/ done() + true it "should upload a file and set the filename as the public_id if use_filename is set to true and unique_filename is set to false", (done) -> @@ -272,6 +317,7 @@ describe "uploader", -> return done(new Error error.message) if error? expect(result.public_id).to.eql "logo" done() + true describe "allowed_formats", -> it "should allow whitelisted formats", (done) -> @@ -279,20 +325,24 @@ describe "uploader", -> return done(new Error error.message) if error? expect(result.format).to.eql("png") done() + true it "should prevent non whitelisted formats from being uploaded", (done) -> cloudinary.v2.uploader.upload IMAGE_FILE, allowed_formats: ["jpg"], tags: UPLOAD_TAGS, (error, result) -> expect(error.http_code).to.eql(400) done() + true it "should allow non whitelisted formats if type is specified and convert to that type", (done) -> cloudinary.v2.uploader.upload IMAGE_FILE, allowed_formats: ["jpg"], format: "jpg", tags: UPLOAD_TAGS, (error, result) -> return done(new Error error.message) if error? expect(result.format).to.eql("jpg") done() + true it "should allow sending face coordinates", (done) -> + @timeout helper.TIMEOUT_LONG coordinates = [[120, 30, 109, 150], [121, 31, 110, 151]] out_coordinates = [[120, 30, 109, 51], [121, 31, 110, 51]] # coordinates are limited to the image dimensions different_coordinates = [[122, 32, 111, 152]] @@ -307,6 +357,9 @@ describe "uploader", -> expect(info.faces).to.eql(different_coordinates) expect(info.coordinates).to.eql(faces: different_coordinates, custom: [custom_coordinates]) done() + true + true + true it "should allow sending context", (done) -> @timeout helper.TIMEOUT_LONG @@ -318,6 +371,8 @@ describe "uploader", -> expect(info.context.custom.caption).to.eql("some caption") expect(info.context.custom.alt).to.eql("alternative") done() + true + true @@ -326,6 +381,7 @@ describe "uploader", -> expect(result.moderation[0].status).to.eql("pending") expect(result.moderation[0].kind).to.eql("manual") done() + true it "should support requesting raw conversion", (done) -> @@ -333,6 +389,7 @@ describe "uploader", -> expect(error?).to.be true expect(error.message).to.contain "is not a valid" done() + true it "should support requesting categorization", (done) -> @@ -340,6 +397,7 @@ describe "uploader", -> expect(error?).to.be true expect(error.message).to.contain "is invalid" done() + true it "should support requesting detection", (done) -> @@ -347,6 +405,7 @@ describe "uploader", -> expect(error).not.to.be undefined expect(error.message).to.contain "is not a valid" done() + true it "should support requesting background_removal", (done) -> @@ -354,6 +413,7 @@ describe "uploader", -> expect(error?).to.be true expect(error.message).to.contain "is invalid" done() + true it "should support requesting auto_tagging", (done) -> @@ -361,6 +421,7 @@ describe "uploader", -> expect(error?).to.be true expect(error.message).to.contain "Must use" done() + true describe "upload_chunked", ()-> @@ -372,12 +433,14 @@ describe "uploader", -> expect(result.bytes).to.eql(stat.size) expect(result.etag).to.eql("4c13724e950abcb13ec480e10f8541f5") done() + true it "should return error if value is less than 5MB", (done)-> fs.stat LARGE_RAW_FILE, (err, stat) -> cloudinary.v2.uploader.upload_large LARGE_RAW_FILE, {chunk_size: 40000, tags: UPLOAD_TAGS}, (error, result) -> expect(error.message).to.eql("All parts except last must be larger than 5mb") done() + true it "should support uploading a small raw file", (done) -> fs.stat RAW_FILE, (err, stat) -> @@ -386,6 +449,7 @@ describe "uploader", -> expect(result.bytes).to.eql(stat.size) expect(result.etag).to.eql("ffc265d8d1296247972b4d478048e448") done() + true it "should support uploading a small image file", (done) -> fs.stat IMAGE_FILE, (err, stat) -> @@ -394,6 +458,7 @@ describe "uploader", -> expect(result.bytes).to.eql(stat.size) expect(result.etag).to.eql("7dc60722d4653261648038b579fdb89e") done() + true it "should support uploading large video files", (done) -> @timeout helper.TIMEOUT_LONG * 10 @@ -405,6 +470,8 @@ describe "uploader", -> expect(result.etag).to.eql("ff6c391d26be0837ee5229885b5bd571") cloudinary.v2.uploader.destroy result.public_id, ()-> done() + true + true it "should support unsigned uploading using presets", (done) -> @timeout helper.TIMEOUT_LONG @@ -414,6 +481,9 @@ describe "uploader", -> cloudinary.v2.api.delete_upload_preset preset.name, -> expect(result.public_id).to.match /^upload_folder\/[a-z0-9]+$/ done() + true + true + true it "should reject promise if error code is returned from the server", (done) -> cloudinary.v2.uploader.upload(EMPTY_IMAGE, tags: UPLOAD_TAGS) @@ -423,6 +493,7 @@ describe "uploader", -> expect(error.message).to.contain "empty" .finally -> done() + true it "should successfully upload with pipes", (done) -> @timeout helper.TIMEOUT_LONG @@ -433,6 +504,7 @@ describe "uploader", -> expected_signature = cloudinary.utils.api_sign_request({public_id: result.public_id, version: result.version}, cloudinary.config().api_secret) expect(result.signature).to.eql(expected_signature) done() + true file_reader = fs.createReadStream(IMAGE_FILE) file_reader.pipe(upload) @@ -443,6 +515,7 @@ describe "uploader", -> expect(error).to.be.ok() expect(error.message).to.match(/socket hang up|ECONNRESET/) done() + true file_reader = fs.createReadStream(IMAGE_FILE) file_reader.pipe(upload) @@ -453,6 +526,7 @@ describe "uploader", -> done() ).to.throwError() done() + true it "should successfully override https agent", (done) -> upload = cloudinary.v2.uploader.upload_stream agent:new https.Agent, tags: UPLOAD_TAGS, (error, result) -> @@ -462,6 +536,7 @@ describe "uploader", -> expected_signature = cloudinary.utils.api_sign_request({public_id: result.public_id, version: result.version}, cloudinary.config().api_secret) expect(result.signature).to.eql(expected_signature) done() + true file_reader = fs.createReadStream(IMAGE_FILE) file_reader.pipe(upload) @@ -472,6 +547,7 @@ describe "uploader", -> return done(new Error error.message) if error? expect(result).to.have.key('responsive_breakpoints') done() + true describe "explicit", -> spy = undefined diff --git a/test/utils_spec.coffee b/test/utils_spec.coffee index aabc8a0f..ecd3a437 100644 --- a/test/utils_spec.coffee +++ b/test/utils_spec.coffee @@ -272,6 +272,8 @@ describe "utils", -> authenticated_image = result authenticated_path = "#{root_path}/image/authenticated" done() + true + true beforeEach -> options = _.merge({ version: authenticated_image['version'], sign_url: true, type: "authenticated" }, specific_options)