2025-04-28 12:04:08 +00:00
|
|
|
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
2022-03-24 23:11:53 +01:00
|
|
|
import * as smartnetwork from '../ts/index.js';
|
2017-12-12 23:35:20 +01:00
|
|
|
|
2018-07-17 09:00:27 +02:00
|
|
|
let testSmartNetwork: smartnetwork.SmartNetwork;
|
2017-12-12 23:35:20 +01:00
|
|
|
|
|
|
|
tap.test('should create a valid instance of SmartNetwork', async () => {
|
2018-07-17 09:00:27 +02:00
|
|
|
testSmartNetwork = new smartnetwork.SmartNetwork();
|
2022-02-16 23:28:12 +01:00
|
|
|
expect(testSmartNetwork).toBeInstanceOf(smartnetwork.SmartNetwork);
|
2018-07-17 09:00:27 +02:00
|
|
|
});
|
2017-12-12 23:35:20 +01:00
|
|
|
|
|
|
|
tap.test('should perform a speedtest', async () => {
|
2021-04-13 10:09:39 +00:00
|
|
|
const result = await testSmartNetwork.getSpeed();
|
2021-04-28 14:27:22 +00:00
|
|
|
console.log(`Download speed for this instance is ${result.downloadSpeed}`);
|
|
|
|
console.log(`Upload speed for this instance is ${result.uploadSpeed}`);
|
2025-04-28 19:27:13 +00:00
|
|
|
// verify speeds are returned as strings and parse to positive numbers
|
|
|
|
expect(typeof result.downloadSpeed).toEqual('string');
|
|
|
|
expect(typeof result.uploadSpeed).toEqual('string');
|
|
|
|
expect(parseFloat(result.downloadSpeed)).toBeGreaterThan(0);
|
|
|
|
expect(parseFloat(result.uploadSpeed)).toBeGreaterThan(0);
|
2018-07-17 09:00:27 +02:00
|
|
|
});
|
2017-12-12 23:35:20 +01:00
|
|
|
|
2018-07-17 09:00:27 +02:00
|
|
|
tap.test('should determine wether a port is free', async () => {
|
2022-02-16 23:28:12 +01:00
|
|
|
await expectAsync(testSmartNetwork.isLocalPortUnused(8080)).toBeTrue();
|
2018-07-17 09:00:27 +02:00
|
|
|
});
|
|
|
|
|
2019-04-16 10:21:11 +02:00
|
|
|
tap.test('should scan a port', async () => {
|
2022-02-16 23:28:12 +01:00
|
|
|
await expectAsync(testSmartNetwork.isRemotePortAvailable('lossless.com:443')).toBeTrue();
|
|
|
|
await expectAsync(testSmartNetwork.isRemotePortAvailable('lossless.com', 443)).toBeTrue();
|
|
|
|
await expectAsync(testSmartNetwork.isRemotePortAvailable('lossless.com:444')).toBeFalse();
|
2019-04-16 10:21:11 +02:00
|
|
|
});
|
|
|
|
|
2019-09-08 16:15:10 +02:00
|
|
|
tap.test('should get gateways', async () => {
|
2025-04-28 19:27:13 +00:00
|
|
|
const gateways = await testSmartNetwork.getGateways();
|
|
|
|
console.log(gateways);
|
|
|
|
// verify gateways object has at least one interface
|
|
|
|
expect(typeof gateways).toEqual('object');
|
|
|
|
expect(Object.keys(gateways).length).toBeGreaterThan(0);
|
2019-09-06 18:28:39 +02:00
|
|
|
});
|
2019-09-06 18:26:32 +02:00
|
|
|
|
2019-09-08 16:15:10 +02:00
|
|
|
tap.test('should get the default gateway', async () => {
|
2025-04-28 19:27:13 +00:00
|
|
|
const defaultGw = await testSmartNetwork.getDefaultGateway();
|
|
|
|
console.log(defaultGw);
|
|
|
|
// verify default gateway contains ipv4 and ipv6 info
|
|
|
|
expect(defaultGw).toBeDefined();
|
|
|
|
expect(defaultGw.ipv4).toBeDefined();
|
|
|
|
expect(defaultGw.ipv6).toBeDefined();
|
2019-09-08 16:15:10 +02:00
|
|
|
});
|
|
|
|
|
2019-11-23 16:07:04 +00:00
|
|
|
tap.test('should get public ips', async () => {
|
|
|
|
const ips = await testSmartNetwork.getPublicIps();
|
|
|
|
console.log(ips);
|
2025-04-28 19:27:13 +00:00
|
|
|
// verify public IPs object contains v4 and v6 properties
|
|
|
|
expect(ips).toHaveProperty('v4');
|
|
|
|
expect(ips).toHaveProperty('v6');
|
2019-11-23 16:07:04 +00:00
|
|
|
});
|
|
|
|
|
2018-07-17 09:00:27 +02:00
|
|
|
tap.start();
|