@heyputer/shell 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-build.yml +0 -2
- package/.github/workflows/npm-publish.yml +0 -4
- package/bin/index.js +22 -202
- package/package.json +3 -5
- package/src/commands/auth.js +7 -12
- package/src/commands/files.js +16 -18
- package/src/commands/shell.js +5 -3
- package/src/commons.js +81 -256
- package/src/executor.js +12 -129
- package/src/modules/ErrorModule.js +62 -1
- package/src/modules/ProfileModule.js +154 -38
- package/src/utils.js +0 -91
- package/tests/ErrorModule.test.js +73 -1
- package/tests/ProfileModule.test.js +58 -44
- package/tests/commons.test.js +66 -124
- package/tests/executor.test.js +8 -0
- package/tests/files.test.js +23 -3
- package/tests/shell.test.js +2 -1
- package/tests/utils.test.js +1 -141
- package/src/commands/apps.js +0 -356
- package/src/commands/deploy.js +0 -54
- package/src/commands/init.js +0 -322
- package/src/commands/sites.js +0 -169
- package/src/commands/subdomains.js +0 -95
- package/tests/apps.test.js +0 -194
- package/tests/deploy.test.js +0 -84
- package/tests/sites.test.js +0 -67
- package/tests/subdomains.test.js +0 -90
package/tests/apps.test.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { listApps, appInfo, createApp, updateApp, deleteApp } from '../src/commands/apps.js';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import Table from 'cli-table3';
|
|
5
|
-
import * as PuterModule from '../src/modules/PuterModule.js';
|
|
6
|
-
import * as subdomains from '../src/commands/subdomains.js';
|
|
7
|
-
import * as sites from '../src/commands/sites.js';
|
|
8
|
-
import * as files from '../src/commands/files.js';
|
|
9
|
-
import * as auth from '../src/commands/auth.js';
|
|
10
|
-
import * as commons from '../src/commons.js';
|
|
11
|
-
import * as utils from '../src/utils.js';
|
|
12
|
-
import crypto from '../src/crypto.js';
|
|
13
|
-
|
|
14
|
-
// Mock console to prevent actual logging
|
|
15
|
-
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
16
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
17
|
-
|
|
18
|
-
vi.mock("conf", () => {
|
|
19
|
-
const Conf = vi.fn(() => ({
|
|
20
|
-
get: vi.fn(),
|
|
21
|
-
set: vi.fn(),
|
|
22
|
-
clear: vi.fn(),
|
|
23
|
-
}));
|
|
24
|
-
return { default: Conf };
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Mock dependencies
|
|
28
|
-
vi.mock('chalk', () => ({
|
|
29
|
-
default: {
|
|
30
|
-
green: vi.fn(text => text),
|
|
31
|
-
red: vi.fn(text => text),
|
|
32
|
-
dim: vi.fn(text => text),
|
|
33
|
-
yellow: vi.fn(text => text),
|
|
34
|
-
cyan: vi.fn(text => text),
|
|
35
|
-
cyanBright: vi.fn(text => text),
|
|
36
|
-
bold: vi.fn(text => text),
|
|
37
|
-
}
|
|
38
|
-
}));
|
|
39
|
-
vi.mock('cli-table3');
|
|
40
|
-
vi.mock('node-fetch');
|
|
41
|
-
vi.mock('../src/modules/PuterModule.js');
|
|
42
|
-
vi.mock('../src/commands/subdomains.js');
|
|
43
|
-
vi.mock('../src/commands/sites.js');
|
|
44
|
-
vi.mock('../src/commands/files.js');
|
|
45
|
-
vi.mock('../src/commands/auth.js');
|
|
46
|
-
vi.mock('../src/commons.js');
|
|
47
|
-
vi.mock('../src/utils.js');
|
|
48
|
-
vi.mock('../src/crypto.js');
|
|
49
|
-
|
|
50
|
-
const mockPuter = {
|
|
51
|
-
apps: {
|
|
52
|
-
list: vi.fn(),
|
|
53
|
-
get: vi.fn(),
|
|
54
|
-
create: vi.fn(),
|
|
55
|
-
update: vi.fn(),
|
|
56
|
-
delete: vi.fn(),
|
|
57
|
-
},
|
|
58
|
-
fs: {
|
|
59
|
-
mkdir: vi.fn(),
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
describe('apps.js', () => {
|
|
64
|
-
let mockTable;
|
|
65
|
-
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
vi.clearAllMocks();
|
|
68
|
-
vi.spyOn(PuterModule, 'getPuter').mockReturnValue(mockPuter);
|
|
69
|
-
vi.spyOn(auth, 'getCurrentDirectory').mockReturnValue('/testuser');
|
|
70
|
-
vi.spyOn(commons, 'isValidAppName').mockReturnValue(true);
|
|
71
|
-
vi.spyOn(commons, 'resolvePath').mockImplementation((_, newPath) => newPath);
|
|
72
|
-
vi.spyOn(crypto, 'randomUUID').mockReturnValue('mock-uuid');
|
|
73
|
-
|
|
74
|
-
mockTable = {
|
|
75
|
-
push: vi.fn(),
|
|
76
|
-
toString: vi.fn(() => 'table string'),
|
|
77
|
-
};
|
|
78
|
-
Table.mockImplementation(() => mockTable);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('listApps', () => {
|
|
82
|
-
it('should list apps successfully', async () => {
|
|
83
|
-
const mockApps = [
|
|
84
|
-
{ title: 'App 1', name: 'app-1', created_at: new Date().toISOString(), index_url: 'https://app-1.puter.site', stats: { open_count: 10, user_count: 5 } },
|
|
85
|
-
{ title: 'App 2', name: 'app-2', created_at: new Date().toISOString(), index_url: 'https://app-2.puter.site', stats: { open_count: 20, user_count: 15 } },
|
|
86
|
-
];
|
|
87
|
-
mockPuter.apps.list.mockResolvedValue(mockApps);
|
|
88
|
-
vi.spyOn(utils, 'formatDate').mockReturnValue('formatted-date');
|
|
89
|
-
|
|
90
|
-
await listApps();
|
|
91
|
-
|
|
92
|
-
expect(mockPuter.apps.list).toHaveBeenCalled();
|
|
93
|
-
expect(mockTable.push).toHaveBeenCalledTimes(2);
|
|
94
|
-
expect(console.log).toHaveBeenCalledWith('table string');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should handle API error when listing apps', async () => {
|
|
98
|
-
mockPuter.apps.list.mockRejectedValue(new Error('API Error'));
|
|
99
|
-
await listApps();
|
|
100
|
-
expect(console.error).toHaveBeenCalledWith('Failed to list apps. Error: API Error');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('appInfo', () => {
|
|
105
|
-
it('should show app info successfully', async () => {
|
|
106
|
-
const mockApp = { name: 'test-app', title: 'Test App' };
|
|
107
|
-
mockPuter.apps.get.mockResolvedValue(mockApp);
|
|
108
|
-
vi.spyOn(utils, 'displayNonNullValues').mockImplementation(() => {});
|
|
109
|
-
|
|
110
|
-
await appInfo(['test-app']);
|
|
111
|
-
|
|
112
|
-
expect(mockPuter.apps.get).toHaveBeenCalledWith('test-app');
|
|
113
|
-
expect(utils.displayNonNullValues).toHaveBeenCalledWith(mockApp);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should show usage if no app name is provided', async () => {
|
|
117
|
-
await appInfo([]);
|
|
118
|
-
expect(console.log).toHaveBeenCalledWith(chalk.red('Usage: app <name>'));
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('should handle app not found', async () => {
|
|
122
|
-
mockPuter.apps.get.mockResolvedValue(null);
|
|
123
|
-
await appInfo(['non-existent-app']);
|
|
124
|
-
expect(console.error).toHaveBeenCalledWith(chalk.red('Could not find this app.'));
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe('createApp', () => {
|
|
129
|
-
beforeEach(() => {
|
|
130
|
-
mockPuter.apps.create.mockResolvedValue({ uid: 'app-uid', name: 'new-app', owner: { username: 'testuser' } });
|
|
131
|
-
mockPuter.fs.mkdir.mockResolvedValue({ uid: 'dir-uid', name: 'app-mock-uuid' });
|
|
132
|
-
vi.spyOn(subdomains, 'createSubdomain').mockResolvedValue(true);
|
|
133
|
-
vi.spyOn(files, 'createFile').mockResolvedValue(true);
|
|
134
|
-
mockPuter.apps.update.mockResolvedValue(true);
|
|
135
|
-
})
|
|
136
|
-
it('should create an app successfully', async () => {
|
|
137
|
-
await createApp({ name: 'new-app' });
|
|
138
|
-
|
|
139
|
-
expect(mockPuter.apps.create).toHaveBeenCalled();
|
|
140
|
-
expect(mockPuter.fs.mkdir).toHaveBeenCalled();
|
|
141
|
-
expect(subdomains.createSubdomain).toHaveBeenCalled();
|
|
142
|
-
expect(files.createFile).toHaveBeenCalled();
|
|
143
|
-
expect(mockPuter.apps.update).toHaveBeenCalled();
|
|
144
|
-
expect(console.log).toHaveBeenCalledWith(chalk.green('App deployed successfully at:'));
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('should show usage if app name is invalid', async () => {
|
|
148
|
-
vi.spyOn(commons, 'isValidAppName').mockReturnValue(false);
|
|
149
|
-
await createApp({ name: 'invalid-' });
|
|
150
|
-
expect(console.log).toHaveBeenCalledWith(chalk.red('Usage: app:create <name> <directory>'));
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('updateApp', () => {
|
|
155
|
-
it('should update an app successfully', async () => {
|
|
156
|
-
mockPuter.apps.get.mockResolvedValue({ uid: 'app-uid', name: 'test-app', owner: { username: 'testuser' }, index_url: 'https://test.puter.site' });
|
|
157
|
-
vi.spyOn(files, 'pathExists').mockResolvedValue(true);
|
|
158
|
-
vi.spyOn(subdomains, 'getSubdomains').mockResolvedValue([{ root_dir: { dirname: 'app-uid', path: '/path/to/app' }, uid: 'sub-uid' }]);
|
|
159
|
-
vi.spyOn(files, 'listRemoteFiles').mockResolvedValue([{ name: 'index.html' }]);
|
|
160
|
-
vi.spyOn(files, 'copyFile').mockResolvedValue(true);
|
|
161
|
-
vi.spyOn(files, 'removeFileOrDirectory').mockResolvedValue(true);
|
|
162
|
-
|
|
163
|
-
await updateApp(['test-app', '.']);
|
|
164
|
-
|
|
165
|
-
expect(mockPuter.apps.get).toHaveBeenCalledWith('test-app');
|
|
166
|
-
expect(files.listRemoteFiles).toHaveBeenCalled();
|
|
167
|
-
expect(files.copyFile).toHaveBeenCalled();
|
|
168
|
-
expect(console.log).toHaveBeenCalledWith(chalk.green('App updated successfully at:'));
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
describe('deleteApp', () => {
|
|
173
|
-
it('should delete an app successfully', async () => {
|
|
174
|
-
mockPuter.apps.get.mockResolvedValue({ uid: 'app-uid', name: 'test-app', title: 'Test App', created_at: new Date().toISOString() });
|
|
175
|
-
mockPuter.apps.delete.mockResolvedValue(true);
|
|
176
|
-
vi.spyOn(subdomains, 'getSubdomains').mockResolvedValue([{ root_dir: { dirname: 'app-uid' }, uid: 'sub-uid' }]);
|
|
177
|
-
vi.spyOn(sites, 'deleteSite').mockResolvedValue(true);
|
|
178
|
-
|
|
179
|
-
const result = await deleteApp('test-app');
|
|
180
|
-
|
|
181
|
-
expect(result).toBe(true);
|
|
182
|
-
expect(mockPuter.apps.delete).toHaveBeenCalledWith('test-app');
|
|
183
|
-
expect(sites.deleteSite).toHaveBeenCalled();
|
|
184
|
-
expect(console.log).toHaveBeenCalledWith(chalk.green('App "test-app" deleted successfully!'));
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('should return false if app not found', async () => {
|
|
188
|
-
mockPuter.apps.get.mockResolvedValue(null);
|
|
189
|
-
const result = await deleteApp('non-existent-app');
|
|
190
|
-
expect(result).toBe(false);
|
|
191
|
-
expect(console.log).toHaveBeenCalledWith(chalk.red('App "non-existent-app" not found.'));
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
package/tests/deploy.test.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { describe, vi, expect, it, beforeEach } from "vitest";
|
|
2
|
-
|
|
3
|
-
vi.mock('conf', () => ({
|
|
4
|
-
default: vi.fn(() => ({
|
|
5
|
-
get: vi.fn(),
|
|
6
|
-
})),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
vi.mock("../src/commands/files");
|
|
10
|
-
vi.mock("../src/commands/sites");
|
|
11
|
-
vi.mock("../src/modules/PuterModule");
|
|
12
|
-
|
|
13
|
-
vi.spyOn(console, "log").mockImplementation(() => { });
|
|
14
|
-
|
|
15
|
-
let deploy;
|
|
16
|
-
let syncDirectory;
|
|
17
|
-
let createSite;
|
|
18
|
-
let getPuter;
|
|
19
|
-
|
|
20
|
-
beforeEach(async () => {
|
|
21
|
-
vi.resetModules();
|
|
22
|
-
vi.clearAllMocks();
|
|
23
|
-
|
|
24
|
-
const deployModule = await import("../src/commands/deploy");
|
|
25
|
-
deploy = deployModule.deploy;
|
|
26
|
-
|
|
27
|
-
const filesModule = await import("../src/commands/files");
|
|
28
|
-
syncDirectory = vi.mocked(filesModule.syncDirectory);
|
|
29
|
-
|
|
30
|
-
const sitesModule = await import("../src/commands/sites");
|
|
31
|
-
createSite = vi.mocked(sitesModule.createSite);
|
|
32
|
-
|
|
33
|
-
const puterModule = await import("../src/modules/PuterModule");
|
|
34
|
-
getPuter = vi.mocked(puterModule.getPuter);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe("deploy", () => {
|
|
38
|
-
it("should show usage when no args provided", async () => {
|
|
39
|
-
await deploy([]);
|
|
40
|
-
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Usage:"));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should deploy successfully", async () => {
|
|
44
|
-
const mockMkdir = vi.fn().mockResolvedValue({
|
|
45
|
-
path: "~/sites/test-app/deployment"
|
|
46
|
-
});
|
|
47
|
-
getPuter.mockReturnValue({
|
|
48
|
-
fs: {
|
|
49
|
-
mkdir: mockMkdir
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
syncDirectory.mockResolvedValue();
|
|
53
|
-
createSite.mockResolvedValue({
|
|
54
|
-
subdomain: "test-app.puter.site"
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
await deploy(["./dist", "--subdomain=test-app"]);
|
|
58
|
-
|
|
59
|
-
expect(mockMkdir).toHaveBeenCalledWith("~/sites/test-app/deployment", {
|
|
60
|
-
dedupeName: true,
|
|
61
|
-
createMissingParents: true
|
|
62
|
-
});
|
|
63
|
-
expect(syncDirectory).toHaveBeenCalled();
|
|
64
|
-
expect(createSite).toHaveBeenCalled();
|
|
65
|
-
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Deployment successful!"));
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should show updated message when site already exists", async () => {
|
|
69
|
-
const mockMkdir = vi.fn().mockResolvedValue({
|
|
70
|
-
path: "~/sites/test-app/deployment"
|
|
71
|
-
});
|
|
72
|
-
getPuter.mockReturnValue({
|
|
73
|
-
fs: {
|
|
74
|
-
mkdir: mockMkdir
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
syncDirectory.mockResolvedValue();
|
|
78
|
-
createSite.mockResolvedValue(null);
|
|
79
|
-
|
|
80
|
-
await deploy(["./dist", "--subdomain=test-app"]);
|
|
81
|
-
|
|
82
|
-
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Deployment successfuly updated!"));
|
|
83
|
-
});
|
|
84
|
-
});
|
package/tests/sites.test.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
})
|
package/tests/subdomains.test.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { vi } from "vitest";
|
|
2
|
-
import { it } from "vitest";
|
|
3
|
-
import { describe } from "vitest";
|
|
4
|
-
import { createSubdomain, deleteSubdomain, getSubdomains, updateSubdomain } from "../src/commands/subdomains";
|
|
5
|
-
import { expect } from "vitest";
|
|
6
|
-
import { getPuter } from "../src/modules/PuterModule";
|
|
7
|
-
|
|
8
|
-
vi.mock("../src/modules/PuterModule")
|
|
9
|
-
vi.mock("conf", () => {
|
|
10
|
-
const Conf = vi.fn(() => ({
|
|
11
|
-
get: vi.fn(),
|
|
12
|
-
set: vi.fn(),
|
|
13
|
-
clear: vi.fn(),
|
|
14
|
-
}));
|
|
15
|
-
return { default: Conf };
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
vi.spyOn(console, "log").mockImplementation(() => { });
|
|
19
|
-
|
|
20
|
-
describe("getSubdomains", () => {
|
|
21
|
-
it("should get subdomains successfully", async () => {
|
|
22
|
-
const mockHostingList = vi.fn().mockResolvedValue([{
|
|
23
|
-
uid: "123",
|
|
24
|
-
subdomain: "hehe.puter.site",
|
|
25
|
-
root_dir: { path: "/some/path" },
|
|
26
|
-
}]);
|
|
27
|
-
vi.mocked(getPuter).mockReturnValue({
|
|
28
|
-
hosting: {
|
|
29
|
-
list: mockHostingList
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
const result = await getSubdomains();
|
|
33
|
-
expect(getPuter).toHaveBeenCalled();
|
|
34
|
-
expect(result).toHaveLength(1)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe("deleteSubdomain", () => {
|
|
39
|
-
it("should delete subdomain successfully", async () => {
|
|
40
|
-
const mockHostingDelete = vi.fn().mockResolvedValue(true);
|
|
41
|
-
vi.mocked(getPuter).mockReturnValue({
|
|
42
|
-
hosting: {
|
|
43
|
-
delete: mockHostingDelete
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
const result = await deleteSubdomain(["hehe.puter.site"]);
|
|
47
|
-
expect(result).toBe(true);
|
|
48
|
-
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("Subdomain deleted successfully"));
|
|
49
|
-
})
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
describe("createSubdomain", () => {
|
|
53
|
-
it("should create subdomain successfully", async () => {
|
|
54
|
-
const mockHostingCreate = vi.fn().mockResolvedValue({
|
|
55
|
-
uid: "123",
|
|
56
|
-
subdomain: "hehe.puter.site",
|
|
57
|
-
root_dir: { path: "/some/path" },
|
|
58
|
-
});
|
|
59
|
-
vi.mocked(getPuter).mockReturnValue({
|
|
60
|
-
hosting: {
|
|
61
|
-
create: mockHostingCreate
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
const result = await createSubdomain("hehe", "/mydir")
|
|
65
|
-
expect(result).toMatchObject({
|
|
66
|
-
subdomain: "hehe.puter.site"
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
describe("updateSubdomain", () => {
|
|
72
|
-
it("should update subdomain successfully", async () => {
|
|
73
|
-
const mockHostingUpdate = vi.fn().mockResolvedValue({
|
|
74
|
-
uid: "123",
|
|
75
|
-
subdomain: "hehe.puter.site",
|
|
76
|
-
root_dir: { path: "/newdir" },
|
|
77
|
-
});
|
|
78
|
-
vi.mocked(getPuter).mockReturnValue({
|
|
79
|
-
hosting: {
|
|
80
|
-
update: mockHostingUpdate
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
const result = await updateSubdomain("hehe", "/newdir")
|
|
84
|
-
expect(result).toMatchObject({
|
|
85
|
-
root_dir: {
|
|
86
|
-
path: "/newdir"
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
})
|