mirror of
https://github.com/Xevion/rdap.git
synced 2025-12-13 20:12:39 -06:00
Major restructuring to improve codebase organization: - Moved test files to src/__tests__/ directory - Reorganized UI components from src/components/common to src/components/ui - Consolidated RDAP-related code into src/rdap/ directory structure - Split network helpers into modular files (asn.ts, ipv4.ts, ipv6.ts) - Created centralized exports via src/lib/network/index.ts - Migrated utility functions from src/helpers.ts to src/lib/utils.ts - Separated RDAP services into dedicated modules (rdap-api.ts, registry.ts, url-resolver.ts) This refactoring enhances code maintainability and follows a clearer separation of concerns.
54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, it, expect } from "vitest";
|
|
import { getType } from "@/rdap/utils";
|
|
import type { Register, RootRegistryType } from "@/rdap/schemas";
|
|
import { registryURLs } from "@/rdap/constants";
|
|
|
|
// Integration tests that fetch real IANA bootstrap data
|
|
// These are slower but test against actual registries
|
|
// Note: Uses Node.js environment instead of happy-dom to allow real network requests
|
|
|
|
const registryCache = new Map<RootRegistryType, Register>();
|
|
|
|
async function getRealRegistry(type: RootRegistryType): Promise<Register> {
|
|
if (registryCache.has(type)) {
|
|
return registryCache.get(type)!;
|
|
}
|
|
|
|
const response = await fetch(registryURLs[type]);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch ${type} registry: ${response.statusText}`);
|
|
}
|
|
|
|
const data = (await response.json()) as Register;
|
|
registryCache.set(type, data);
|
|
return data;
|
|
}
|
|
|
|
describe("getType - Integration tests with real registries", () => {
|
|
it("should detect entity with real entity registry", async () => {
|
|
// Test with a known entity tag (RIPE)
|
|
const result = await getType("TEST-RIPE", getRealRegistry);
|
|
expect(result.isOk).toBe(true);
|
|
if (result.isOk) {
|
|
expect(result.value).toBe("entity");
|
|
}
|
|
}, 10000); // Longer timeout for network call
|
|
|
|
it("should detect entity with ARIN tag", async () => {
|
|
const result = await getType("NET-ARIN", getRealRegistry);
|
|
expect(result.isOk).toBe(true);
|
|
if (result.isOk) {
|
|
expect(result.value).toBe("entity");
|
|
}
|
|
}, 10000);
|
|
|
|
it("should not detect invalid entity tag", async () => {
|
|
const result = await getType("INVALID-NOTREAL", getRealRegistry);
|
|
// Should either error or detect as something else, but not entity
|
|
if (result.isOk) {
|
|
expect(result.value).not.toBe("entity");
|
|
}
|
|
}, 10000);
|
|
});
|