@itentialopensource/adapter-azure_devops
Version: 
This adapter integrates with system described as: Azure DevOps.
1,469 lines (1,399 loc) • 188 kB
JavaScript
/* @copyright Itential, LLC 2019 (pre-modifications) */
// Set globals
/* global describe it log pronghornProps */
/* eslint no-unused-vars: warn */
/* eslint no-underscore-dangle: warn  */
/* eslint import/no-dynamic-require:warn */
// include required items for testing & logging
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const util = require('util');
const mocha = require('mocha');
const winston = require('winston');
const { expect } = require('chai');
const { use } = require('chai');
const td = require('testdouble');
const log = require('../../utils/logger');
const anything = td.matchers.anything();
// stub and attemptTimeout are used throughout the code so set them here
const isRapidFail = false;
const isSaveMockData = false;
// read in the properties from the sampleProperties files
let adaptdir = __dirname;
if (adaptdir.endsWith('/test/integration')) {
  adaptdir = adaptdir.substring(0, adaptdir.length - 17);
} else if (adaptdir.endsWith('/test/unit')) {
  adaptdir = adaptdir.substring(0, adaptdir.length - 10);
}
const samProps = require(`${adaptdir}/sampleProperties.json`).properties;
// these variables can be changed to run in integrated mode so easier to set them here
// always check these in with bogus data!!!
samProps.stub = true;
// uncomment if connecting
// samProps.host = 'replace.hostorip.here';
// samProps.authentication.username = 'username';
// samProps.authentication.password = 'password';
// samProps.authentication.token = 'password';
// samProps.protocol = 'http';
// samProps.port = 80;
// samProps.ssl.enabled = false;
// samProps.ssl.accept_invalid_cert = false;
if (samProps.request.attempt_timeout < 30000) {
  samProps.request.attempt_timeout = 30000;
}
samProps.devicebroker.enabled = true;
const attemptTimeout = samProps.request.attempt_timeout;
const { stub } = samProps;
// these are the adapter properties. You generally should not need to alter
// any of these after they are initially set up
global.pronghornProps = {
  pathProps: {
    encrypted: false
  },
  adapterProps: {
    adapters: [{
      id: 'Test-azure_devops',
      type: 'AzureDevops',
      properties: samProps
    }]
  }
};
global.$HOME = `${__dirname}/../..`;
/**
 * Runs the common asserts for test
 */
function runCommonAsserts(data, error) {
  assert.equal(undefined, error);
  assert.notEqual(undefined, data);
  assert.notEqual(null, data);
  assert.notEqual(undefined, data.response);
  assert.notEqual(null, data.response);
}
/**
 * Runs the error asserts for the test
 */
function runErrorAsserts(data, error, code, origin, displayStr) {
  assert.equal(null, data);
  assert.notEqual(undefined, error);
  assert.notEqual(null, error);
  assert.notEqual(undefined, error.IAPerror);
  assert.notEqual(null, error.IAPerror);
  assert.notEqual(undefined, error.IAPerror.displayString);
  assert.notEqual(null, error.IAPerror.displayString);
  assert.equal(code, error.icode);
  assert.equal(origin, error.IAPerror.origin);
  assert.equal(displayStr, error.IAPerror.displayString);
}
/**
 * @function saveMockData
 * Attempts to take data from responses and place them in MockDataFiles to help create Mockdata.
 * Note, this was built based on entity file structure for Adapter-Engine 1.6.x
 * @param {string} entityName - Name of the entity saving mock data for
 * @param {string} actionName -  Name of the action saving mock data for
 * @param {string} descriptor -  Something to describe this test (used as a type)
 * @param {string or object} responseData - The data to put in the mock file.
 */
function saveMockData(entityName, actionName, descriptor, responseData) {
  // do not need to save mockdata if we are running in stub mode (already has mock data) or if told not to save
  if (stub || !isSaveMockData) {
    return false;
  }
  // must have a response in order to store the response
  if (responseData && responseData.response) {
    let data = responseData.response;
    // if there was a raw response that one is better as it is untranslated
    if (responseData.raw) {
      data = responseData.raw;
      try {
        const temp = JSON.parse(data);
        data = temp;
      } catch (pex) {
        // do not care if it did not parse as we will just use data
      }
    }
    try {
      const base = path.join(__dirname, `../../entities/${entityName}/`);
      const mockdatafolder = 'mockdatafiles';
      const filename = `mockdatafiles/${actionName}-${descriptor}.json`;
      if (!fs.existsSync(base + mockdatafolder)) {
        fs.mkdirSync(base + mockdatafolder);
      }
      // write the data we retrieved
      fs.writeFile(base + filename, JSON.stringify(data, null, 2), 'utf8', (errWritingMock) => {
        if (errWritingMock) throw errWritingMock;
        // update the action file to reflect the changes. Note: We're replacing the default object for now!
        fs.readFile(`${base}action.json`, (errRead, content) => {
          if (errRead) throw errRead;
          // parse the action file into JSON
          const parsedJson = JSON.parse(content);
          // The object update we'll write in.
          const responseObj = {
            type: descriptor,
            key: '',
            mockFile: filename
          };
          // get the object for method we're trying to change.
          const currentMethodAction = parsedJson.actions.find((obj) => obj.name === actionName);
          // if the method was not found - should never happen but...
          if (!currentMethodAction) {
            throw Error('Can\'t find an action for this method in the provided entity.');
          }
          // if there is a response object, we want to replace the Response object. Otherwise we'll create one.
          const actionResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === descriptor);
          // Add the action responseObj back into the array of response objects.
          if (!actionResponseObj) {
            // if there is a default response object, we want to get the key.
            const defaultResponseObj = currentMethodAction.responseObjects.find((obj) => obj.type === 'default');
            // save the default key into the new response object
            if (defaultResponseObj) {
              responseObj.key = defaultResponseObj.key;
            }
            // save the new response object
            currentMethodAction.responseObjects = [responseObj];
          } else {
            // update the location of the mock data file
            actionResponseObj.mockFile = responseObj.mockFile;
          }
          // Save results
          fs.writeFile(`${base}action.json`, JSON.stringify(parsedJson, null, 2), (err) => {
            if (err) throw err;
          });
        });
      });
    } catch (e) {
      log.debug(`Failed to save mock data for ${actionName}. ${e.message}`);
      return false;
    }
  }
  // no response to save
  log.debug(`No data passed to save into mockdata for ${actionName}`);
  return false;
}
// require the adapter that we are going to be using
const AzureDevops = require('../../adapter');
// begin the testing - these should be pretty well defined between the describe and the it!
describe('[integration] Azure_devops Adapter Test', () => {
  describe('AzureDevops Class Tests', () => {
    const a = new AzureDevops(
      pronghornProps.adapterProps.adapters[0].id,
      pronghornProps.adapterProps.adapters[0].properties
    );
    if (isRapidFail) {
      const state = {};
      state.passed = true;
      mocha.afterEach(function x() {
        state.passed = state.passed
        && (this.currentTest.state === 'passed');
      });
      mocha.beforeEach(function x() {
        if (!state.passed) {
          return this.currentTest.skip();
        }
        return true;
      });
    }
    describe('#class instance created', () => {
      it('should be a class with properties', (done) => {
        try {
          assert.notEqual(null, a);
          assert.notEqual(undefined, a);
          const checkId = global.pronghornProps.adapterProps.adapters[0].id;
          assert.equal(checkId, a.id);
          assert.notEqual(null, a.allProps);
          const check = global.pronghornProps.adapterProps.adapters[0].properties.healthcheck.type;
          assert.equal(check, a.healthcheckType);
          done();
        } catch (error) {
          log.error(`Test Failure: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#connect', () => {
      it('should get connected - no healthcheck', (done) => {
        try {
          a.healthcheckType = 'none';
          a.connect();
          try {
            assert.equal(true, a.alive);
            done();
          } catch (error) {
            log.error(`Test Failure: ${error}`);
            done(error);
          }
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      });
      it('should get connected - startup healthcheck', (done) => {
        try {
          a.healthcheckType = 'startup';
          a.connect();
          try {
            assert.equal(true, a.alive);
            done();
          } catch (error) {
            log.error(`Test Failure: ${error}`);
            done(error);
          }
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      });
    });
    describe('#healthCheck', () => {
      it('should be healthy', (done) => {
        try {
          a.healthCheck(null, (data) => {
            try {
              assert.equal(true, a.healthy);
              saveMockData('system', 'healthcheck', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    // broker tests
    describe('#getDevicesFiltered - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          const opts = {
            filter: {
              name: 'deviceName'
            }
          };
          a.getDevicesFiltered(opts, (data, error) => {
            try {
              if (stub) {
                if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') {
                  assert.equal(null, error);
                  assert.notEqual(undefined, data);
                  assert.notEqual(null, data);
                  assert.equal(0, data.total);
                  assert.equal(0, data.list.length);
                } else {
                  const displayE = 'Error 400 received on request';
                  runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
                }
              } else {
                runCommonAsserts(data, error);
              }
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#iapGetDeviceCount - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          const opts = {
            filter: {
              name: 'deviceName'
            }
          };
          a.iapGetDeviceCount((data, error) => {
            try {
              if (stub) {
                if (samProps.devicebroker.getDevicesFiltered[0].handleFailure === 'ignore') {
                  assert.equal(null, error);
                  assert.notEqual(undefined, data);
                  assert.notEqual(null, data);
                  assert.equal(0, data.count);
                } else {
                  const displayE = 'Error 400 received on request';
                  runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
                }
              } else {
                runCommonAsserts(data, error);
              }
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    // exposed cache tests
    describe('#iapPopulateEntityCache - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.iapPopulateEntityCache('Device', (data, error) => {
            try {
              if (stub) {
                assert.equal(null, data);
                assert.notEqual(undefined, error);
                assert.notEqual(null, error);
                done();
              } else {
                assert.equal(undefined, error);
                assert.equal('success', data[0]);
                done();
              }
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#iapRetrieveEntitiesCache - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.iapRetrieveEntitiesCache('Device', {}, (data, error) => {
            try {
              if (stub) {
                assert.equal(null, data);
                assert.notEqual(null, error);
                assert.notEqual(undefined, error);
              } else {
                assert.equal(undefined, error);
                assert.notEqual(null, data);
                assert.notEqual(undefined, data);
              }
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    /*
    -----------------------------------------------------------------------
    -----------------------------------------------------------------------
    *** All code above this comment will be replaced during a migration ***
    ******************* DO NOT REMOVE THIS COMMENT BLOCK ******************
    -----------------------------------------------------------------------
    -----------------------------------------------------------------------
    */
    const pipelinesOrganization = 'fakedata';
    const pipelinesProject = 'fakedata';
    const pipelinesApiVersion = 'fakedata';
    let pipelinesPipelineId = 555;
    const pipelinesPipelinesCreateBodyParam = {
      configuration: null,
      folder: 'string',
      name: 'string'
    };
    describe('#pipelinesCreate - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.pipelinesCreate(pipelinesOrganization, pipelinesPipelinesCreateBodyParam, pipelinesProject, pipelinesApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('string', data.response.folder);
                assert.equal(7, data.response.id);
                assert.equal('string', data.response.name);
                assert.equal(7, data.response.revision);
              } else {
                runCommonAsserts(data, error);
              }
              pipelinesPipelineId = data.response.id;
              saveMockData('Pipelines', 'pipelinesCreate', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#pipelinesList - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.pipelinesList(pipelinesOrganization, pipelinesProject, null, null, null, pipelinesApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
                assert.equal('object', typeof data.response[2]);
                assert.equal('object', typeof data.response[3]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Pipelines', 'pipelinesList', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#pipelinesGet - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.pipelinesGet(pipelinesOrganization, pipelinesProject, pipelinesPipelineId, null, pipelinesApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('string', data.response.folder);
                assert.equal(10, data.response.id);
                assert.equal('string', data.response.name);
                assert.equal(6, data.response.revision);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Pipelines', 'pipelinesGet', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const previewOrganization = 'fakedata';
    const previewProject = 'fakedata';
    const previewPipelineId = 555;
    const previewApiVersion = 'fakedata';
    const previewPreviewPreviewBodyParam = {
      previewRun: false,
      resources: null,
      stagesToSkip: [
        'string'
      ],
      templateParameters: {},
      variables: {},
      yamlOverride: 'string'
    };
    describe('#previewPreview - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.previewPreview(previewOrganization, previewPreviewPreviewBodyParam, previewProject, previewPipelineId, null, previewApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('string', data.response.finalYaml);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Preview', 'previewPreview', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const runsOrganization = 'fakedata';
    const runsProject = 'fakedata';
    let runsPipelineId = 555;
    const runsApiVersion = 'fakedata';
    let runsRunId = 555;
    const runsRunsRunPipelineBodyParam = {
      previewRun: false,
      resources: null,
      stagesToSkip: [
        'string'
      ],
      templateParameters: {},
      variables: {},
      yamlOverride: 'string'
    };
    describe('#runsRunPipeline - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.runsRunPipeline(runsOrganization, runsRunsRunPipelineBodyParam, runsProject, runsPipelineId, null, runsApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal(2, data.response.id);
                assert.equal('string', data.response.name);
              } else {
                runCommonAsserts(data, error);
              }
              runsPipelineId = data.response.id;
              runsRunId = data.response.id;
              saveMockData('Runs', 'runsRunPipeline', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#runsList - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.runsList(runsOrganization, runsProject, runsPipelineId, runsApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
                assert.equal('object', typeof data.response[2]);
                assert.equal('object', typeof data.response[3]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Runs', 'runsList', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#runsGet - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.runsGet(runsOrganization, runsProject, runsPipelineId, runsRunId, runsApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal(5, data.response.id);
                assert.equal('string', data.response.name);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Runs', 'runsGet', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const artifactsOrganization = 'fakedata';
    const artifactsProject = 'fakedata';
    const artifactsPipelineId = 555;
    const artifactsRunId = 555;
    const artifactsArtifactName = 'fakedata';
    const artifactsApiVersion = 'fakedata';
    describe('#artifactsGet - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.artifactsGet(artifactsOrganization, artifactsProject, artifactsPipelineId, artifactsRunId, artifactsArtifactName, null, artifactsApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('string', data.response.name);
                assert.equal('string', data.response.url);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Artifacts', 'artifactsGet', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const logsOrganization = 'fakedata';
    const logsProject = 'fakedata';
    const logsPipelineId = 555;
    const logsRunId = 555;
    const logsApiVersion = 'fakedata';
    describe('#logsList - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.logsList(logsOrganization, logsProject, logsPipelineId, logsRunId, null, logsApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal(true, Array.isArray(data.response.logs));
                assert.equal('object', typeof data.response.signedContent);
                assert.equal('string', data.response.url);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Logs', 'logsList', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const logsLogId = 555;
    describe('#logsGet - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.logsGet(logsOrganization, logsProject, logsPipelineId, logsRunId, logsLogId, null, logsApiVersion, (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('string', data.response.createdOn);
                assert.equal(4, data.response.id);
                assert.equal('string', data.response.lastChangedOn);
                assert.equal(5, data.response.lineCount);
                assert.equal('object', typeof data.response.signedContent);
                assert.equal('string', data.response.url);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Logs', 'logsGet', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#repositoriesGetDeletedRepositories - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.repositoriesGetDeletedRepositories('fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesGetDeletedRepositories', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#repositoriesGetRecycleBinRepositories - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.repositoriesGetRecycleBinRepositories('fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesGetRecycleBinRepositories', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#repositoriesDeleteRepositoryFromRecycleBin - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.repositoriesDeleteRepositoryFromRecycleBin('fakedata', 'fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesDeleteRepositoryFromRecycleBin', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const repositoriesRepositoriesRestoreRepositoryFromRecycleBinBodyParam = {
      deleted: false
    };
    describe('#repositoriesRestoreRepositoryFromRecycleBin - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.repositoriesRestoreRepositoryFromRecycleBin('fakedata', repositoriesRepositoriesRestoreRepositoryFromRecycleBinBodyParam, 'fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesRestoreRepositoryFromRecycleBin', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const repositoriesRepositoriesCreateBodyParam = {
      name: 'string',
      parentRepository: {
        collection: {
          id: 'string',
          name: 'string',
          url: 'string'
        },
        id: 'string',
        isFork: false,
        name: 'string',
        project: {
          abbreviation: 'string',
          defaultTeamImageUrl: 'string',
          description: 'string',
          id: 'string',
          lastUpdateTime: 'string',
          name: 'string',
          revision: 4,
          state: 'deleting',
          url: 'string',
          visibility: 'private'
        },
        remoteUrl: 'string',
        sshUrl: 'string',
        url: 'string'
      },
      project: {
        abbreviation: 'string',
        defaultTeamImageUrl: 'string',
        description: 'string',
        id: 'string',
        lastUpdateTime: 'string',
        name: 'string',
        revision: 3,
        state: 'wellFormed',
        url: 'string',
        visibility: 'private'
      }
    };
    describe('#repositoriesCreate - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.repositoriesCreate('fakedata', repositoriesRepositoriesCreateBodyParam, 'fakedata', null, 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesCreate', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#repositoriesList - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.repositoriesList('fakedata', 'fakedata', null, null, null, 'fakedata', (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesList', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#repositoriesDelete - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.repositoriesDelete('fakedata', 'fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesDelete', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#repositoriesGetRepository - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.repositoriesGetRepository('fakedata', 'fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesGetRepository', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const repositoriesRepositoriesUpdateBodyParam = {
      _links: {
        links: {}
      },
      defaultBranch: 'string',
      id: 'string',
      isDisabled: true,
      isFork: false,
      name: 'string',
      parentRepository: {
        collection: {
          id: 'string',
          name: 'string',
          url: 'string'
        },
        id: 'string',
        isFork: true,
        name: 'string',
        project: {
          abbreviation: 'string',
          defaultTeamImageUrl: 'string',
          description: 'string',
          id: 'string',
          lastUpdateTime: 'string',
          name: 'string',
          revision: 4,
          state: 'all',
          url: 'string',
          visibility: 'public'
        },
        remoteUrl: 'string',
        sshUrl: 'string',
        url: 'string'
      },
      project: {
        abbreviation: 'string',
        defaultTeamImageUrl: 'string',
        description: 'string',
        id: 'string',
        lastUpdateTime: 'string',
        name: 'string',
        revision: 2,
        state: 'deleted',
        url: 'string',
        visibility: 'private'
      },
      remoteUrl: 'string',
      size: 6,
      sshUrl: 'string',
      url: 'string',
      validRemoteUrls: [
        'string'
      ],
      webUrl: 'string'
    };
    describe('#repositoriesUpdate - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.repositoriesUpdate('fakedata', repositoriesRepositoriesUpdateBodyParam, 'fakedata', 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('Repositories', 'repositoriesUpdate', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const refsFavoritesRefsFavoritesCreateBodyParam = {
      _links: {
        links: {}
      },
      id: 2,
      identityId: 'string',
      name: 'string',
      repositoryId: 'string',
      type: 'invalid',
      url: 'string'
    };
    describe('#refsFavoritesCreate - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.refsFavoritesCreate('fakedata', refsFavoritesRefsFavoritesCreateBodyParam, 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('RefsFavorites', 'refsFavoritesCreate', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#refsFavoritesList - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.refsFavoritesList('fakedata', 'fakedata', null, null, 'fakedata', (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
                assert.equal('object', typeof data.response[2]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('RefsFavorites', 'refsFavoritesList', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#refsFavoritesDelete - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.refsFavoritesDelete('fakedata', 'fakedata', 555, 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('RefsFavorites', 'refsFavoritesDelete', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#refsFavoritesGet - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.refsFavoritesGet('fakedata', 'fakedata', 555, 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('RefsFavorites', 'refsFavoritesGet', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#policyConfigurationsGet - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.policyConfigurationsGet('fakedata', 'fakedata', null, null, null, null, null, 'fakedata', (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('PolicyConfigurations', 'policyConfigurationsGet', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#pullRequestsGetPullRequestsByProject - errors', () => {
      it('should work if integrated or standalone with mockdata', (done) => {
        try {
          a.pullRequestsGetPullRequestsByProject('fakedata', 'fakedata', null, null, null, null, null, null, null, null, null, null, null, 'fakedata', (data, error) => {
            try {
              if (stub) {
                runCommonAsserts(data, error);
                assert.equal('object', typeof data.response[0]);
                assert.equal('object', typeof data.response[1]);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('PullRequests', 'pullRequestsGetPullRequestsByProject', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    describe('#pullRequestsGetPullRequestById - errors', () => {
      it('should work if integrated but since no mockdata should error when run standalone', (done) => {
        try {
          a.pullRequestsGetPullRequestById('fakedata', 555, 'fakedata', 'fakedata', (data, error) => {
            try {
              if (stub) {
                const displayE = 'Error 400 received on request';
                runErrorAsserts(data, error, 'AD.500', 'Test-azure_devops-connectorRest-handleEndResponse', displayE);
              } else {
                runCommonAsserts(data, error);
              }
              saveMockData('PullRequests', 'pullRequestsGetPullRequestById', 'default', data);
              done();
            } catch (err) {
              log.error(`Test Failure: ${err}`);
              done(err);
            }
          });
        } catch (error) {
          log.error(`Adapter Exception: ${error}`);
          done(error);
        }
      }).timeout(attemptTimeout);
    });
    const pullRequestsPullRequestsCreateBodyParam = {
      _links: {
        links: {}
      },
      artifactId: 'string',
      autoCompleteSetBy: {
        _links: {
          links: {}
        },
        descriptor: 'string',
        displayName: 'string',
        url: 'string'
      },
      closedBy: {
        _links: {
          links: {}
        },
        descriptor: 'string',
        displayName: 'string',
        url: 'string'
      },
      closedDate: 'string',
      codeReviewId: 1,
      commits: [
        {
          _links: {
            links: {}
          },
          author: {
            date: 'string',
            email: 'string',
            imageUrl: 'string',
            name: 'string'
          },
          changeCounts: {},
          changes: [
            {
              changeType: 'property',
              item: 'string',
              newContent: {
                content: 'string',
                contentType: 'base64Encoded'
              },
              sourceServerItem: 'string',
              url: 'string'
            }
          ],
          comment: 'string',
          commentTruncated: true,
          commitId: 'string',
          committer: {
            date: 'string',
            email: 'string',
            imageUrl: 'string',
            name: 'string'
          },
          parents: [
            'string'
          ],
          push: {
            _links: {
              links: {}
            },
            date: 'string',
            pushedBy: {
              _links: {
                links: {}
              },
              descriptor: 'string',
              displayName: 'string',
              url: 'string'
            },
            pushId: 1,
            url: 'string'
          },
          remoteUrl: 'string',
          statuses: [
            {
              _links: {
                links: {}
              },
              context: {
                genre: 'string',
                name: 'string'
              },
              createdBy: {
                _links: {
                  links: {}
                },
                descriptor: 'string',
                displayName: 'string',
                url: 'string'
              },
              creationDate: 'string',
              description: 'string',
              id: 1,
              state: 'succeeded',
              targetUrl: 'string',
              updatedDate: 'string'
            }
          ],
          url: 'string',
          workItems: [
            {
              id: 'string',
              url: 'string'
            }
          ]
        }
      ],
      completionOptions: {
        autoCompleteIgnoreConfigIds: [
          3
        ],
        bypassPolicy: false,
        bypassReason: 'string',
        deleteSourceBranch: false,
        mergeCommitMessage: 'string',
        mergeStrategy: 'rebaseMerge',
        squashMerge: false,
        transitionWorkItems: true,
        triggeredByAutoComplete: true
      },
      completionQueueTime: 'string',
      createdBy: {
        _links: {
          links: {}
        },
        descriptor: 'string',
        displayName: 'string',
        url: 'string'
      },
      creationDate: 'string',
      description: 'string',
      forkSource: {
        _links: {
          links: {}
        },
        creator: {
          _links: {
            links: {}
          },
          descriptor: 'string',
          displayName: 'string',
          url: 'string'
        },
        isLocked: false,
        isLockedBy: {
          _links: {
            links: {}
          },
          descriptor: 'string',
          displayName: 'string',
          url: 'string'
        },
        name: 'string',
        objectId: 'string',
        peeledObjectId: 'string',
        statuses: [
          {
            _links: {
              links: {}
            },
            context: {
              genre: 'string',
              name: 'string'
            },
            createdBy: {
              _links: {
                links: {}
              },
              descriptor: 'string',
              displayName: 'string',
              url: 'string'
            },
            creationDate: 'string',
            description: 'string',
            id: 1,
            state: 'notSet',
            targetUrl: 'string',
            updatedDate: 'string'
          }
        ],
        url: 'string'
      },
      hasMultipleMergeBases: false,
      isDraft: false,