@@ -898,5 +898,72 @@ describe('Backbone Webdav extension', function() {
898898 expect ( model . isNew ( ) ) . toEqual ( false ) ;
899899 } ) ;
900900 } ) ;
901+
902+ describe ( 'custom method' , function ( ) {
903+ var TestModel ;
904+
905+ beforeEach ( function ( ) {
906+ TestModel = OC . Backbone . Model . extend ( {
907+ url : 'http://example.com/owncloud/remote.php/test/1' ,
908+ sync : OC . Backbone . davSync ,
909+ customCall : function ( data , options ) {
910+ options = _ . extend ( { } , options ) ;
911+ options . data = data ;
912+ return this . sync ( 'REPORT' , this , options ) ;
913+ }
914+ } ) ;
915+ } ) ;
916+
917+ it ( 'serializes JSON if a JS object is passed as data' , function ( ) {
918+ var model = new TestModel ( ) ;
919+ model . customCall ( { someData : '123' } ) ;
920+
921+ expect ( davClientRequestStub . calledOnce ) . toEqual ( true ) ;
922+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 0 ] )
923+ . toEqual ( 'REPORT' ) ;
924+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 1 ] )
925+ . toEqual ( 'http://example.com/owncloud/remote.php/test/1' ) ;
926+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 2 ] [ 'Content-Type' ] )
927+ . toEqual ( 'application/json' ) ;
928+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 2 ] [ 'X-Requested-With' ] )
929+ . toEqual ( 'XMLHttpRequest' ) ;
930+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 3 ] )
931+ . toEqual ( JSON . stringify ( { someData : '123' } ) ) ;
932+ } ) ;
933+ it ( 'does not serializes JSON if a string is passed as data' , function ( ) {
934+ var model = new TestModel ( ) ;
935+ model . customCall ( 'whatever' ) ;
936+
937+ expect ( davClientRequestStub . calledOnce ) . toEqual ( true ) ;
938+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 0 ] )
939+ . toEqual ( 'REPORT' ) ;
940+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 1 ] )
941+ . toEqual ( 'http://example.com/owncloud/remote.php/test/1' ) ;
942+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 2 ] [ 'Content-Type' ] )
943+ . toEqual ( 'text/plain' ) ;
944+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 2 ] [ 'X-Requested-With' ] )
945+ . toEqual ( 'XMLHttpRequest' ) ;
946+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 3 ] )
947+ . toEqual ( 'whatever' ) ;
948+ } ) ;
949+ it ( 'sends XML mime type when passed data string is XML' , function ( ) {
950+ var model = new TestModel ( ) ;
951+ var body = '<?xml version="1.0" encoding="utf-8" ?>' ;
952+ body += '<root></root>' ;
953+ model . customCall ( body ) ;
954+
955+ expect ( davClientRequestStub . calledOnce ) . toEqual ( true ) ;
956+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 0 ] )
957+ . toEqual ( 'REPORT' ) ;
958+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 1 ] )
959+ . toEqual ( 'http://example.com/owncloud/remote.php/test/1' ) ;
960+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 2 ] [ 'Content-Type' ] )
961+ . toEqual ( 'application/xml' ) ;
962+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 2 ] [ 'X-Requested-With' ] )
963+ . toEqual ( 'XMLHttpRequest' ) ;
964+ expect ( davClientRequestStub . getCall ( 0 ) . args [ 3 ] )
965+ . toEqual ( body ) ;
966+ } ) ;
967+ } ) ;
901968} ) ;
902969
0 commit comments