@@ -42,13 +42,25 @@ describe("WebApiClient", function() {
4242 // Respond to update Request for account
4343 var updateAccountUrl = RegExp . escape ( fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000001)" ) ;
4444 xhr . respondWith ( "PATCH" , new RegExp ( updateAccountUrl , "g" ) ,
45- [ 204 , { "Content-Type" : "application/json" } , "{}" ]
45+ [ 204 , { "Content-Type" : "application/json" } , "{operation: 'Update' }" ]
4646 ) ;
4747
4848 // Respond to Delete Request for account
4949 var deleteAccountUrl = RegExp . escape ( fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000001)" ) ;
5050 xhr . respondWith ( "DELETE" , new RegExp ( deleteAccountUrl , "g" ) ,
51- [ 204 , { "Content-Type" : "application/json" } , "{}" ]
51+ [ 204 , { "Content-Type" : "application/json" } , "{operation: 'Delete'}" ]
52+ ) ;
53+
54+ // Respond to Associate Request for account
55+ var associateAccountUrl = RegExp . escape ( fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000002)/opportunity_customer_accounts/$ref" ) ;
56+ xhr . respondWith ( "POST" , new RegExp ( associateAccountUrl , "g" ) ,
57+ [ 204 , { "Content-Type" : "application/json" } , "{operation: 'Associate'}" ]
58+ ) ;
59+
60+ // Respond to Delete Request for account
61+ var disassociateAccountUrl = RegExp . escape ( fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000002)/opportunity_customer_accounts(00000000-0000-0000-0000-000000000001)/$ref" ) ;
62+ xhr . respondWith ( "DELETE" , new RegExp ( disassociateAccountUrl , "g" ) ,
63+ [ 204 , { "Content-Type" : "application/json" } , "{operation: 'Disassociate'}" ]
5264 ) ;
5365 } ) ;
5466
@@ -223,6 +235,156 @@ describe("WebApiClient", function() {
223235 } ) ;
224236 } ) ;
225237
238+ describe ( "Associate" , function ( ) {
239+ it ( "should fail if no target passed" , function ( ) {
240+ expect ( function ( ) {
241+ WebApiClient . Associate (
242+ {
243+ relationShip : "opportunity_customer_accounts" ,
244+ source :
245+ {
246+ entityName : "opportunity" ,
247+ entityId : "00000000-0000-0000-0000-000000000001"
248+ }
249+ } ) ;
250+ } ) . toThrow ( ) ;
251+ } ) ;
252+
253+ it ( "should fail if no source passed" , function ( ) {
254+ expect ( function ( ) {
255+ WebApiClient . Associate (
256+ {
257+ relationShip : "opportunity_customer_accounts" ,
258+ target :
259+ {
260+ entityName : "account" ,
261+ entityId : "00000000-0000-0000-0000-000000000002"
262+ }
263+ } ) ;
264+ } ) . toThrow ( ) ;
265+ } ) ;
266+
267+ it ( "should fail if no relationShip passed" , function ( ) {
268+ expect ( function ( ) {
269+ WebApiClient . Associate (
270+ {
271+ source :
272+ {
273+ entityName : "opportunity" ,
274+ entityId : "00000000-0000-0000-0000-000000000001"
275+ } ,
276+ target :
277+ {
278+ entityName : "account" ,
279+ entityId : "00000000-0000-0000-0000-000000000002"
280+ }
281+ } ) ;
282+ } ) . toThrow ( ) ;
283+ } ) ;
284+
285+ it ( "should associate record and return" , function ( done ) {
286+ WebApiClient . Associate (
287+ {
288+ relationShip : "opportunity_customer_accounts" ,
289+ source :
290+ {
291+ entityName : "opportunity" ,
292+ entityId : "00000000-0000-0000-0000-000000000001"
293+ } ,
294+ target :
295+ {
296+ entityName : "account" ,
297+ entityId : "00000000-0000-0000-0000-000000000002"
298+ }
299+ } )
300+ . then ( function ( response ) {
301+ expect ( response ) . toBeDefined ( ) ;
302+ } )
303+ . catch ( function ( error ) {
304+ expect ( error ) . toBeUndefined ( ) ;
305+ } )
306+ // Wait for promise
307+ . finally ( done ) ;
308+
309+ xhr . respond ( ) ;
310+ } ) ;
311+ } ) ;
312+
313+ describe ( "Disassociate" , function ( ) {
314+ it ( "should fail if no target passed" , function ( ) {
315+ expect ( function ( ) {
316+ WebApiClient . Disassociate (
317+ {
318+ relationShip : "opportunity_customer_accounts" ,
319+ source :
320+ {
321+ entityName : "opportunity" ,
322+ entityId : "00000000-0000-0000-0000-000000000001"
323+ }
324+ } ) ;
325+ } ) . toThrow ( ) ;
326+ } ) ;
327+
328+ it ( "should fail if no source passed" , function ( ) {
329+ expect ( function ( ) {
330+ WebApiClient . Disassociate (
331+ {
332+ relationShip : "opportunity_customer_accounts" ,
333+ target :
334+ {
335+ entityName : "account" ,
336+ entityId : "00000000-0000-0000-0000-000000000002"
337+ }
338+ } ) ;
339+ } ) . toThrow ( ) ;
340+ } ) ;
341+
342+ it ( "should fail if no relationShip passed" , function ( ) {
343+ expect ( function ( ) {
344+ WebApiClient . Disassociate (
345+ {
346+ source :
347+ {
348+ entityName : "opportunity" ,
349+ entityId : "00000000-0000-0000-0000-000000000001"
350+ } ,
351+ target :
352+ {
353+ entityName : "account" ,
354+ entityId : "00000000-0000-0000-0000-000000000002"
355+ }
356+ } ) ;
357+ } ) . toThrow ( ) ;
358+ } ) ;
359+
360+ it ( "should disassociate record and return" , function ( done ) {
361+ WebApiClient . Disassociate (
362+ {
363+ relationShip : "opportunity_customer_accounts" ,
364+ source :
365+ {
366+ entityName : "opportunity" ,
367+ entityId : "00000000-0000-0000-0000-000000000001"
368+ } ,
369+ target :
370+ {
371+ entityName : "account" ,
372+ entityId : "00000000-0000-0000-0000-000000000002"
373+ }
374+ } )
375+ . then ( function ( response ) {
376+ expect ( response ) . toBeDefined ( ) ;
377+ } )
378+ . catch ( function ( error ) {
379+ expect ( error ) . toBeUndefined ( ) ;
380+ } )
381+ // Wait for promise
382+ . finally ( done ) ;
383+
384+ xhr . respond ( ) ;
385+ } ) ;
386+ } ) ;
387+
226388 describe ( "Headers" , function ( ) {
227389 it ( "should set default headers" , function ( ) {
228390 expect ( WebApiClient . GetDefaultHeaders ( ) ) . toBeDefined ( ) ;
0 commit comments