fix(accounts): refresh status before enabling accounts

Validate Real-Debrid, Mega-Debrid, and Debrid-Link accounts silently before exposing a newly enabled account to active downloads. Keep the row toggle optimistic, skip network checks while disabling, persist direct account-check results, and avoid the browser-login race for an already authenticated Real-Debrid web session.
This commit is contained in:
Sucukdeluxe
2026-08-15 21:41:38 +02:00
parent d720c5912e
commit 82303dc94a
5 changed files with 83 additions and 12 deletions
+15
View File
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { AppController } from "../src/main/app-controller";
import { defaultSettings } from "../src/main/constants";
import { parseDebridLinkApiKeys } from "../src/shared/debrid-link-keys";
import type { AppSettings, DebridAccountStatus } from "../src/shared/types";
vi.mock("electron", () => ({
@@ -88,4 +89,18 @@ Backup-Passphrase=${echoedPassphrase}`;
expectNoSecret(status, [secret, encodedSecret, echoedHeaderSecret, echoedPassphrase]);
expect((status as DebridAccountStatus).message).toContain("[geschützt]");
});
it("persists a direct status refresh for an existing account", async () => {
const settings = defaultSettings();
settings.debridLinkApiKeys = "existing-account-token";
const accountId = parseDebridLinkApiKeys(settings.debridLinkApiKeys)[0].id;
mockFetchOnce(200, { success: true, value: { username: "active-user", accountType: 1 } });
const controller = createController(settings);
const status = await controller.checkAccountCredentials({ kind: "debridlink-api", accountId });
expect(status).toEqual(expect.objectContaining({ accountId, valid: true, username: "active-user" }));
expect((controller as unknown as { manager: { applyDebridAccountStatuses: ReturnType<typeof vi.fn> } }).manager.applyDebridAccountStatuses)
.toHaveBeenCalledWith([expect.objectContaining({ accountId, valid: true })]);
});
});