From a762e2e3f2581ca484ba2b25893e3b77d14361d6 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 2 Feb 2026 21:23:58 -0800 Subject: [PATCH] First test! --- src/widgets/backrest/proxy.js | 4 ++-- src/widgets/backrest/proxy.test.js | 37 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/widgets/backrest/proxy.test.js diff --git a/src/widgets/backrest/proxy.js b/src/widgets/backrest/proxy.js index 1b1052b87..04e177573 100644 --- a/src/widgets/backrest/proxy.js +++ b/src/widgets/backrest/proxy.js @@ -7,14 +7,14 @@ import widgets from "widgets/widgets"; const proxyName = "backrestProxyHandler"; const logger = createLogger(proxyName); -function sumField(plans, field) { +export function sumField(plans, field) { return plans.reduce((sum, plan) => { const num = Number(plan[field]); return sum + (Number.isNaN(num) ? 0 : num); }, 0); } -function buildResponse(plans) { +export function buildResponse(plans) { const numSuccess30Days = sumField(plans, "backupsSuccessLast30days"); const numFailure30Days = sumField(plans, "backupsFailed30days"); const bytesAdded30Days = sumField(plans, "bytesAddedLast30days"); diff --git a/src/widgets/backrest/proxy.test.js b/src/widgets/backrest/proxy.test.js new file mode 100644 index 000000000..2c29efaf6 --- /dev/null +++ b/src/widgets/backrest/proxy.test.js @@ -0,0 +1,37 @@ +import { describe, expect, it } from "vitest"; + +import { buildResponse } from "./proxy"; + +describe("backrest proxy buildResponse", () => { + it("aggregates plan metrics and latest status counts", () => { + const plans = [ + { + backupsSuccessLast30days: 3, + backupsFailed30days: 1, + bytesAddedLast30days: 1000, + recentBackups: { status: ["STATUS_SUCCESS"] }, + }, + { + backupsSuccessLast30days: 2, + backupsFailed30days: 0, + bytesAddedLast30days: 500, + recentBackups: { status: ["STATUS_ERROR"] }, + }, + { + backupsSuccessLast30days: "not-a-number", + backupsFailed30days: 4, + bytesAddedLast30days: 250, + recentBackups: { status: [] }, + }, + ]; + + expect(buildResponse(plans)).toEqual({ + numPlans: 3, + numSuccess30Days: 5, + numFailure30Days: 5, + numSuccessLatest: 1, + numFailureLatest: 1, + bytesAdded30Days: 1750, + }); + }); +});