@@ -3560,7 +3560,7 @@ describe("promises -", function () {
35603560 "If-Match" : "*"
35613561 }
35623562 } )
3563- . put ( mocks . responses . entityDefinitionsIdUrl + '/Attributes(' + mocks . data . testEntityId2 + ')' , mocks . data . testAttributeDefinition )
3563+ . put ( mocks . responses . entityDefinitionsIdUrl + '/Attributes(' + mocks . data . testEntityId2 + ')' , mocks . data . testAttributeDefinition )
35643564 . reply ( response . status , response . responseText , response . responseHeaders ) ;
35653565 } ) ;
35663566
@@ -4868,6 +4868,65 @@ describe("promises -", function () {
48684868 } ) ;
48694869 } ) ;
48704870
4871+ describe ( "update / delete - returns an error" , function ( ) {
4872+ var scope ;
4873+ var rBody = mocks . data . batchUpdateDelete ;
4874+ var rBodys = rBody . split ( '\n' ) ;
4875+ var checkBody = '' ;
4876+ for ( var i = 0 ; i < rBodys . length ; i ++ ) {
4877+ checkBody += rBodys [ i ] ;
4878+ }
4879+ before ( function ( ) {
4880+ var response = mocks . responses . batchError ;
4881+ scope = nock ( mocks . webApiUrl + '$batch' )
4882+ . filteringRequestBody ( function ( body ) {
4883+ body = body . replace ( / d w a _ b a t c h _ [ \d \w ] { 8 } - [ \d \w ] { 4 } - [ \d \w ] { 4 } - [ \d \w ] { 4 } - [ \d \w ] { 12 } / g, 'dwa_batch_XXX' ) ;
4884+ body = body . replace ( / c h a n g e s e t _ [ \d \w ] { 8 } - [ \d \w ] { 4 } - [ \d \w ] { 4 } - [ \d \w ] { 4 } - [ \d \w ] { 12 } / g, 'changeset_XXX' ) ;
4885+ var bodys = body . split ( '\n' ) ;
4886+
4887+ var resultBody = '' ;
4888+ for ( var i = 0 ; i < bodys . length ; i ++ ) {
4889+ resultBody += bodys [ i ] ;
4890+ }
4891+ return resultBody ;
4892+ } )
4893+ . post ( "" , checkBody )
4894+ . reply ( response . status , response . responseText , response . responseHeaders ) ;
4895+ } ) ;
4896+
4897+ after ( function ( ) {
4898+ nock . cleanAll ( ) ;
4899+ } ) ;
4900+
4901+ it ( "returns a correct response" , function ( done ) {
4902+ dynamicsWebApiTest . startBatch ( ) ;
4903+
4904+ dynamicsWebApiTest . update ( mocks . data . testEntityId2 , 'records' , { firstname : "Test" , lastname : "Batch!" } ) ;
4905+ dynamicsWebApiTest . deleteRecord ( mocks . data . testEntityId2 , 'records' , 'firstname' ) ;
4906+
4907+ dynamicsWebApiTest . executeBatch ( )
4908+ . then ( function ( object ) {
4909+ done ( object ) ;
4910+ } ) . catch ( function ( object ) {
4911+ expect ( object . length ) . to . be . eq ( 1 ) ;
4912+
4913+ expect ( object [ 0 ] . error ) . to . deep . equal ( {
4914+ "code" : "0x0" , "message" : "error" , "innererror" : { "message" : "error" , "type" : "Microsoft.Crm.CrmHttpException" , "stacktrace" : "stack" }
4915+ } ) ;
4916+
4917+ expect ( object [ 0 ] . status ) . to . equal ( 400 ) ;
4918+ expect ( object [ 0 ] . statusMessage ) . to . equal ( "Bad Request" ) ;
4919+ expect ( object [ 0 ] . statusText ) . to . equal ( "Bad Request" ) ;
4920+
4921+ done ( ) ;
4922+ } ) ;
4923+ } ) ;
4924+
4925+ it ( "all requests have been made" , function ( ) {
4926+ expect ( scope . isDone ( ) ) . to . be . true ;
4927+ } ) ;
4928+ } ) ;
4929+
48714930 describe ( "create / create with Content-ID" , function ( ) {
48724931 var scope ;
48734932 var rBody = mocks . data . batchCreateContentID ;
@@ -4956,7 +5015,7 @@ describe("promises -", function () {
49565015 dynamicsWebApiTest . startBatch ( ) ;
49575016
49585017 dynamicsWebApiTest . createRequest ( { collection : 'records' , entity : { firstname : "Test" , lastname : "Batch!" } , contentId : '1' } ) ;
4959- dynamicsWebApiTest . createRequest ( { collection :
'tests' , entity :
{ firstname :
"Test1" , lastname :
"Batch!" , "[email protected] " :
"$1" } } ) ; 5018+ dynamicsWebApiTest . createRequest ( { collection :
'tests' , entity :
{ firstname :
"Test1" , lastname :
"Batch!" , "[email protected] " :
"$1" } } ) ; 49605019
49615020 dynamicsWebApiTest . executeBatch ( )
49625021 . then ( function ( object ) {
@@ -5481,7 +5540,7 @@ describe("promises -", function () {
54815540 }
54825541 } )
54835542 . get ( mocks . responses . collectionUrl )
5484- . query ( { '$select' : 'name' } )
5543+ . query ( { '$select' : 'name' } )
54855544 . reply ( response . status , response . responseText , response . responseHeaders ) ;
54865545 } ) ;
54875546
0 commit comments