Files
Multi-Debrid-Downloader/tests/account-edit.test.ts
Sucukdeluxe 1b7caba2eb feat: add Deepbrid, daily scheduling, and notification center
Add encrypted Deepbrid API accounts with account validation, provider routing, fallback, usage tracking, safe error handling, and verified 1Fichier downloads. Restore persistent recurring daily starts with local-calendar deduplication and legacy schedule compatibility. Add durable Discord package, run, remaining-volume, stall, and recovery notifications with privacy-safe telemetry and disk-failure recovery.
2026-08-24 07:37:55 +02:00

135 lines
4.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { defaultSettings } from "../src/main/constants";
import { createRendererState } from "../src/main/renderer-state";
import { getMegaDebridAccountId } from "../src/shared/mega-debrid-accounts";
import {
buildAccountDeleteCommand,
buildAccountReplaceCommand,
createAccountEditState,
validateAccountEdit,
type AccountEditTarget
} from "../src/renderer/account-edit";
function megaTarget(identity: string): AccountEditTarget {
const accountId = getMegaDebridAccountId(identity);
return {
type: "mega",
rowKey: `mega-megadebrid-api-${accountId}`,
kind: "megadebrid-api",
service: "megadebrid-api",
accountId
};
}
describe("renderer-safe account editing", () => {
it("targets one concrete Real-Debrid API account for replace and delete", () => {
const settings = defaultSettings();
settings.realDebridApiTokens = JSON.stringify({
version: 1,
accounts: [
{ id: "rda_first", token: "fixture-token-first" },
{ id: "rda_second", token: "fixture-token-second" }
]
});
const renderer = createRendererState(settings);
const target: AccountEditTarget = {
type: "single",
rowKey: "rd-rda_second",
kind: "realdebrid-api",
service: "realdebrid",
provider: "realdebrid",
accountId: "rda_second"
};
const edit = createAccountEditState(target, renderer.accounts);
expect(buildAccountReplaceCommand({ ...edit, token: "replacement-token" })).toEqual(expect.objectContaining({
action: "replace",
kind: "realdebrid-api",
accountId: "rda_second",
secret: "replacement-token"
}));
expect(buildAccountDeleteCommand(target)).toEqual({
action: "delete",
kind: "realdebrid-api",
accountId: "rda_second"
});
});
it("opens an existing account without reading its stored secret", () => {
const identity = "safe-edit@example.test";
const state = createRendererState({
...defaultSettings(),
megaCredentials: `${identity}:fixture-stored-secret-4dH8`,
megaDebridApiCredentials: `${identity}:fixture-stored-secret-4dH8`,
megaDebridApiEnabled: true
});
const edit = createAccountEditState(megaTarget(identity), state.accounts);
expect(edit.login).toBe(identity);
expect(edit.password).toBe("");
expect(JSON.stringify(edit)).not.toContain("fixture-stored-secret-4dH8");
});
it("builds a replace command whose blank secret retains the main-process value", () => {
const identity = "safe-edit@example.test";
const renderer = createRendererState({
...defaultSettings(),
megaCredentials: `${identity}:fixture-stored-secret-4dH8`,
megaDebridApiCredentials: `${identity}:fixture-stored-secret-4dH8`,
megaDebridApiEnabled: true
});
const edit = createAccountEditState(megaTarget(identity), renderer.accounts);
expect(validateAccountEdit(edit, renderer.accounts)).toBeNull();
expect(buildAccountReplaceCommand(edit)).toEqual(expect.objectContaining({
action: "replace",
accountId: getMegaDebridAccountId(identity),
identity,
secret: ""
}));
});
it("rejects duplicate identities using safe account metadata", () => {
const first = "first-safe@example.test";
const second = "second-safe@example.test";
const renderer = createRendererState({
...defaultSettings(),
megaCredentials: `${first}:fixture-first-secret-1aB2\n${second}:fixture-second-secret-3cD4`,
megaDebridApiCredentials: `${first}:fixture-first-secret-1aB2\n${second}:fixture-second-secret-3cD4`,
megaDebridApiEnabled: true
});
const edit = { ...createAccountEditState(megaTarget(second), renderer.accounts), login: first };
expect(validateAccountEdit(edit, renderer.accounts)).toMatch(/bereits vorhanden/i);
});
it("builds an identity-only delete command", () => {
const target = megaTarget("delete-safe@example.test");
expect(buildAccountDeleteCommand(target)).toEqual({
action: "delete",
kind: "megadebrid-api",
accountId: target.type === "mega" ? target.accountId : ""
});
});
it("uses the synthetic Deepbrid account id for edit, reveal and delete", () => {
const renderer = createRendererState({ ...defaultSettings(), deepbridApiKey: "synthetic-deepbrid-key" });
const target: AccountEditTarget = {
type: "single",
rowKey: "svc-deepbrid",
kind: "deepbrid-api",
service: "deepbrid",
provider: "deepbrid"
};
const edit = createAccountEditState(target, renderer.accounts);
expect(buildAccountReplaceCommand({ ...edit, token: "replacement-deepbrid-key" })).toEqual(expect.objectContaining({
kind: "deepbrid-api",
accountId: "svc-deepbrid",
secret: "replacement-deepbrid-key"
}));
expect(buildAccountDeleteCommand(target).accountId).toBe("svc-deepbrid");
});
});