Showing posts with label webapi. Show all posts
Showing posts with label webapi. Show all posts

Tuesday, September 8, 2020

Mock Xrm.WebApi.retrieveRecord(...).then in Jasmine Unit test without using any other node module

In the describe/beforeEach/it add below :

For Successful call:

 Xrm: {

  WebApi: {

        retrieveRecord: () => {
            //Add the result Object Properties to this object below
            var retrieveRecordResult = {
            };
            return Promise.resolve(retrieveRecordResult);
        }
        retrieveMultipleRecords: () => {
            //Add the result array Properties to this object below
            var retrieveMultipleRecordsResults = {
                entities: [{ fieldName: fieldValue, anotherFiedName: anotherFieldValue }]
            };
            return Promise.resolve(retrieveMultipleRecordsResults);
        }
    }
}
  window['Xrm']=Xrm;

For Error in the call:

Xrm: {
    WebApi: {
        retrieveRecord: () => {
            //Add the result Object Properties to this object below
            var retrieveRecordError = {
                message: 'Error in retrieve Multiple'
            };
            return Promise.reject(retrieveRecordError);
        }
        retrieveMultipleRecords: () => {
            //Add the result array Properties to this object below
            var retrieveMultipleRecordsError = {
                message: 'Error in retrieve Multiple'
            };
            return Promise.reject(retrieveMultipleRecordsError);
        }
    }
}
  window['Xrm']=Xrm;