144 lines
4.5 KiB
TypeScript
144 lines
4.5 KiB
TypeScript
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
|
import { Qenv } from '@push.rocks/qenv';
|
|
import * as unifi from '../ts/index.js';
|
|
|
|
// =============================================================================
|
|
// NETWORK CONTROLLER API INTEGRATION TESTS (Local API)
|
|
// Tests may use live production keys to test specific features at scale.
|
|
// Make sure to avoid dangerous, destructive or security relevant operations.
|
|
// =============================================================================
|
|
|
|
const testQenv = new Qenv('./', './.nogit/');
|
|
|
|
let testController: unifi.UnifiController;
|
|
|
|
tap.test('setup - create UnifiController with API key', async () => {
|
|
const host = await testQenv.getEnvVarOnDemand('UNIFI_CONSOLE_IP');
|
|
const apiKey = await testQenv.getEnvVarOnDemand('UNIFI_NETWORK_DEV_KEY');
|
|
|
|
testController = new unifi.UnifiController({
|
|
host,
|
|
apiKey,
|
|
controllerType: 'unifi-os',
|
|
verifySsl: false,
|
|
});
|
|
|
|
// With API key, already authenticated
|
|
expect(testController.isAuthenticated()).toBeTrue();
|
|
console.log('UnifiController created with API key authentication');
|
|
});
|
|
|
|
// READ-ONLY: List devices
|
|
tap.test('READ-ONLY - should list devices', async () => {
|
|
const devices = await testController.deviceManager.listDevices();
|
|
|
|
console.log(`Found ${devices.length} devices`);
|
|
expect(devices).toBeArray();
|
|
|
|
for (const device of devices) {
|
|
expect(device).toBeInstanceOf(unifi.UnifiDevice);
|
|
console.log(` - ${device.getDisplayName()} (${device.model}) - ${device.isOnline() ? 'online' : 'offline'}`);
|
|
}
|
|
});
|
|
|
|
// READ-ONLY: List access points
|
|
tap.test('READ-ONLY - should list access points', async () => {
|
|
const accessPoints = await testController.deviceManager.getAccessPoints();
|
|
|
|
console.log(`Found ${accessPoints.length} access points`);
|
|
expect(accessPoints).toBeArray();
|
|
|
|
for (const ap of accessPoints) {
|
|
console.log(` - AP: ${ap.getDisplayName()} (${ap.ip})`);
|
|
}
|
|
});
|
|
|
|
// READ-ONLY: List switches
|
|
tap.test('READ-ONLY - should list switches', async () => {
|
|
const switches = await testController.deviceManager.getSwitches();
|
|
|
|
console.log(`Found ${switches.length} switches`);
|
|
expect(switches).toBeArray();
|
|
|
|
for (const sw of switches) {
|
|
console.log(` - Switch: ${sw.getDisplayName()} (${sw.ip})`);
|
|
}
|
|
});
|
|
|
|
// READ-ONLY: List gateways
|
|
tap.test('READ-ONLY - should list gateways', async () => {
|
|
const gateways = await testController.deviceManager.getGateways();
|
|
|
|
console.log(`Found ${gateways.length} gateways`);
|
|
expect(gateways).toBeArray();
|
|
|
|
for (const gw of gateways) {
|
|
console.log(` - Gateway: ${gw.getDisplayName()} (${gw.ip})`);
|
|
}
|
|
});
|
|
|
|
// READ-ONLY: List active clients
|
|
tap.test('READ-ONLY - should list active clients', async () => {
|
|
const clients = await testController.clientManager.listActiveClients();
|
|
|
|
console.log(`Found ${clients.length} active clients`);
|
|
expect(clients).toBeArray();
|
|
|
|
for (const client of clients.slice(0, 10)) {
|
|
console.log(` - ${client.getDisplayName()} (${client.ip || 'no IP'}) - ${client.getConnectionType()}`);
|
|
}
|
|
if (clients.length > 10) {
|
|
console.log(` ... and ${clients.length - 10} more`);
|
|
}
|
|
});
|
|
|
|
// READ-ONLY: List wireless clients
|
|
tap.test('READ-ONLY - should list wireless clients', async () => {
|
|
const wirelessClients = await testController.clientManager.getWirelessClients();
|
|
|
|
console.log(`Found ${wirelessClients.length} wireless clients`);
|
|
expect(wirelessClients).toBeArray();
|
|
});
|
|
|
|
// READ-ONLY: List wired clients
|
|
tap.test('READ-ONLY - should list wired clients', async () => {
|
|
const wiredClients = await testController.clientManager.getWiredClients();
|
|
|
|
console.log(`Found ${wiredClients.length} wired clients`);
|
|
expect(wiredClients).toBeArray();
|
|
});
|
|
|
|
// READ-ONLY: Get system info
|
|
tap.test('READ-ONLY - should get system info', async () => {
|
|
const sysInfo = await testController.getSystemInfo();
|
|
|
|
console.log('System info retrieved');
|
|
expect(sysInfo).toBeDefined();
|
|
});
|
|
|
|
// READ-ONLY: Get health
|
|
tap.test('READ-ONLY - should get health status', async () => {
|
|
const health = await testController.getHealth();
|
|
|
|
console.log('Health status retrieved');
|
|
expect(health).toBeDefined();
|
|
});
|
|
|
|
// READ-ONLY: Get WLANs
|
|
tap.test('READ-ONLY - should list WLANs', async () => {
|
|
const wlans = await testController.getWlans();
|
|
|
|
console.log('WLANs retrieved');
|
|
expect(wlans).toBeDefined();
|
|
});
|
|
|
|
// READ-ONLY: Get networks
|
|
tap.test('READ-ONLY - should list networks', async () => {
|
|
const networks = await testController.getNetworks();
|
|
|
|
console.log('Networks retrieved');
|
|
expect(networks).toBeDefined();
|
|
});
|
|
|
|
export default tap.start();
|