mirror of
https://github.com/DeBrosOfficial/network-ts-sdk.git
synced 2025-12-11 01:58:49 +00:00
- Introduced `proxyAnon` method in `NetworkClient` to facilitate anonymous HTTP requests through the Anyone network. - Added `ProxyRequest` and `ProxyResponse` interfaces to define the structure of proxy requests and responses. - Updated README.md with detailed examples on how to use the new proxy functionality, including GET and POST requests. - Enhanced error handling for proxy requests to ensure graceful failure in case of issues.
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { describe, it, expect, beforeAll } from "vitest";
|
|
import { createTestClient, skipIfNoGateway } from "./setup";
|
|
|
|
describe("Network", () => {
|
|
beforeAll(() => {
|
|
if (skipIfNoGateway()) {
|
|
console.log("Skipping network tests");
|
|
}
|
|
});
|
|
|
|
it("should check health", async () => {
|
|
const client = await createTestClient();
|
|
const healthy = await client.network.health();
|
|
expect(typeof healthy).toBe("boolean");
|
|
});
|
|
|
|
it("should get network status", async () => {
|
|
const client = await createTestClient();
|
|
const status = await client.network.status();
|
|
expect(status).toBeDefined();
|
|
expect(typeof status.connected).toBe("boolean");
|
|
expect(typeof status.peer_count).toBe("number");
|
|
});
|
|
|
|
it("should list peers", async () => {
|
|
const client = await createTestClient();
|
|
const peers = await client.network.peers();
|
|
expect(Array.isArray(peers)).toBe(true);
|
|
});
|
|
|
|
it("should proxy request through Anyone network", async () => {
|
|
const client = await createTestClient();
|
|
|
|
// Test with a simple GET request
|
|
const response = await client.network.proxyAnon({
|
|
url: "https://httpbin.org/get",
|
|
method: "GET",
|
|
headers: {
|
|
"User-Agent": "DeBros-SDK-Test/1.0",
|
|
},
|
|
});
|
|
|
|
expect(response).toBeDefined();
|
|
expect(response.status_code).toBe(200);
|
|
expect(response.body).toBeDefined();
|
|
expect(typeof response.body).toBe("string");
|
|
});
|
|
|
|
it("should handle proxy errors gracefully", async () => {
|
|
const client = await createTestClient();
|
|
|
|
// Test with invalid URL
|
|
await expect(
|
|
client.network.proxyAnon({
|
|
url: "http://localhost:1/invalid",
|
|
method: "GET",
|
|
})
|
|
).rejects.toThrow();
|
|
});
|
|
});
|