@@ -639,6 +639,7 @@ describe "api", ->
639639 @ timeout helper .TIMEOUT_LONG
640640 cloudinary .v2 .uploader .upload IMAGE_FILE, moderation : " manual" , (error , upload_result ) ->
641641 cloudinary .v2 .api .update upload_result .public_id , moderation_status : " approved" , (error , api_result ) ->
642+ return done (new Error error .message ) if error?
642643 expect (api_result .moderation [0 ].status ).to .eql (" approved" )
643644 done ()
644645 true
@@ -706,45 +707,27 @@ describe "api", ->
706707 ))
707708 )
708709
709- it " should support listing by moderation kind and value" , (done ) ->
710+ it " should support listing by moderation kind and value" , () ->
710711 itBehavesLike " a list with a cursor" , cloudinary .v2 .api .resources_by_moderation , " manual" , " approved"
711- @ timeout helper .TIMEOUT_MEDIUM
712- ids = []
713- api_results = []
714- lists = {}
715- after_listing = (list ) ->
716- (error , list_result ) ->
717- lists[list] = list_result .resources .map ((r ) -> r .public_id )
718- if keys (lists).length == 3
719- expect (lists .approved ).to .contain (ids[0 ])
720- expect (lists .approved ).not .to .contain (ids[1 ])
721- expect (lists .approved ).not .to .contain (ids[2 ])
722- expect (lists .rejected ).to .contain (ids[1 ])
723- expect (lists .rejected ).not .to .contain (ids[0 ])
724- expect (lists .rejected ).not .to .contain (ids[2 ])
725- expect (lists .pending ).to .contain (ids[2 ])
726- expect (lists .pending ).not .to .contain (ids[0 ])
727- expect (lists .pending ).not .to .contain (ids[1 ])
728- done ()
729-
730- after_update = (error , api_result ) ->
731- api_results .push (api_result)
732- if api_results .length == 2
733- cloudinary .v2 .api .resources_by_moderation (" manual" , " approved" , max_results : 1000 , moderations : true , after_listing (" approved" ))
734- cloudinary .v2 .api .resources_by_moderation (" manual" , " rejected" , max_results : 1000 , moderations : true , after_listing (" rejected" ))
735- cloudinary .v2 .api .resources_by_moderation (" manual" , " pending" , max_results : 1000 , moderations : true , after_listing (" pending" ))
736-
737- after_upload = (error , upload_result ) ->
738- return done (new Error error .message ) if error?
739- ids .push (upload_result .public_id )
740- if ids .length == 3
741- cloudinary .v2 .api .update ids[0 ], moderation_status : " approved" , after_update
742- cloudinary .v2 .api .update ids[1 ], moderation_status : " rejected" , after_update
743-
744- cloudinary .v2 .uploader .upload (IMAGE_FILE, moderation : " manual" , tags : UPLOAD_TAGS, after_upload)
745- cloudinary .v2 .uploader .upload (IMAGE_FILE, moderation : " manual" , tags : UPLOAD_TAGS, after_upload)
746- cloudinary .v2 .uploader .upload (IMAGE_FILE, moderation : " manual" , tags : UPLOAD_TAGS, after_upload)
747- true
712+
713+
714+ helper .mockPromise (xhr, write, request)->
715+ [
716+ " approved"
717+ " pending"
718+ " rejected"
719+ ].forEach (stat)->
720+ status = stat
721+ status2 = status
722+ request .resetHistory ()
723+
724+ cloudinary .v2 .api .resources_by_moderation (" manual" , status2, moderations : true )
725+ sinon .assert .calledWith request, sinon .match ( (arg )->
726+ new RegExp (" /resources/image/moderations/manual/#{ status2} $" ).test (arg ? .pathname )
727+ , " /resources/image/moderations/manual/#{ status} " )
728+ sinon .assert .calledWith request, sinon .match ( (arg )->
729+ / ^ moderations=true$ / .test (arg ? .query )
730+ , " moderations=true" )
748731
749732 # For this test to work, "Auto-create folders" should be enabled in the Upload Settings.
750733 # Replace `it` with `it.skip` below if you want to disable it.
0 commit comments