fix(realdebrid): persist web status and report relevant provider errors

Check Real-Debrid API and browser sessions through the account status flow, retain the service status across settings updates, and refresh the account row when a browser login is detected. Exclude unavailable providers that were never attempted from conversion failures and prevent aggregated fallback text from being mislabeled as a Debrid-Link terminal error. Bump the development version to 2.0.37 and add focused regression coverage.
This commit is contained in:
Sucukdeluxe
2026-08-14 21:02:30 +02:00
parent c2d5dbaeb3
commit b80209a10f
20 changed files with 556 additions and 81 deletions
+52 -5
View File
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, afterEach } from "vitest";
import { checkMegaDebridAccount, checkDebridLinkKey, checkAllDebridAccounts } from "../src/main/account-check";
import { checkMegaDebridAccount, checkDebridLinkKey, checkAllDebridAccounts, checkRealDebridAccount, REAL_DEBRID_STATUS_ID } from "../src/main/account-check";
import type { MegaDebridAccountEntry } from "../src/shared/mega-debrid-accounts";
import type { DebridLinkApiKeyEntry } from "../src/shared/debrid-link-keys";
import type { AppSettings } from "../src/shared/types";
@@ -78,7 +78,7 @@ describe("checkMegaDebridAccount", () => {
});
});
describe("checkDebridLinkKey", () => {
describe("checkDebridLinkKey", () => {
it("reports valid + premium from premiumLeft seconds", async () => {
const premiumLeft = 60 * 24 * 60 * 60;
mockFetchOnce(200, { success: true, value: { username: "u", accountType: 1, premiumLeft } });
@@ -108,14 +108,61 @@ describe("checkDebridLinkKey", () => {
const st = await checkDebridLinkKey(debridLinkKey(), undefined, NOW);
expect(st.valid).toBe(false);
});
});
});
describe("checkRealDebridAccount", () => {
it("uses the browser-session probe and returns a stable service status", async () => {
const premiumUntilMs = NOW + 30 * 24 * 60 * 60 * 1000;
const probe = vi.fn(async () => ({
valid: true,
isPremium: true,
premiumUntilMs,
username: "web-user"
}));
const status = await checkRealDebridAccount({
token: "",
realDebridUseWebLogin: true
} as AppSettings, undefined, NOW, probe);
expect(probe).toHaveBeenCalledTimes(1);
expect(status).toMatchObject({
accountId: REAL_DEBRID_STATUS_ID,
provider: "realdebrid",
valid: true,
isPremium: true,
premiumUntilMs,
email: "web-user"
});
});
});
describe("checkAllDebridAccounts", () => {
it("returns empty array when nothing configured", async () => {
it("returns empty array when nothing configured", async () => {
const settings = { megaCredentials: "", megaPassword: "", debridLinkApiKeys: "" } as unknown as AppSettings;
const result = await checkAllDebridAccounts(settings);
expect(result).toEqual([]);
});
});
it("includes Real-Debrid web login in the bulk account check", async () => {
const settings = {
token: "",
realDebridUseWebLogin: true,
megaCredentials: "",
megaPassword: "",
debridLinkApiKeys: ""
} as AppSettings;
const probe = vi.fn(async () => ({ valid: true, isPremium: true, username: "web-user" }));
const result = await checkAllDebridAccounts(settings, undefined, probe);
expect(result).toHaveLength(1);
expect(result[0]).toMatchObject({
accountId: REAL_DEBRID_STATUS_ID,
provider: "realdebrid",
valid: true
});
});
it("checks every configured mega account + debrid-link key", async () => {
const futureSec = Math.floor(Date.now() / 1000) + 1000;