UNPKG

@itentialopensource/adapter-scansource

Version:

This adapter integrates with system described as: apis.

1,365 lines (1,290 loc) 106 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-scansource', type: 'Scansource', 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 Scansource = require('../../adapter'); // begin the testing - these should be pretty well defined between the describe and the it! describe('[integration] Scansource Adapter Test', () => { describe('Scansource Class Tests', () => { const a = new Scansource( 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-scansource-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-scansource-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 addressCollectionKey = 'fakedata'; const addressAddressId = 555; describe('#addressCopyAddress - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addressCopyAddress(addressCollectionKey, addressAddressId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressCopyAddress', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const addressSourceCollectionKey = 'fakedata'; const addressDestinationCollectionKey = 'fakedata'; describe('#addressMoveAddress - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addressMoveAddress(addressSourceCollectionKey, addressDestinationCollectionKey, addressAddressId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressMoveAddress', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const addressAddressValidateBodyParam = { Street1: 'string', Street2: 'string', City: 'string', StateProvince: 'string', PostalCode: 'string', CountryCode: 'string' }; describe('#addressValidate - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addressValidate(addressAddressValidateBodyParam, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.State); assert.equal('string', data.response.Classification); assert.equal(true, Array.isArray(data.response.Attributes)); assert.equal('object', typeof data.response.EffectiveAddress); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressValidate', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const addressAddressAddAddressBodyParam = { AddressType: 4, Name: 'string', Attention: 'string', Phone: 'string', Street1: 'string', Street2: 'string', City: 'string', StateProvince: 'string', PostalCode: 'string', CountryCode: 'string', ExtendedData: 'string' }; describe('#addressAddAddress - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addressAddAddress(addressCollectionKey, addressAddressAddAddressBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressAddAddress', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const addressRegion = 555; describe('#addressGetAddressCountries - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addressGetAddressCountries(addressRegion, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressGetAddressCountries', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#addressExists - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addressExists(addressCollectionKey, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressExists', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const addressCountryCode = 'fakedata'; describe('#addressGetAddressProvinceStates - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addressGetAddressProvinceStates(addressCountryCode, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressGetAddressProvinceStates', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#addressSearch - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addressSearch(addressCollectionKey, null, null, null, null, null, addressCountryCode, null, null, (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('Address', 'addressSearch', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const addressAddressUpdateAddressBodyParam = { Id: 9, AddressType: 1, Name: 'string', Attention: 'string', Phone: 'string', Street1: 'string', Street2: 'string', City: 'string', StateProvince: 'string', PostalCode: 'string', CountryCode: 'string', ExtendedData: 'string' }; describe('#addressUpdateAddress - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.addressUpdateAddress(addressCollectionKey, addressAddressUpdateAddressBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressUpdateAddress', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#addressGetAddress - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.addressGetAddress(addressCollectionKey, addressAddressId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(8, data.response.Id); assert.equal('string', data.response.Created); assert.equal('string', data.response.Updated); assert.equal(3, data.response.AddressType); assert.equal('string', data.response.Name); assert.equal('string', data.response.Attention); assert.equal('string', data.response.Phone); assert.equal('string', data.response.Street1); assert.equal('string', data.response.Street2); assert.equal('string', data.response.City); assert.equal('string', data.response.StateProvince); assert.equal('string', data.response.PostalCode); assert.equal('string', data.response.CountryCode); assert.equal('string', data.response.ExtendedData); } else { runCommonAsserts(data, error); } saveMockData('Address', 'addressGetAddress', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const cartCartCollectionKey = 'fakedata'; const cartCartId = 555; const cartCartSaveCheckoutInfoBodyParam = { PONumber: 'string', EndUserPO: 'string', RequestedDeliveryDate: 'string', ShipMethodServiceLevelCode: 'string', ServiceLevelDescription: 'string', ShippingAccountNumber: 'string', FreightForwarderNumber: 'string', ShipComplete: false, Memo: 'string', PayorId: 'string', ShippingAddress: { Name: 'string', Street1: 'string', Street2: 'string', City: 'string', State: 'string', PostalCode: 'string', Country: 'string' }, Carrier: { CarrierAddress: { Name: 'string', Street1: 'string', Street2: 'string', City: 'string', State: 'string', PostalCode: 'string', Country: 'string' }, Phone: 'string' }, Created: 'string', Updated: 'string' }; describe('#cartSaveCheckoutInfo - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartSaveCheckoutInfo(cartCartCollectionKey, cartCartSaveCheckoutInfoBodyParam, cartCartId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartSaveCheckoutInfo', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartCopyCart - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartCopyCart(cartCartCollectionKey, cartCartId, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartCopyCart', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const cartCartAddItemBodyParam = { Item: 'string', Quantity: 7 }; describe('#cartAddItem - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartAddItem(cartCartCollectionKey, cartCartAddItemBodyParam, cartCartId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartAddItem', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const cartSourceCollectionKey = 'fakedata'; const cartDestinationCollectionKey = 'fakedata'; describe('#cartMoveCart - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartMoveCart(cartSourceCollectionKey, cartDestinationCollectionKey, cartCartId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartMoveCart', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const cartCartAddCartBodyParam = { Name: 'string' }; describe('#cartAddCart - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartAddCart(cartCartCollectionKey, cartCartAddCartBodyParam, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartAddCart', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartGetCheckoutInfo - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.cartGetCheckoutInfo(cartCartCollectionKey, cartCartId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.PONumber); assert.equal('string', data.response.EndUserPO); assert.equal('string', data.response.RequestedDeliveryDate); assert.equal('string', data.response.ShipMethodServiceLevelCode); assert.equal('string', data.response.ServiceLevelDescription); assert.equal('string', data.response.ShippingAccountNumber); assert.equal('string', data.response.FreightForwarderNumber); assert.equal(true, data.response.ShipComplete); assert.equal('string', data.response.Memo); assert.equal('string', data.response.PayorId); assert.equal('object', typeof data.response.ShippingAddress); assert.equal('object', typeof data.response.Carrier); assert.equal('string', data.response.Created); assert.equal('string', data.response.Updated); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartGetCheckoutInfo', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartExists - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartExists(cartCartCollectionKey, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartExists', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartHasCurrent - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartHasCurrent(cartCartCollectionKey, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartHasCurrent', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const cartCartUpdateItemBodyParam = { Item: 'string', Quantity: 8 }; describe('#cartUpdateItem - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartUpdateItem(cartCartCollectionKey, cartCartId, cartCartUpdateItemBodyParam, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartUpdateItem', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartGetCartList - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.cartGetCartList(cartCartCollectionKey, null, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(7, data.response.CurrentCartId); assert.equal(true, Array.isArray(data.response.Carts)); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartGetCartList', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartSwitchCurrentCart - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartSwitchCurrentCart(cartCartCollectionKey, cartCartId, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartSwitchCurrentCart', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const cartCartUpdateCartBodyParam = { Name: 'string' }; describe('#cartUpdateCart - errors', () => { it('should work if integrated but since no mockdata should error when run standalone', (done) => { try { a.cartUpdateCart(cartCartCollectionKey, cartCartUpdateCartBodyParam, null, (data, error) => { try { if (stub) { const displayE = 'Error 400 received on request'; runErrorAsserts(data, error, 'AD.500', 'Test-scansource-connectorRest-handleEndResponse', displayE); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartUpdateCart', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#cartGetCart - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.cartGetCart(cartCartCollectionKey, cartCartId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(8, data.response.Id); assert.equal('string', data.response.Name); assert.equal('string', data.response.Description); assert.equal('string', data.response.ExtendedData); assert.equal(true, Array.isArray(data.response.CartItems)); assert.equal('object', typeof data.response.CartCheckoutInfo); assert.equal('string', data.response.Created); assert.equal('string', data.response.Updated); } else { runCommonAsserts(data, error); } saveMockData('Cart', 'cartGetCart', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const ciscoDartDealId = 'fakedata'; describe('#ciscoDartGetDetail - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.ciscoDartGetDetail(ciscoDartDealId, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.DealId); assert.equal(true, Array.isArray(data.response.Lines)); } else { runCommonAsserts(data, error); } saveMockData('CiscoDart', 'ciscoDartGetDetail', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const ciscoDartCustomerNumber = 'fakedata'; describe('#ciscoDartGetSummary - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.ciscoDartGetSummary(ciscoDartCustomerNumber, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('CiscoDart', 'ciscoDartGetSummary', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const customConfigCustomerNumber = 'fakedata'; describe('#customConfigGetCustomConfigs - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.customConfigGetCustomConfigs(customConfigCustomerNumber, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('object', typeof data.response[0]); } else { runCommonAsserts(data, error); } saveMockData('CustomConfig', 'customConfigGetCustomConfigs', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const customerCustomerNumber = 'fakedata'; const customerRegion = 'fakedata'; describe('#customerGetCustCreditData - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.customerGetCustCreditData(customerCustomerNumber, customerRegion, (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('Customer', 'customerGetCustCreditData', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const customerBusinessUnit = 'fakedata'; describe('#customerGetPayers - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.customerGetPayers(customerCustomerNumber, customerBusinessUnit, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal(true, Array.isArray(data.response.Payers)); assert.equal(true, Array.isArray(data.response.Errors)); assert.equal(true, Array.isArray(data.response.Warnings)); } else { runCommonAsserts(data, error); } saveMockData('Customer', 'customerGetPayers', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); const invoiceCustomerNumber = 'fakedata'; const invoiceInvoiceNumber = 'fakedata'; describe('#invoiceGetInvoiceDetail - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.invoiceGetInvoiceDetail(invoiceCustomerNumber, invoiceInvoiceNumber, null, (data, error) => { try { if (stub) { runCommonAsserts(data, error); assert.equal('string', data.response.InvoiceNumber); assert.equal('string', data.response.SalesOrderNumber); assert.equal('object', typeof data.response.BillingAddress); assert.equal('object', typeof data.response.ShippingAddress); assert.equal('string', data.response.PONumber); assert.equal('string', data.response.EndUserPO); assert.equal('string', data.response.ReferenceNumber); assert.equal('string', data.response.ShipDate); assert.equal('string', data.response.Cancelled); assert.equal('string', data.response.DocType); assert.equal('string', data.response.SalesRepCode); assert.equal('string', data.response.SalesRepName); assert.equal('string', data.response.SalesRepEmail); assert.equal(1, data.response.FreightAmount); assert.equal(1, data.response.TaxAmount); assert.equal(4, data.response.InsuranceAmount); assert.equal(10, data.response.Total); assert.equal('string', data.response.Currency); assert.equal('string', data.response.EnteredByEmail); assert.equal('string', data.response.ShippingOption); assert.equal('string', data.response.ShippingOptionDescription); assert.equal(true, Array.isArray(data.response.InvoiceLines)); assert.equal(true, Array.isArray(data.response.TrackingNumbers)); } else { runCommonAsserts(data, error); } saveMockData('Invoice', 'invoiceGetInvoiceDetail', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#invoiceGetInvoiceList - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.invoiceGetInvoiceList(invoiceCustomerNumber, null, null, null, invoiceInvoiceNumber, null, null, null, (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('Invoice', 'invoiceGetInvoiceList', 'default', data); done(); } catch (err) { log.error(`Test Failure: ${err}`); done(err); } }); } catch (error) { log.error(`Adapter Exception: ${error}`); done(error); } }).timeout(attemptTimeout); }); describe('#invoiceGetPDF - errors', () => { it('should work if integrated or standalone with mockdata', (done) => { try { a.invoiceGetPDF(invoiceCustomerNumber, invoiceInvoiceNumber, (data, error) => {