mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-30 23:25:24 +00:00
This commit is contained in:
1 parent
87cc80b291
commit
25816084aa
28 files changed
+1797
-49
No files matched your search
@@ -21,8 +21,9 @@ vi.mock("../../../utils/system-crypto.js", () => ({
|
||||
|
||||
const { TestSqliteDatabase } =
|
||||
await import("../../database/repositories/test-support.js");
|
||||
const { createLink, deleteLink, getLink, updateLink } =
|
||||
const { createLink, deleteLink, getLink, listLinks, updateLink } =
|
||||
await import("../../../sync/client/link-store.js");
|
||||
const { setActiveUserId } = await import("../../../sync/accounts.js");
|
||||
|
||||
let db: InstanceType<typeof TestSqliteDatabase>;
|
||||
|
||||
@@ -96,3 +97,79 @@ describe("the desktop's link", () => {
|
||||
expect(await updateLink({ cursor: 1 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("several links", () => {
|
||||
beforeEach(async () => {
|
||||
await db.run(sql`UPDATE users SET is_admin = 1 WHERE id = 'local'`);
|
||||
await db.run(
|
||||
sql`INSERT INTO users (id, username, password_hash) VALUES ('second', 'second', '')`,
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps one link per local user", async () => {
|
||||
await createLink({
|
||||
userId: "local",
|
||||
serverUrl: "https://a",
|
||||
sessionToken: "a",
|
||||
});
|
||||
await createLink({
|
||||
userId: "second",
|
||||
serverUrl: "https://b",
|
||||
sessionToken: "b",
|
||||
});
|
||||
expect((await listLinks()).map((link) => link.serverUrl).sort()).toEqual([
|
||||
"https://a",
|
||||
"https://b",
|
||||
]);
|
||||
expect((await getLink("second"))?.serverUrl).toBe("https://b");
|
||||
expect((await getLink("local"))?.serverUrl).toBe("https://a");
|
||||
});
|
||||
|
||||
it("answers for the active account when no user is given", async () => {
|
||||
await createLink({
|
||||
userId: "local",
|
||||
serverUrl: "https://a",
|
||||
sessionToken: "a",
|
||||
});
|
||||
await createLink({
|
||||
userId: "second",
|
||||
serverUrl: "https://b",
|
||||
sessionToken: "b",
|
||||
});
|
||||
expect((await getLink())?.serverUrl).toBe("https://a");
|
||||
await setActiveUserId("second");
|
||||
expect((await getLink())?.serverUrl).toBe("https://b");
|
||||
});
|
||||
|
||||
it("changes and removes only the link it is asked about", async () => {
|
||||
await createLink({
|
||||
userId: "local",
|
||||
serverUrl: "https://a",
|
||||
sessionToken: "a",
|
||||
});
|
||||
await createLink({
|
||||
userId: "second",
|
||||
serverUrl: "https://b",
|
||||
sessionToken: "b",
|
||||
});
|
||||
await updateLink({ cursor: 9, status: "offline" }, "second");
|
||||
expect((await getLink("local"))?.cursor).toBe(0);
|
||||
expect((await getLink("second"))?.cursor).toBe(9);
|
||||
await deleteLink("second");
|
||||
expect(await getLink("second")).toBeNull();
|
||||
expect((await getLink("local"))?.serverUrl).toBe("https://a");
|
||||
});
|
||||
|
||||
it("stores connection options without touching the type switches", async () => {
|
||||
await createLink({
|
||||
userId: "local",
|
||||
serverUrl: "https://a",
|
||||
sessionToken: "a",
|
||||
});
|
||||
await updateLink({ disabledTypes: ["hosts"] }, "local");
|
||||
await updateLink({ options: { clientCertificate: "work" } }, "local");
|
||||
const link = await getLink("local");
|
||||
expect(link?.options).toEqual({ clientCertificate: "work" });
|
||||
expect(link?.disabledTypes).toEqual(["hosts"]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user