UNPKG

@itentialopensource/adapter-github

Version:

This adapter integrates with system described as: github.

1,406 lines (1,327 loc) 1.03 MB
/* @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 anything = td.matchers.anything(); // stub and attemptTimeout are used throughout the code so set them here let logLevel = 'none'; 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-github', type: 'GitHub', properties: samProps }] } }; global.$HOME = `${__dirname}/../..`; // set the log levels that Pronghorn uses, spam and trace are not defaulted in so without // this you may error on log.trace calls. const myCustomLevels = { levels: { spam: 6, trace: 5, debug: 4, info: 3, warn: 2, error: 1, none: 0 } }; // need to see if there is a log level passed in process.argv.forEach((val) => { // is there a log level defined to be passed in? if (val.indexOf('--LOG') === 0) { // get the desired log level const inputVal = val.split('=')[1]; // validate the log level is supported, if so set it if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) { logLevel = inputVal; } } }); // need to set global logging global.log = winston.createLogger({ level: logLevel, levels: myCustomLevels.levels, transports: [ new winston.transports.Console() ] }); /** * 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 GitHub = require('../../adapter'); // begin the testing - these should be pretty well defined between the describe and the it! describe('[integration] GitHub Adapter Test', () => { describe('GitHub Class Tests', () => { const a = new GitHub( 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-github-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-github-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 ****************** ----------------------------------------------------------------------- ----------------------------------------------------------------------- */ describe('#getEmojis - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getEmojis((data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Emojis', 'getEmojis', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getEvents - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getEvents((data, error) => { try { runCommonAsserts(data, error); if (stub) { 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('Events', 'getEvents', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getFeeds - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getFeeds((data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('string', data.response.current_user_actor_url); assert.equal('string', data.response.current_user_organization_url); assert.equal('string', data.response.current_user_public); assert.equal('string', data.response.current_user_url); assert.equal('string', data.response.timeline_url); assert.equal('string', data.response.user_url); } else { runCommonAsserts(data, error); } saveMockData('Feeds', 'getFeeds', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); let gistsId = 'fakedata'; const gistsPostGistsBodyParam = { description: 'string', files: { 'file1.txt': { content: 'string' } }, public: true }; describe('#postGists - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.postGists(gistsPostGistsBodyParam, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(10, data.response.comments); assert.equal('string', data.response.comments_url); assert.equal('string', data.response.created_at); assert.equal('string', data.response.description); assert.equal('object', typeof data.response.files); assert.equal(true, Array.isArray(data.response.forks)); assert.equal('string', data.response.git_pull_url); assert.equal('string', data.response.git_push_url); assert.equal(true, Array.isArray(data.response.history)); assert.equal('string', data.response.html_url); assert.equal('string', data.response.id); assert.equal(false, data.response.public); assert.equal('string', data.response.url); assert.equal('object', typeof data.response.user); } else { runCommonAsserts(data, error); } gistsId = data.response.id; saveMockData('Gists', 'postGists', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const gistsPostGistsIdCommentsBodyParam = { body: 'string' }; describe('#postGistsIdComments - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.postGistsIdComments(gistsId, gistsPostGistsIdCommentsBodyParam, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('string', data.response.body); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'postGistsIdComments', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#postGistsIdForks - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.postGistsIdForks(gistsId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'postGistsIdForks', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGists - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGists(null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'getGists', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGistsPublic - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGistsPublic(null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { 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('Gists', 'getGistsPublic', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGistsStarred - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGistsStarred(null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'getGistsStarred', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const gistsPatchGistsIdBodyParam = { description: 'string', files: { 'delete_this_file.txt': 'string', 'file1.txt': { content: 'string' }, 'new_file.txt': { content: 'string' }, 'old_name.txt': { content: 'string', filename: 'string' } } }; describe('#patchGistsId - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.patchGistsId(gistsId, gistsPatchGistsIdBodyParam, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(8, data.response.comments); assert.equal('string', data.response.comments_url); assert.equal('string', data.response.created_at); assert.equal('string', data.response.description); assert.equal('object', typeof data.response.files); assert.equal(true, Array.isArray(data.response.forks)); assert.equal('string', data.response.git_pull_url); assert.equal('string', data.response.git_push_url); assert.equal(true, Array.isArray(data.response.history)); assert.equal('string', data.response.html_url); assert.equal('string', data.response.id); assert.equal(false, data.response.public); assert.equal('string', data.response.url); assert.equal('object', typeof data.response.user); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'patchGistsId', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGistsId - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGistsId(gistsId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(9, data.response.comments); assert.equal('string', data.response.comments_url); assert.equal('string', data.response.created_at); assert.equal('string', data.response.description); assert.equal('object', typeof data.response.files); assert.equal(true, Array.isArray(data.response.forks)); assert.equal('string', data.response.git_pull_url); assert.equal('string', data.response.git_push_url); assert.equal(true, Array.isArray(data.response.history)); assert.equal('string', data.response.html_url); assert.equal('string', data.response.id); assert.equal(false, data.response.public); assert.equal('string', data.response.url); assert.equal('object', typeof data.response.user); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'getGistsId', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGistsIdComments - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGistsIdComments(gistsId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { 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('Gists', 'getGistsIdComments', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const gistsCommentId = 555; const gistsPatchGistsIdCommentsCommentIdBodyParam = { body: 'string' }; describe('#patchGistsIdCommentsCommentId - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.patchGistsIdCommentsCommentId(gistsId, gistsCommentId, gistsPatchGistsIdCommentsCommentIdBodyParam, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('string', data.response.body); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'patchGistsIdCommentsCommentId', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGistsIdCommentsCommentId - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGistsIdCommentsCommentId(gistsId, gistsCommentId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('string', data.response.body); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'getGistsIdCommentsCommentId', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#putGistsIdStar - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.putGistsIdStar(gistsId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'putGistsIdStar', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGistsIdStar - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getGistsIdStar(gistsId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Gists', 'getGistsIdStar', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getGitignoreTemplates - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGitignoreTemplates((data, error) => { try { if (stub) { runCommonAsserts(data, error); } else { runCommonAsserts(data, error); } saveMockData('Gitignore', 'getGitignoreTemplates', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const gitignoreLanguage = 'fakedata'; describe('#getGitignoreTemplatesLanguage - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getGitignoreTemplatesLanguage(gitignoreLanguage, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('string', data.response.name); assert.equal('string', data.response.source); } else { runCommonAsserts(data, error); } saveMockData('Gitignore', 'getGitignoreTemplatesLanguage', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const issuesFilter = 'fakedata'; const issuesState = 'fakedata'; const issuesLabels = 'fakedata'; const issuesSort = 'fakedata'; const issuesDirection = 'fakedata'; describe('#getIssues - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getIssues(issuesFilter, issuesState, issuesLabels, issuesSort, issuesDirection, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('Issues', 'getIssues', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const legacyKeyword = 'fakedata'; const legacyState = 'fakedata'; const legacyOwner = 'fakedata'; const legacyRepository = 'fakedata'; describe('#getLegacyIssuesSearchOwnerRepositoryStateKeyword - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getLegacyIssuesSearchOwnerRepositoryStateKeyword(legacyKeyword, legacyState, legacyOwner, legacyRepository, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(true, Array.isArray(data.response.issues)); } else { runCommonAsserts(data, error); } saveMockData('Legacy', 'getLegacyIssuesSearchOwnerRepositoryStateKeyword', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getLegacyReposSearchKeyword - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getLegacyReposSearchKeyword(legacyKeyword, null, null, null, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Legacy', 'getLegacyReposSearchKeyword', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const legacyEmail = 'fakedata'; describe('#getLegacyUserEmailEmail - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getLegacyUserEmailEmail(legacyEmail, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('object', typeof data.response.user); } else { runCommonAsserts(data, error); } saveMockData('Legacy', 'getLegacyUserEmailEmail', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getLegacyUserSearchKeyword - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getLegacyUserSearchKeyword(legacyKeyword, null, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(true, Array.isArray(data.response.users)); } else { runCommonAsserts(data, error); } saveMockData('Legacy', 'getLegacyUserSearchKeyword', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const markdownPostMarkdownBodyParam = { context: 'string', mode: 'string', text: 'string' }; describe('#postMarkdown - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.postMarkdown(markdownPostMarkdownBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Markdown', 'postMarkdown', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#postMarkdownRaw - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.postMarkdownRaw((data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Markdown', 'postMarkdownRaw', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getMeta - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getMeta((data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(true, Array.isArray(data.response.git)); assert.equal(true, Array.isArray(data.response.hooks)); } else { runCommonAsserts(data, error); } saveMockData('Meta', 'getMeta', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const networksOwner = 'fakedata'; const networksRepo = 'fakedata'; describe('#getNetworksOwnerRepoEvents - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getNetworksOwnerRepoEvents(networksOwner, networksRepo, (data, error) => { try { runCommonAsserts(data, error); if (stub) { 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('Networks', 'getNetworksOwnerRepoEvents', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const notificationsPutNotificationsBodyParam = { last_read_at: 'string' }; describe('#putNotifications - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.putNotifications(notificationsPutNotificationsBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Notifications', 'putNotifications', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); let notificationsId = 'fakedata'; describe('#getNotifications - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getNotifications(null, null, null, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(6, data.response.id); assert.equal('string', data.response.last_read_at); assert.equal('string', data.response.reason); assert.equal('object', typeof data.response.repository); assert.equal('object', typeof data.response.subject); assert.equal(false, data.response.unread); assert.equal('string', data.response.updated_at); assert.equal('string', data.response.url); } else { runCommonAsserts(data, error); } notificationsId = data.response.id; saveMockData('Notifications', 'getNotifications', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#patchNotificationsThreadsId - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.patchNotificationsThreadsId(notificationsId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-github-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Notifications', 'patchNotificationsThreadsId', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getNotificationsThreadsId - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.getNotificationsThreadsId(notificationsId, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal(4, data.response.id); assert.equal('string', data.response.last_read_at); assert.equal('string', data.response.reason); assert.equal('object', typeof data.response.repository); assert.equal('object', typeof data.response.subject); assert.equal(true, data.response.unread); assert.equal('string', data.response.updated_at); assert.equal('string', data.response.url); } else { runCommonAsserts(data, error); } saveMockData('Notifications', 'getNotificationsThreadsId', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const notificationsPutNotificationsThreadsIdSubscriptionBodyParam = { created_at: 'string', ignored: false, reason: {}, subscribed: true, thread_url: 'string', url: 'string' }; describe('#putNotificationsThreadsIdSubscription - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.putNotificationsThreadsIdSubscription(notificationsId, notificationsPutNotificationsThreadsIdSubscriptionBodyParam, (data, error) => { try { runCommonAsserts(data, error); if (stub) { assert.equal('string', data.response.created_at); assert.equal(false, data.response.ignored); assert.equal('string', data.response.reason); assert.equal('string', data.response.repository_url); assert.equal(false, data.response.subscribed); assert.equal('string', data.response.thread_url); assert.equal('string', data.response.url); } else { runCommonAsserts(data, error); } saveMockDat