This commit is contained in:
2025-11-18 20:47:48 +00:00
commit 747fb787e1
38 changed files with 18518 additions and 0 deletions

153
test/test.node+bun+deno.ts Normal file
View File

@@ -0,0 +1,153 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { PeeringDbClient } from '../ts/index.js';
let client: PeeringDbClient;
// Initialize client
tap.test('should create a PeeringDB client instance', async () => {
client = new PeeringDbClient();
expect(client).toBeInstanceOf(PeeringDbClient);
expect(client.networks).toBeDefined();
expect(client.organizations).toBeDefined();
expect(client.facilities).toBeDefined();
expect(client.exchanges).toBeDefined();
});
// Test network queries
tap.test('should fetch networks list', async () => {
const networks = await client.networks.list({ limit: 5 });
expect(Array.isArray(networks)).toEqual(true);
expect(networks.length).toBeGreaterThan(0);
expect(networks.length).toBeLessThanOrEqual(5);
expect(networks[0]).toHaveProperty('id');
expect(networks[0]).toHaveProperty('asn');
expect(networks[0]).toHaveProperty('name');
});
tap.test('should fetch a network by ASN', async () => {
// Google's ASN
const network = await client.networks.getByAsn(15169);
expect(network).toBeDefined();
expect(network?.asn).toEqual(15169);
expect(network?.name).toBeDefined();
});
tap.test('should search networks by name', async () => {
const networks = await client.networks.searchByName('Google', { limit: 5 });
expect(Array.isArray(networks)).toEqual(true);
expect(networks.length).toBeGreaterThan(0);
});
// Test organization queries
tap.test('should fetch organizations list', async () => {
const orgs = await client.organizations.list({ limit: 5 });
expect(Array.isArray(orgs)).toEqual(true);
expect(orgs.length).toBeGreaterThan(0);
expect(orgs[0]).toHaveProperty('id');
expect(orgs[0]).toHaveProperty('name');
});
tap.test('should fetch organization by ID', async () => {
const org = await client.organizations.getById(2);
expect(org).toBeDefined();
expect(org?.id).toEqual(2);
expect(org?.name).toBeDefined();
});
// Test facility queries
tap.test('should fetch facilities list', async () => {
const facilities = await client.facilities.list({ limit: 5 });
expect(Array.isArray(facilities)).toEqual(true);
expect(facilities.length).toBeGreaterThan(0);
expect(facilities[0]).toHaveProperty('id');
expect(facilities[0]).toHaveProperty('name');
expect(facilities[0]).toHaveProperty('city');
});
tap.test('should search facilities by name', async () => {
const facilities = await client.facilities.searchByName('Equinix', { limit: 5 });
expect(Array.isArray(facilities)).toEqual(true);
expect(facilities.length).toBeGreaterThan(0);
});
tap.test('should get facilities by country', async () => {
const facilities = await client.facilities.getByCountry('US', { limit: 5 });
expect(Array.isArray(facilities)).toEqual(true);
expect(facilities.length).toBeGreaterThan(0);
expect(facilities[0].country).toEqual('US');
});
// Test exchange queries
tap.test('should fetch exchanges list', async () => {
const exchanges = await client.exchanges.list({ limit: 5 });
expect(Array.isArray(exchanges)).toEqual(true);
expect(exchanges.length).toBeGreaterThan(0);
expect(exchanges[0]).toHaveProperty('id');
expect(exchanges[0]).toHaveProperty('name');
});
tap.test('should search exchanges by name', async () => {
const exchanges = await client.exchanges.searchByName('AMS-IX', { limit: 5 });
expect(Array.isArray(exchanges)).toEqual(true);
expect(exchanges.length).toBeGreaterThan(0);
});
// Test query parameters
tap.test('should support field selection', async () => {
const networks = await client.networks.list({
limit: 1,
fields: 'id,asn,name',
});
expect(networks.length).toEqual(1);
expect(networks[0]).toHaveProperty('id');
expect(networks[0]).toHaveProperty('asn');
expect(networks[0]).toHaveProperty('name');
});
tap.test('should support depth parameter', async () => {
const network = await client.networks.getByAsn(15169, 2);
expect(network).toBeDefined();
expect(network?.asn).toEqual(15169);
// With depth=2, org should be expanded to full object
if (network?.org) {
expect(typeof network.org).toEqual('object');
}
});
// Test derived objects
tap.test('should fetch network-IX connections', async () => {
const netixlans = await client.netIxLans.list({ limit: 5 });
expect(Array.isArray(netixlans)).toEqual(true);
expect(netixlans.length).toBeGreaterThan(0);
expect(netixlans[0]).toHaveProperty('net_id');
expect(netixlans[0]).toHaveProperty('ixlan_id');
});
tap.test('should fetch network-facility connections', async () => {
const netfacs = await client.netFacs.list({ limit: 5 });
expect(Array.isArray(netfacs)).toEqual(true);
expect(netfacs.length).toBeGreaterThan(0);
expect(netfacs[0]).toHaveProperty('net_id');
expect(netfacs[0]).toHaveProperty('fac_id');
});
// Test convenience methods
tap.test('convenience: should get network by ASN', async () => {
const network = await client.convenience.getNetworkByAsn(15169);
expect(network).toBeDefined();
expect(network?.asn).toEqual(15169);
});
tap.test('convenience: should search networks', async () => {
const networks = await client.convenience.searchNetworks('Google');
expect(Array.isArray(networks)).toEqual(true);
expect(networks.length).toBeGreaterThan(0);
});
tap.test('convenience: should search facilities', async () => {
const facilities = await client.convenience.searchFacilities('Equinix');
expect(Array.isArray(facilities)).toEqual(true);
expect(facilities.length).toBeGreaterThan(0);
});
export default tap.start();