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:
@@ -120,7 +120,7 @@ describe("realdebrid-web", () => {
|
||||
.toBe("ghi789");
|
||||
});
|
||||
|
||||
it("uses the already logged-in browser window to warm the token cache before unrestricting", async () => {
|
||||
it("uses the already logged-in browser window to warm the token cache before unrestricting", async () => {
|
||||
const apiFetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
||||
download: "https://cdn.real-debrid.example/file.bin",
|
||||
filename: "file.bin",
|
||||
@@ -160,6 +160,46 @@ describe("realdebrid-web", () => {
|
||||
expect(mockSessionFetch).not.toHaveBeenCalled();
|
||||
expect(apiFetch).toHaveBeenCalledTimes(1);
|
||||
expect(apiFetch.mock.calls[0]?.[0]).toBe("https://api.real-debrid.com/rest/1.0/unrestrict/link");
|
||||
expect(mockBrowserWindow.webContents.executeJavaScript).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
expect(mockBrowserWindow.webContents.executeJavaScript).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("checks the logged-in browser account without exposing its token", async () => {
|
||||
mockExecuteJavaScript.mockResolvedValue("token-from-window");
|
||||
const apiFetch = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
||||
username: "web-user",
|
||||
email: "web-user@example.test",
|
||||
type: "premium",
|
||||
expiration: "2030-01-02T03:04:05.000Z"
|
||||
}), { status: 200 }));
|
||||
vi.stubGlobal("fetch", apiFetch);
|
||||
|
||||
const fallback = new RealDebridWebFallback(() => true);
|
||||
await fallback.openLoginWindow();
|
||||
const status = await fallback.probeLoginState();
|
||||
|
||||
expect(status).toEqual({
|
||||
valid: true,
|
||||
username: "web-user",
|
||||
email: "web-user@example.test",
|
||||
isPremium: true,
|
||||
premiumUntilMs: Date.parse("2030-01-02T03:04:05.000Z"),
|
||||
message: "Premium aktiv"
|
||||
});
|
||||
expect(JSON.stringify(status)).not.toContain("token-from-window");
|
||||
expect(apiFetch).toHaveBeenCalledWith(
|
||||
"https://api.real-debrid.com/rest/1.0/user",
|
||||
expect.objectContaining({
|
||||
headers: expect.objectContaining({ Authorization: "Bearer token-from-window" })
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("notifies the controller when a new browser token is detected", async () => {
|
||||
mockExecuteJavaScript.mockResolvedValue("new-browser-token");
|
||||
const onAuthenticated = vi.fn();
|
||||
const fallback = new RealDebridWebFallback(() => true, onAuthenticated);
|
||||
|
||||
await fallback.openLoginWindow();
|
||||
await vi.waitFor(() => expect(onAuthenticated).toHaveBeenCalledTimes(1));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user