11describe ( "WebApiClient" , function ( ) {
22 var fakeUrl = "http://unit-test.local" ;
33 var account ;
4+ var contact ;
45 var xhr ;
56
67 Xrm = { } ;
@@ -18,6 +19,10 @@ describe("WebApiClient", function() {
1819 account = {
1920 Name : "Adventure Works"
2021 } ;
22+
23+ contact = {
24+ FirstName : "Joe"
25+ } ;
2126
2227 xhr = sinon . fakeServer . create ( ) ;
2328
@@ -39,6 +44,12 @@ describe("WebApiClient", function() {
3944 [ 200 , { "Content-Type" : "application/json" } , JSON . stringify ( [ account ] ) ]
4045 ) ;
4146
47+ // Respond to Retrieve Request for contact with alternate key
48+ var retrieveByAlternateKeyUrl = RegExp . escape ( fakeUrl + "/api/data/v8.0/contacts(firstname='Joe',emailaddress1='[email protected] ')" ) ; 49+ xhr . respondWith ( "GET" , new RegExp ( retrieveByAlternateKeyUrl , "g" ) ,
50+ [ 200 , { "Content-Type" : "application/json" } , JSON . stringify ( contact ) ]
51+ ) ;
52+
4253 // Respond to update Request for account
4354 var updateAccountUrl = RegExp . escape ( fakeUrl + "/api/data/v8.0/accounts(00000000-0000-0000-0000-000000000001)" ) ;
4455 xhr . respondWith ( "PATCH" , new RegExp ( updateAccountUrl , "g" ) ,
@@ -171,6 +182,28 @@ describe("WebApiClient", function() {
171182
172183 xhr . respond ( ) ;
173184 } ) ;
185+
186+ it ( "should retrieve by alternative key" , function ( done ) {
187+ WebApiClient . Retrieve (
188+ {
189+ entityName : "contact" ,
190+ alternateKey :
191+ [
192+ { property : "firstname" , value : "Joe" } ,
193+ { property :
"emailaddress1" , value :
"[email protected] " } 194+ ]
195+ } )
196+ . then ( function ( response ) {
197+ expect ( response ) . toEqual ( contact ) ;
198+ } )
199+ . catch ( function ( error ) {
200+ expect ( error ) . toBeUndefined ( ) ;
201+ } )
202+ // Wait for promise
203+ . finally ( done ) ;
204+
205+ xhr . respond ( ) ;
206+ } ) ;
174207 } ) ;
175208
176209 describe ( "Update" , function ( ) {
0 commit comments