Skip to content

Commit 934ae14

Browse files
author
Amir Tocker
committed
Mock delete_all_resources test
1 parent b12db51 commit 934ae14

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

test/api_spec.coffee

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -593,32 +593,30 @@ describe "api", ->
593593
describe "delete_all_resources", ->
594594
itBehavesLike "accepts next_cursor", cloudinary.v2.api.delete_all_resources
595595
describe "keep_original: yes", ->
596-
it "should allow deleting all derived resources", (done) ->
597-
@timeout helper.TIMEOUT_LONG
598-
cloudinary.v2.uploader.upload IMAGE_FILE, public_id: "api_test5", eager: {transformation: {width: 101, crop: "scale"}}, tags: UPLOAD_TAGS, (error, upload_result) ->
599-
cloudinary.v2.api.resource "api_test5", (error, resource) ->
600-
return done(new Error error.message) if error?
601-
expect(resource).to.be.an(Object)
602-
expect(resource.derived).not.to.be.empty()
603-
# Prepare to loop until no more resources to delete
604-
delete_all = (next, callback)->
605-
options = {keep_original: yes}
606-
options.next_cursor = next if next?
607-
cloudinary.v2.api.delete_all_resources options, (error, delete_result) ->
608-
return done(new Error error.message) if error?
609-
if delete_result.next_cursor?
610-
delete_all(delete_result.next_cursor, callback)
611-
else
612-
callback()
613-
# execute loop
614-
delete_all undefined, ()->
615-
cloudinary.v2.api.resource "api_test5", (error, new_resource) ->
616-
return done(new Error error.message) if error?
617-
expect(new_resource.derived).to.be.empty()
618-
done()
619-
true
620-
true
621-
true
596+
it "should allow deleting all derived resources", () ->
597+
helper.mockPromise (xhr, write, request)->
598+
options = {keep_original: yes}
599+
cloudinary.v2.api.delete_all_resources options
600+
sinon.assert.calledWith(request, sinon.match((arg)->
601+
new RegExp("/resources/image/upload$").test(arg.pathname)
602+
,
603+
"/resources/image/upload"
604+
))
605+
sinon.assert.calledWith(request, sinon.match((arg)->
606+
"DELETE" == arg.method
607+
,
608+
"DELETE"
609+
))
610+
sinon.assert.calledWith(write, sinon.match(
611+
helper.apiParamMatcher('keep_original', 'true')
612+
,
613+
"keep_original=true"
614+
))
615+
sinon.assert.calledWith(write, sinon.match(
616+
helper.apiParamMatcher('all', 'true')
617+
,
618+
"all=true"
619+
))
622620

623621
describe "update", ()->
624622
describe "notification url", ()->

0 commit comments

Comments
 (0)