File size: 1,462 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
47
48
49
50
51
52
53
54
import { describe, beforeAll, afterEach, afterAll, test, expect } from "vitest";

import { Client, client, duplicate } from "..";
import { transformed_api_info, config_response } from "./test_data";
import { initialise_server } from "./server";

const app_reference = "hmb/hello_world";
const secret_app_reference = "hmb/secret_world";
const secret_direct_app_reference = "https://hmb-secret-world.hf.space";

const server = initialise_server();

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

describe("view_api", () => {
	test("viewing the api of a running, public app", async () => {
		const app = await Client.connect(app_reference);

		expect(await app.view_api()).toEqual(transformed_api_info);
	});

	test("viewing the api of a running, private app", async () => {
		const app = await Client.connect(secret_app_reference, {
			hf_token: "hf_123"
		});

		expect(app.config).toEqual({
			...config_response,
			root: secret_direct_app_reference
		});

		expect(await app.view_api()).toEqual({
			...transformed_api_info
		});
	});

	test("viewing the api of a running, private app with a direct app URL", async () => {
		const app = await Client.connect(secret_direct_app_reference, {
			hf_token: "hf_123"
		});

		expect(app.config).toEqual({
			...config_response,
			root: secret_direct_app_reference
		});

		expect(await app.view_api()).toEqual({
			...transformed_api_info
		});
	});
});