diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0b3f625..779ebad 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [16.x, 18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: diff --git a/package.json b/package.json index 72965ae..8555a4d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ "clean:dist": "npx rimraf dist/", "clean:src": "npx rimraf src/Manage/ & npx rimraf src/Automate/", "clean": "npm run clean:dist & npm run clean:generator & npm run clean:src", - "test": "npx nyc mocha", + "test": "npm run test:manage", + "test:automate": "npx nyc mocha test/test-automate.js", + "test:manage": "npx nyc mocha test/test-manage.js", "pregenerate": "npm run clean", "generate:automate": "node generator/automate-generator.js", "generate:manage": "node generator/manage-generator.js", diff --git a/test/test-automate.js b/test/test-automate.js new file mode 100644 index 0000000..75e6bd3 --- /dev/null +++ b/test/test-automate.js @@ -0,0 +1,120 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const dotenv = require('dotenv') +const path = require('path') +const { AutomateAPI } = require('../dist') +const assert = require('assert') +const { describe, it } = require('mocha') + +dotenv.config({ path: path.join(__dirname, '.env') }) + +const { AUTOMATE_API_CLIENT_ID, AUTOMATE_API_PASSWORD, AUTOMATE_API_URL, AUTOMATE_API_USER } = + process.env + +const cwa = new AutomateAPI({ + clientId: AUTOMATE_API_CLIENT_ID, + serverUrl: AUTOMATE_API_URL, + username: AUTOMATE_API_USER, + password: AUTOMATE_API_PASSWORD, + // eslint-disable-next-line @typescript-eslint/no-empty-function + logger: () => {}, +}) + +describe('Automate', () => { + describe('instance', () => { + it('should be an instance of Automate', (done) => { + assert(cwa instanceof AutomateAPI) + done() + }) + + it('should have AVTemplatePoliciesAPI', (done) => { + assert(cwa.AVTemplatePoliciesAPI) + done() + }) + it('should have ClientsAPI', (done) => { + assert(cwa.ClientsAPI) + done() + }) + it('should have CommandsAPI', (done) => { + assert(cwa.CommandsAPI) + done() + }) + it('should have ComputersAPI', (done) => { + assert(cwa.ComputersAPI) + done() + }) + it('should have ContactsAPI', (done) => { + assert(cwa.ContactsAPI) + done() + }) + it('should have DataViewsAPI', (done) => { + assert(cwa.DataViewsAPI) + done() + }) + it('should have DrivesAPI', (done) => { + assert(cwa.DrivesAPI) + done() + }) + it('should have EventLogsAPI', (done) => { + assert(cwa.EventLogsAPI) + done() + }) + it('should have LocationsAPI', (done) => { + assert(cwa.LocationsAPI) + done() + }) + it('should have MaintenanceWindowDefinitionsAPI', (done) => { + assert(cwa.MaintenanceWindowDefinitionsAPI) + done() + }) + it('should have MonitorsAPI', (done) => { + assert(cwa.MonitorsAPI) + done() + }) + it('should have NetworkDevicesAPI', (done) => { + assert(cwa.NetworkDevicesAPI) + done() + }) + it('should have PatchingAPI', (done) => { + assert(cwa.PatchingAPI) + done() + }) + it('should have RemoteAgentAPI', (done) => { + assert(cwa.RemoteAgentAPI) + done() + }) + it('should have ScriptingAPI', (done) => { + assert(cwa.ScriptingAPI) + done() + }) + it('should have SearchesAPI', (done) => { + assert(cwa.SearchesAPI) + done() + }) + it('should have SystemAPI', (done) => { + assert(cwa.SystemAPI) + done() + }) + it('should have TicketsAPI', (done) => { + assert(cwa.TicketsAPI) + done() + }) + it('should have UserProfilesAPI', (done) => { + assert(cwa.UserProfilesAPI) + done() + }) + }) + + describe('ComputersAPI', () => { + it('should return a list of computers', (done) => { + cwa.ComputersAPI.getComputerList({ pageSize: 1 }) + .then((results) => { + assert(results.length === 1) + const computer = results[0] + assert(computer.Id) + assert(computer.ComputerName) + done() + }) + .catch((error) => done(error)) + }) + }) +}) diff --git a/test/test.js b/test/test-manage.js similarity index 64% rename from test/test.js rename to test/test-manage.js index 04bc39d..ff2e29e 100644 --- a/test/test.js +++ b/test/test-manage.js @@ -4,7 +4,7 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const dotenv = require('dotenv') const path = require('path') -const { ManageAPI, AutomateAPI, utils } = require('../dist') +const { ManageAPI, utils } = require('../dist') const assert = require('assert') const { describe, it } = require('mocha') const { isPromise } = require('./test-utils.js') @@ -17,10 +17,6 @@ const { MANAGE_API_PUBLIC_KEY, MANAGE_API_PRIVATE_KEY, MANAGE_API_CLIENT_ID, - AUTOMATE_API_CLIENT_ID, - AUTOMATE_API_PASSWORD, - AUTOMATE_API_URL, - AUTOMATE_API_USER, } = process.env const cwm = new ManageAPI({ @@ -34,115 +30,6 @@ const cwm = new ManageAPI({ logger: () => {}, }) -const cwa = new AutomateAPI({ - clientId: AUTOMATE_API_CLIENT_ID, - serverUrl: AUTOMATE_API_URL, - username: AUTOMATE_API_USER, - password: AUTOMATE_API_PASSWORD, - // eslint-disable-next-line @typescript-eslint/no-empty-function - logger: () => {}, -}) - -describe('Automate', () => { - describe('instance', () => { - it('should be an instance of Automate', (done) => { - assert(cwa instanceof AutomateAPI) - done() - }) - - it('should have AVTemplatePoliciesAPI', (done) => { - assert(cwa.AVTemplatePoliciesAPI) - done() - }) - it('should have ClientsAPI', (done) => { - assert(cwa.ClientsAPI) - done() - }) - it('should have CommandsAPI', (done) => { - assert(cwa.CommandsAPI) - done() - }) - it('should have ComputersAPI', (done) => { - assert(cwa.ComputersAPI) - done() - }) - it('should have ContactsAPI', (done) => { - assert(cwa.ContactsAPI) - done() - }) - it('should have DataViewsAPI', (done) => { - assert(cwa.DataViewsAPI) - done() - }) - it('should have DrivesAPI', (done) => { - assert(cwa.DrivesAPI) - done() - }) - it('should have EventLogsAPI', (done) => { - assert(cwa.EventLogsAPI) - done() - }) - it('should have LocationsAPI', (done) => { - assert(cwa.LocationsAPI) - done() - }) - it('should have MaintenanceWindowDefinitionsAPI', (done) => { - assert(cwa.MaintenanceWindowDefinitionsAPI) - done() - }) - it('should have MonitorsAPI', (done) => { - assert(cwa.MonitorsAPI) - done() - }) - it('should have NetworkDevicesAPI', (done) => { - assert(cwa.NetworkDevicesAPI) - done() - }) - it('should have PatchingAPI', (done) => { - assert(cwa.PatchingAPI) - done() - }) - it('should have RemoteAgentAPI', (done) => { - assert(cwa.RemoteAgentAPI) - done() - }) - it('should have ScriptingAPI', (done) => { - assert(cwa.ScriptingAPI) - done() - }) - it('should have SearchesAPI', (done) => { - assert(cwa.SearchesAPI) - done() - }) - it('should have SystemAPI', (done) => { - assert(cwa.SystemAPI) - done() - }) - it('should have TicketsAPI', (done) => { - assert(cwa.TicketsAPI) - done() - }) - it('should have UserProfilesAPI', (done) => { - assert(cwa.UserProfilesAPI) - done() - }) - }) - - describe('ComputersAPI', () => { - it('should return a list of computers', (done) => { - cwa.ComputersAPI.getComputerList({ pageSize: 1 }) - .then((results) => { - assert(results.length === 1) - const computer = results[0] - assert(computer.Id) - assert(computer.ComputerName) - done() - }) - .catch((error) => done(error)) - }) - }) -}) - describe('Manage', () => { describe('instance', () => { it('should be an instance of Manage', (done) => { @@ -278,10 +165,12 @@ describe('Manage', () => { cwm .paginate(cwm.CompanyAPI.getCompanyCommunicationTypes, { pageSize: 2, startPage: 1 }, {}) .then((pagedResults) => { - return cwm.CompanyAPI.getCompanyCommunicationTypes().then((unPagedResults) => { - assert(unPagedResults.length === pagedResults.length) - done() - }) + return cwm.CompanyAPI.getCompanyCommunicationTypes({ pageSize: 50 }).then( + (unPagedResults) => { + assert(unPagedResults.length === pagedResults.length) + done() + }, + ) }) .catch((err) => done(err)) })