@@ -9,6 +9,7 @@ Q = require('q')
99path = require (' path' );
1010isFunction = require (' lodash/isFunction' )
1111at = require (' lodash/at' )
12+ uniq = require (' lodash/uniq' )
1213ClientRequest = require (' _http_client' ).ClientRequest
1314require (' jsdom-global' )()
1415
@@ -33,7 +34,10 @@ describe "uploader", ->
3334 config = cloudinary .config (true )
3435 if (! (config .api_key && config .api_secret ))
3536 expect ().fail (" Missing key and secret. Please set CLOUDINARY_URL." )
36- cloudinary .v2 .api .delete_resources_by_tag (helper .TEST_TAG ) unless cloudinary .config ().keep_test_products
37+ Q .allSettled [
38+ cloudinary .v2 .api .delete_resources_by_tag (helper .TEST_TAG ) unless cloudinary .config ().keep_test_products
39+ cloudinary .v2 .api .delete_resources_by_tag (helper .TEST_TAG , resource_type : " video" ) unless cloudinary .config ().keep_test_products
40+ ]
3741
3842 beforeEach ->
3943 cloudinary .config (true )
@@ -387,18 +391,34 @@ describe "uploader", ->
387391 done ()
388392 true
389393
390- it " should support uploading large video files" , (done ) ->
394+ it " should support uploading large video files" , () ->
391395 @ timeout helper .TIMEOUT_LONG * 10
392- fs .stat LARGE_VIDEO, (err , stat ) ->
393- return done (new Error err .message ) if err?
394- cloudinary .v2 .uploader .upload_chunked LARGE_VIDEO, {resource_type : ' video' , timeout : helper .TIMEOUT_LONG * 10 , tags : UPLOAD_TAGS}, (error , result ) ->
395- return done (new Error error .message ) if error?
396- expect (result .bytes ).to .eql (stat .size )
397- expect (result .etag ).to .eql (" ff6c391d26be0837ee5229885b5bd571" )
398- cloudinary .v2 .uploader .destroy result .public_id , ()->
399- done ()
400- true
401- true
396+ writeSpy = sinon .spy (ClientRequest .prototype , ' write' )
397+ stat = fs .statSync ( LARGE_VIDEO)
398+ expect (stat).to .be .ok ()
399+ Q .denodeify (cloudinary .v2 .uploader .upload_chunked )( LARGE_VIDEO, {chunk_size : 6000000 , resource_type : ' video' , timeout : helper .TIMEOUT_LONG * 10 , tags : UPLOAD_TAGS})
400+ .then (result)->
401+ expect (result .bytes ).to .eql (stat .size )
402+ expect (result .etag ).to .eql (" ff6c391d26be0837ee5229885b5bd571" )
403+ timestamps = writeSpy .args .map ((a )-> a[0 ].toString ())
404+ .filter ((p ) -> p .match (/ timestamp/ ))
405+ .map ((p ) -> p .match (/ "timestamp"\s + (\d + )/ )[1 ])
406+ expect (timestamps .length ).to .be .greaterThan (1 )
407+ expect (uniq (timestamps)).to .eql (timestamps)
408+ .finally ->
409+ writeSpy .restore ()
410+
411+ it " should update timestamp for each chuck" , ()->
412+ writeSpy = sinon .spy (ClientRequest .prototype , ' write' )
413+ Q .denodeify (cloudinary .v2 .uploader .upload_chunked )( LARGE_VIDEO, {chunk_size : 6000000 , resource_type : ' video' , timeout : helper .TIMEOUT_LONG * 10 , tags : UPLOAD_TAGS})
414+ .then ->
415+ timestamps = writeSpy .args .map ((a )-> a[0 ].toString ())
416+ .filter ((p ) -> p .match (/ timestamp/ ))
417+ .map ((p ) -> p .match (/ "timestamp"\s + (\d + )/ )[1 ])
418+ expect (timestamps .length ).to .be .greaterThan (1 )
419+ expect (uniq (timestamps)).to .eql (timestamps)
420+ .finally ->
421+ writeSpy .restore ()
402422
403423 it " should support uploading based on a url" , (done ) ->
404424 @ timeout helper .TIMEOUT_MEDIUM
0 commit comments