File size: 1,199 Bytes
0ad74ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import { Client } from "../client";
import { initialise_server } from "./server";
import { BROKEN_CONNECTION_MSG } from "../constants";
const server = initialise_server();
import { beforeAll, afterEach, afterAll, it, expect, describe } from "vitest";
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
describe("post_data", () => {
it("should send a POST request with the correct headers and body", async () => {
const app = await Client.connect("hmb/hello_world");
const config = app.config;
const url = config?.root;
const body = { data: "test" };
if (!url) {
throw new Error("No URL provided");
}
const [response, status] = await app.post_data(url, body);
expect(response).toEqual({});
expect(status).toBe(200);
});
it("should handle network errors", async () => {
const app = await Client.connect("hmb/secret_world", {
hf_token: "hf_123"
});
const url = "https://hmb-secret-world.hf.space";
if (!url) {
throw new Error("No URL provided");
}
const [response, status] = await app.post_data(url, {});
expect(response).toEqual(BROKEN_CONNECTION_MSG);
expect(status).toBe(500);
});
});
|