mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 15:15:24 +00:00
feat(snippets): bring back sharing, target hosts and drag reorder
This commit is contained in:
1 parent
796db8f0a8
commit
1fd89acd90
16 files changed
+1376
-53
No files matched your search
@@ -30,6 +30,8 @@ export async function startServer(
|
||||
permissions?: string[];
|
||||
users?: string[];
|
||||
capabilities?: string[];
|
||||
shareableUsers?: { id: string; username: string }[];
|
||||
shareableRoles?: { id: number; name: string; displayName: string }[];
|
||||
} = {},
|
||||
): Promise<TestServer> {
|
||||
const db = await createTestDb(pluginDir);
|
||||
@@ -45,6 +47,8 @@ export async function startServer(
|
||||
manifest,
|
||||
capabilities: options.capabilities ?? manifest.capabilities,
|
||||
db: db.database,
|
||||
shareableUsers: options.shareableUsers,
|
||||
shareableRoles: options.shareableRoles,
|
||||
router: () => (router = express.Router()),
|
||||
permissions: options.permissions ?? [
|
||||
"snippets.view",
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { manifest, startServer, type TestServer } from "./helpers";
|
||||
|
||||
let server: TestServer | null = null;
|
||||
|
||||
afterEach(async () => {
|
||||
await server?.close();
|
||||
server = null;
|
||||
});
|
||||
|
||||
describe("share target routes", () => {
|
||||
it("lists users and roles to share with", async () => {
|
||||
server = await startServer({
|
||||
shareableUsers: [{ id: "user-2", username: "bob" }],
|
||||
shareableRoles: [{ id: 3, name: "ops", displayName: "Ops" }],
|
||||
});
|
||||
const users = await server.request("GET", "/share-targets/users");
|
||||
expect(users.status).toBe(200);
|
||||
expect(users.body).toEqual({ users: [{ id: "user-2", username: "bob" }] });
|
||||
|
||||
const roles = await server.request("GET", "/share-targets/roles");
|
||||
expect(roles.status).toBe(200);
|
||||
expect(roles.body).toEqual({
|
||||
roles: [{ id: 3, name: "ops", displayName: "Ops" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("needs the share permission", async () => {
|
||||
server = await startServer({ permissions: ["snippets.view"] });
|
||||
expect((await server.request("GET", "/share-targets/users")).status).toBe(
|
||||
403,
|
||||
);
|
||||
});
|
||||
|
||||
it("fails without the hosts:write capability", async () => {
|
||||
server = await startServer({
|
||||
capabilities: manifest.capabilities.filter((c) => c !== "hosts:write"),
|
||||
});
|
||||
expect((await server.request("GET", "/share-targets/roles")).status).toBe(
|
||||
500,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user