UNPKG

@itentialopensource/adapter-opsgenie

Version:

This adapter integrates with system described as: opsgenieRestApi.

1,440 lines (1,364 loc) 193 kB
/* @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-opsgenie', type: 'Opsgenie', 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 Opsgenie = require('../../adapter'); // begin the testing - these should be pretty well defined between the describe and the it! describe('[integration] Opsgenie Adapter Test', () => { describe('Opsgenie Class Tests', () => { const a = new Opsgenie( 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-opsgenie-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-opsgenie-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 ****************** ----------------------------------------------------------------------- ----------------------------------------------------------------------- */ let alertRequestId = 'fakedata'; const alertCreateAlertBodyParam = { user: 'string', note: 'string', source: 'string', message: 'string', alias: 'string', description: 'string', responders: [ { type: 'none', id: 'string' } ], visibleTo: [ { type: 'escalation', id: 'string' } ], actions: [ 'string' ], tags: [ 'string' ], details: {}, entity: 'string', priority: 'P1' }; describe('#createAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.createAlert(alertCreateAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(7, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } alertRequestId = data.response.requestId; saveMockData('Alert', 'createAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertCreateSavedSearchesBodyParam = { name: 'string', query: 'string', owner: {} }; describe('#createSavedSearches - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.createSavedSearches(alertCreateSavedSearchesBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'createSavedSearches', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertIdentifier = 'fakedata'; const alertAcknowledgeAlertBodyParam = { user: 'string', note: 'string', source: 'string' }; describe('#acknowledgeAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.acknowledgeAlert(alertIdentifier, null, alertAcknowledgeAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(8, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'acknowledgeAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertActionName = 'fakedata'; const alertExecuteCustomAlertActionBodyParam = { user: 'string', note: 'string', source: 'string' }; describe('#executeCustomAlertAction - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.executeCustomAlertAction(alertIdentifier, null, alertActionName, alertExecuteCustomAlertActionBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(7, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'executeCustomAlertAction', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAssignAlertBodyParam = { user: 'string', note: 'string', source: 'string', owner: { type: 'team', id: 'string', username: samProps.authentication.username } }; describe('#assignAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.assignAlert(alertIdentifier, null, alertAssignAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(1, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'assignAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertFile = 'fakedata'; describe('#addAttachment - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addAttachment(alertIdentifier, null, alertFile, null, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'addAttachment', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertCloseAlertBodyParam = { user: 'string', note: 'string', source: 'string' }; describe('#closeAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.closeAlert(alertIdentifier, null, alertCloseAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(7, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'closeAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAddDetailsBodyParam = { user: 'string', note: 'string', source: 'string', details: {} }; describe('#addDetails - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addDetails(alertIdentifier, null, alertAddDetailsBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(7, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'addDetails', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertEscalateAlertBodyParam = { user: 'string', note: 'string', source: 'string', escalation: { type: 'user', id: 'string', name: 'string' } }; describe('#escalateAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.escalateAlert(alertIdentifier, null, alertEscalateAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(1, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'escalateAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAddNoteBodyParam = { note: 'string' }; describe('#addNote - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addNote(alertIdentifier, null, alertAddNoteBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(2, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'addNote', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAddResponderBodyParam = { user: 'string', note: 'string', source: 'string', responder: { type: 'team', id: 'string' } }; describe('#addResponder - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addResponder(alertIdentifier, null, alertAddResponderBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(10, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'addResponder', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertSnoozeAlertBodyParam = { user: 'string', note: 'string', source: 'string', endTime: 'string' }; describe('#snoozeAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.snoozeAlert(alertIdentifier, null, alertSnoozeAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(3, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'snoozeAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAddTagsBodyParam = { user: 'string', note: 'string', source: 'string', tags: [ 'string' ] }; describe('#addTags - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addTags(alertIdentifier, null, alertAddTagsBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(4, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'addTags', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAddTeamBodyParam = { user: 'string', note: 'string', source: 'string', team: { type: 'group', id: 'string', name: 'string' } }; describe('#addTeam - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addTeam(alertIdentifier, null, alertAddTeamBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(2, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'addTeam', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertUnAcknowledgeAlertBodyParam = { user: 'string', note: 'string', source: 'string' }; describe('#unAcknowledgeAlert - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.unAcknowledgeAlert(alertIdentifier, null, alertUnAcknowledgeAlertBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(4, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'unAcknowledgeAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#listAlerts - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.listAlerts(null, null, null, null, null, null, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'listAlerts', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#countAlerts - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.countAlerts(null, null, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'countAlerts', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getRequestStatus - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getRequestStatus(alertRequestId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'getRequestStatus', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#listSavedSearches - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.listSavedSearches((data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'listSavedSearches', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertUpdateSavedSearchBodyParam = { name: 'string', query: 'string', owner: {} }; describe('#updateSavedSearch - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.updateSavedSearch(alertIdentifier, null, alertUpdateSavedSearchBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'updateSavedSearch', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getSavedSearch - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getSavedSearch(alertIdentifier, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'getSavedSearch', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#getAlert - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getAlert(alertIdentifier, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'getAlert', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#listAttachments - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.listAttachments(alertIdentifier, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'listAttachments', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertAttachmentId = 555; describe('#getAttachment - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.getAttachment(alertIdentifier, null, alertAttachmentId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'getAttachment', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertUpdateAlertDescriptionBodyParam = { description: 'string' }; describe('#updateAlertDescription - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.updateAlertDescription(alertIdentifier, null, alertUpdateAlertDescriptionBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('success', data.response); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'updateAlertDescription', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#listLogs - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.listLogs(alertIdentifier, null, null, null, null, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'listLogs', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertUpdateAlertMessageBodyParam = { message: 'string' }; describe('#updateAlertMessage - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.updateAlertMessage(alertIdentifier, null, alertUpdateAlertMessageBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('success', data.response); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'updateAlertMessage', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#listNotes - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.listNotes(alertIdentifier, null, null, null, null, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'listNotes', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const alertUpdateAlertPriorityBodyParam = { priority: 'P4' }; describe('#updateAlertPriority - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.updateAlertPriority(alertIdentifier, null, alertUpdateAlertPriorityBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('success', data.response); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'updateAlertPriority', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#listRecipients - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.listRecipients(alertIdentifier, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Alert', 'listRecipients', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const integrationCreateIntegrationBodyParam = { type: 'CloudWatchEvents', name: 'string' }; describe('#createIntegration - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.createIntegration(integrationCreateIntegrationBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Integration', 'createIntegration', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const integrationAuthenticateIntegrationBodyParam = { type: 'Apimetrics' }; describe('#authenticateIntegration - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.authenticateIntegration(integrationAuthenticateIntegrationBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.requestId); assert.equal(10, data.response.took); assert.equal('string', data.response.result); assert.equal('object', typeof data.response.data); } else { runCommonAsserts(data, error); } saveMockData('Integration', 'authenticateIntegration', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const integrationId = 'fakedata'; describe('#disableIntegration - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.disableIntegration(integrationId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-opsgenie-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Integration', 'disableIntegration', 'd