import { test } from "node:test";
import assert from "node:assert";
import { NixOSClient } from "./nixos-client.ts";
test("NixOSClient - searchOptions with 'nginx' query", async () => {
const client = new NixOSClient();
try {
const result = await client.searchOptions("nginx", 0, 5);
// Verify structure
assert(typeof result === "object", "Result should be an object");
assert(Array.isArray(result.options), "options should be an array");
assert(typeof result.total === "number", "total should be a number");
// Verify results
assert(result.total > 0, "Should find nginx-related options");
assert(
result.options.length > 0,
"Should return at least one option"
);
// Verify option structure
const firstOption = result.options[0];
assert(
typeof firstOption.option_name === "string",
"option_name should be a string"
);
assert(
typeof firstOption.option_description === "string",
"option_description should be a string"
);
console.log(`✅ Found ${result.total} total results, returned ${result.options.length} options`);
console.log(`First result: ${firstOption.option_name}`);
console.log(`Description: ${firstOption.option_description.substring(0, 100)}...`);
} catch (error) {
console.error("❌ Test failed:", error instanceof Error ? error.message : error);
throw error;
}
});
test("NixOSClient - searchOptions with pagination", async () => {
const client = new NixOSClient();
try {
const result1 = await client.searchOptions("services", 0, 3);
const result2 = await client.searchOptions("services", 3, 3);
assert(
result1.options.length > 0,
"First page should have results"
);
assert(
result1.options[0].option_name !== result2.options[0].option_name,
"Different pages should have different results"
);
console.log("✅ Pagination works correctly");
} catch (error) {
console.error("❌ Pagination test failed:", error instanceof Error ? error.message : error);
throw error;
}
});
test("NixOSClient - searchOptions with multi-word query", async () => {
const client = new NixOSClient();
try {
const result = await client.searchOptions("firewall networking", 0, 10);
assert(
result.options.length > 0,
"Should find results for multi-word query"
);
assert(
result.total > 0,
"Total should be greater than 0"
);
console.log(`✅ Multi-word search found ${result.total} results`);
console.log(`Sample results: ${result.options.slice(0, 3).map((o) => o.option_name).join(", ")}`);
} catch (error) {
console.error("❌ Multi-word test failed:", error instanceof Error ? error.message : error);
throw error;
}
});
test("NixOSClient - searchPackages with 'exactaudiocopy' query", async () => {
const client = new NixOSClient();
try {
const result = await client.searchPackages("exactaudiocopy", 0, 5);
// Verify structure
assert(typeof result === "object", "Result should be an object");
assert(Array.isArray(result.packages), "packages should be an array");
assert(typeof result.total === "number", "total should be a number");
// Verify results
assert(result.total > 0, "Should find exactaudiocopy package");
assert(
result.packages.length > 0,
"Should return at least one package"
);
// Verify package structure
const firstPackage = result.packages[0];
assert(
typeof firstPackage.package_attr_name === "string",
"package_attr_name should be a string"
);
assert(
typeof firstPackage.package_description === "string",
"package_description should be a string"
);
assert(
typeof firstPackage.package_pversion === "string",
"package_pversion should be a string"
);
console.log(`✅ Found ${result.total} total results, returned ${result.packages.length} packages`);
console.log(`First result: ${firstPackage.package_attr_name} v${firstPackage.package_pversion}`);
console.log(`Description: ${firstPackage.package_description.substring(0, 100)}...`);
} catch (error) {
console.error("❌ Test failed:", error instanceof Error ? error.message : error);
throw error;
}
});
test("NixOSClient - searchPackages with pagination", async () => {
const client = new NixOSClient();
try {
const result1 = await client.searchPackages("python", 0, 3);
const result2 = await client.searchPackages("python", 3, 3);
assert(
result1.packages.length > 0,
"First page should have results"
);
assert(
result1.packages[0].package_attr_name !== result2.packages[0].package_attr_name,
"Different pages should have different results"
);
console.log("✅ Package pagination works correctly");
} catch (error) {
console.error("❌ Package pagination test failed:", error instanceof Error ? error.message : error);
throw error;
}
});