Skip to content

Commit bc4fd18

Browse files
authored
Merge pull request #60 from reynaldichernando/test-sites
Add sites test
2 parents 7cfe967 + d3a4f98 commit bc4fd18

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/sites.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { describe, vi, expect, it } from "vitest";
2+
import { createSite, deleteSite, infoSite, listSites } from "../src/commands/sites";
3+
import { createSubdomain, deleteSubdomain, getSubdomains } from "../src/commands/subdomains";
4+
import { getPuter } from "../src/modules/PuterModule.js";
5+
import { getCurrentDirectory } from "../src/commands/auth.js";
6+
7+
vi.mock("../src/commands/subdomains")
8+
vi.mock("../src/modules/PuterModule")
9+
vi.mock('../src/commands/auth.js');
10+
11+
vi.spyOn(console, "log").mockImplementation(() => { });
12+
13+
describe("listSites", () => {
14+
it("should list sites successfully", async () => {
15+
vi.mocked(getSubdomains).mockResolvedValue([{
16+
uid: "123",
17+
subdomain: "hehe.puter.site",
18+
root_dir: { path: "/some/path" },
19+
}])
20+
await listSites();
21+
expect(getSubdomains).toHaveBeenCalled();
22+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Total Sites: 1"))
23+
})
24+
})
25+
26+
describe("infoSite", () => {
27+
it("should get site info successfully", async () => {
28+
const mockHostingGet = vi.fn().mockResolvedValue({
29+
uid: "123",
30+
subdomain: "hehe.puter.site",
31+
root_dir: { path: "/some/path" },
32+
});
33+
vi.mocked(getPuter).mockReturnValue({
34+
hosting: {
35+
get: mockHostingGet
36+
}
37+
})
38+
39+
await infoSite(["hehe.puter.site"])
40+
expect(getPuter).toHaveBeenCalled();
41+
expect(mockHostingGet).toHaveBeenCalled();
42+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("hehe.puter.site"))
43+
})
44+
})
45+
46+
describe("deleteSite", () => {
47+
it("should delete site successfully", async () => {
48+
vi.mocked(deleteSubdomain)
49+
const result = await deleteSite(["hehe.puter.site"]);
50+
expect(result).toBe(true);
51+
})
52+
})
53+
54+
describe("createSite", () => {
55+
it("should create site successfully", async () => {
56+
vi.mocked(createSubdomain).mockResolvedValue({
57+
uid: "123",
58+
subdomain: "hehe.puter.site",
59+
root_dir: { path: "/some/path" },
60+
})
61+
vi.mocked(getCurrentDirectory).mockReturnValue('/testuser');
62+
const result = await createSite(["hehe hehe --subdomain=hehe"]);
63+
expect(result).toMatchObject({
64+
subdomain: "hehe.puter.site"
65+
})
66+
})
67+
})

0 commit comments

Comments
 (0)