Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
k-grube committed Feb 29, 2024
1 parent 0cd2b40 commit c636249
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
120 changes: 120 additions & 0 deletions test/test-automate.js
Original file line number Diff line number Diff line change
@@ -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))
})
})
})
125 changes: 7 additions & 118 deletions test/test.js → test/test-manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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({
Expand All @@ -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) => {
Expand Down Expand Up @@ -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))
})
Expand Down

0 comments on commit c636249

Please sign in to comment.