mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-28 04:21:15 +02:00
Compare commits
2 Commits
copilot/fi
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d09cf1b5d | ||
|
|
c80d65483a |
@@ -122,7 +122,6 @@ function initAutoUpdater(mainWindow) {
|
|||||||
* Separated from init for reusability and testability.
|
* Separated from init for reusability and testability.
|
||||||
*/
|
*/
|
||||||
async function checkForUpdates() {
|
async function checkForUpdates() {
|
||||||
if (process.env.SNAP || process.env.FLATPAK_ID) return;
|
|
||||||
if (!require("electron").app.isPackaged) return;
|
if (!require("electron").app.isPackaged) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -141,6 +140,7 @@ async function downloadUpdate() {
|
|||||||
await autoUpdater.downloadUpdate();
|
await autoUpdater.downloadUpdate();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("Download failed:", err.message);
|
logger.error("Download failed:", err.message);
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,7 @@ async function sendReport(params) {
|
|||||||
|
|
||||||
if (includeLogs === "yes" && logDir) {
|
if (includeLogs === "yes" && logDir) {
|
||||||
// YYYY-MM-DD
|
// YYYY-MM-DD
|
||||||
const now = new Date();
|
const today = new Date().toISOString().split("T")[0];
|
||||||
const today = [
|
|
||||||
now.getFullYear(),
|
|
||||||
String(now.getMonth() + 1).padStart(2, "0"),
|
|
||||||
String(now.getDate()).padStart(2, "0")
|
|
||||||
].join("-");
|
|
||||||
|
|
||||||
const logFilePath = path.join(logDir, `LOGS-${today}.log`);
|
const logFilePath = path.join(logDir, `LOGS-${today}.log`);
|
||||||
|
|
||||||
@@ -35,17 +30,10 @@ async function sendReport(params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reportUrl = process.env.BUG_REPORT_URL;
|
const response = await fetch(process.env.BUG_REPORT_URL, {
|
||||||
const reportApiKey = process.env.BUG_REPORT_API_KEY;
|
|
||||||
|
|
||||||
if (!reportUrl || !reportApiKey) {
|
|
||||||
throw new Error("Bug report service is not configured. Missing BUG_REPORT_URL or BUG_REPORT_API_KEY on backend.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(reportUrl, {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"X-Api-Key": reportApiKey
|
"X-Api-Key": process.env.BUG_REPORT_API_KEY
|
||||||
},
|
},
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,13 +45,31 @@ async function initUpdateUI() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
btn.onclick = () => {
|
const initialButtonText = btn.textContent;
|
||||||
window.electronAPI.downloadUpdate();
|
const initialIconText = icon.textContent;
|
||||||
|
const initialTitleText = title.textContent;
|
||||||
|
const initialSubText = sub.textContent;
|
||||||
|
|
||||||
|
btn.onclick = async () => {
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
btn.textContent = "Downloading...";
|
btn.textContent = "Downloading...";
|
||||||
icon.textContent = "download";
|
icon.textContent = "download";
|
||||||
title.textContent = "Downloading update";
|
title.textContent = "Downloading update";
|
||||||
progressWrap.style.display = "flex";
|
progressWrap.style.display = "flex";
|
||||||
|
|
||||||
|
try {
|
||||||
|
await window.electronAPI.downloadUpdate();
|
||||||
|
} catch {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.textContent = initialButtonText;
|
||||||
|
icon.textContent = initialIconText;
|
||||||
|
title.textContent = initialTitleText;
|
||||||
|
sub.textContent = initialSubText;
|
||||||
|
progressWrap.style.display = "none";
|
||||||
|
progressFill.style.width = "0%";
|
||||||
|
progressPct.textContent = "0%";
|
||||||
|
progressEta.textContent = "";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.electronAPI.onDownloadProgress((progress) => {
|
window.electronAPI.onDownloadProgress((progress) => {
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class BugReportModal {
|
|||||||
window.electronAPI.logInfo("Submitting:", data);
|
window.electronAPI.logInfo("Submitting:", data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const success = await window.topbarAPI.sendReport(data);
|
const success = await window.electronAPI.sendReport(data);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
localStorage.removeItem("draft_bug_title");
|
localStorage.removeItem("draft_bug_title");
|
||||||
|
|||||||
53
test/unit/autoUpdater.test.js
Normal file
53
test/unit/autoUpdater.test.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
const mockDownloadUpdate = jest.fn();
|
||||||
|
const mockCheckForUpdates = jest.fn();
|
||||||
|
const mockOn = jest.fn();
|
||||||
|
const mockQuitAndInstall = jest.fn();
|
||||||
|
|
||||||
|
jest.mock("electron-updater", () => ({
|
||||||
|
autoUpdater: {
|
||||||
|
autoDownload: true,
|
||||||
|
autoInstallOnAppQuit: true,
|
||||||
|
on: mockOn,
|
||||||
|
checkForUpdates: mockCheckForUpdates,
|
||||||
|
downloadUpdate: mockDownloadUpdate,
|
||||||
|
quitAndInstall: mockQuitAndInstall,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock("electron", () => ({
|
||||||
|
app: {
|
||||||
|
isPackaged: true,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const mockLoggerError = jest.fn();
|
||||||
|
jest.mock("../../server/logger", () => ({
|
||||||
|
logger: {
|
||||||
|
info: jest.fn(),
|
||||||
|
warn: jest.fn(),
|
||||||
|
error: mockLoggerError,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { downloadUpdate } = require("../../app/autoUpdater");
|
||||||
|
|
||||||
|
describe("autoUpdater.downloadUpdate", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("resolves when electron-updater download succeeds", async () => {
|
||||||
|
mockDownloadUpdate.mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
await expect(downloadUpdate()).resolves.toBeUndefined();
|
||||||
|
expect(mockDownloadUpdate).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("rejects when electron-updater download fails", async () => {
|
||||||
|
const error = new Error("network down");
|
||||||
|
mockDownloadUpdate.mockRejectedValue(error);
|
||||||
|
|
||||||
|
await expect(downloadUpdate()).rejects.toThrow("network down");
|
||||||
|
expect(mockLoggerError).toHaveBeenCalledWith("Download failed:", "network down");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
jest.mock("../../server/logger", () => ({
|
|
||||||
logger: {
|
|
||||||
info: jest.fn(),
|
|
||||||
warn: jest.fn(),
|
|
||||||
error: jest.fn(),
|
|
||||||
},
|
|
||||||
logDir: null,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const { sendReport } = require("../../app/sendReport");
|
|
||||||
|
|
||||||
describe("sendReport", () => {
|
|
||||||
const originalEnv = { ...process.env };
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
process.env.BUG_REPORT_URL = "";
|
|
||||||
process.env.BUG_REPORT_API_KEY = "";
|
|
||||||
global.fetch = jest.fn();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
process.env = originalEnv;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("throws a clear error when backend bug report config is missing", async () => {
|
|
||||||
await expect(
|
|
||||||
sendReport({
|
|
||||||
title: "Bug title",
|
|
||||||
description: "Bug description",
|
|
||||||
includeLogs: "no",
|
|
||||||
}),
|
|
||||||
).rejects.toThrow(
|
|
||||||
"Bug report service is not configured. Missing BUG_REPORT_URL or BUG_REPORT_API_KEY on backend.",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(global.fetch).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("sends request from backend when bug report config is present", async () => {
|
|
||||||
process.env.BUG_REPORT_URL = "https://example.com/report";
|
|
||||||
process.env.BUG_REPORT_API_KEY = "safe-test-key";
|
|
||||||
global.fetch.mockResolvedValue({ ok: true });
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
sendReport({
|
|
||||||
title: "Bug title",
|
|
||||||
description: "Bug description",
|
|
||||||
includeLogs: "no",
|
|
||||||
}),
|
|
||||||
).resolves.toBe(true);
|
|
||||||
|
|
||||||
expect(global.fetch).toHaveBeenCalledWith(
|
|
||||||
"https://example.com/report",
|
|
||||||
expect.objectContaining({
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"X-Api-Key": "safe-test-key",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user