mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
test(guards): derive the rounding guard's directories from the connection keys
The guard kept its own provider list and its own comment stripper next to the shared PROVIDER_DIRS and stripComments helpers, so a new integration could slip past it. It now uses both, plus the file importers, which are not a connection.
This commit is contained in:
1 parent
c50007ef61
commit
4f02004146
1 file changed
+9
-22
@@ -14,22 +14,15 @@ import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { walkSourceFiles } from "./helpers/source-files";
|
||||
import { PROVIDER_DIRS } from "./helpers/provider-dirs";
|
||||
import { stripComments, walkSourceFiles } from "./helpers/source-files";
|
||||
|
||||
const LIB = join(process.cwd(), "src", "lib");
|
||||
const PROVIDER_DIRS = [
|
||||
"apple-health",
|
||||
"dawarich",
|
||||
"fitbit",
|
||||
"google-health",
|
||||
"nightscout",
|
||||
"oura",
|
||||
"polar",
|
||||
"strava",
|
||||
"whoop",
|
||||
"withings",
|
||||
"import",
|
||||
];
|
||||
/**
|
||||
* Every provider the product connects to, plus the file importers (Health
|
||||
* Connect, the export parsers), which are not a connection of their own.
|
||||
*/
|
||||
const ROUNDING_DIRS = [...PROVIDER_DIRS, "import"];
|
||||
const ROUNDING =
|
||||
/\.toFixed\s*\(|\b(?:function|const|let)\s+round2\b|Math\.round\s*\([^;]*\*\s*(10+)\s*\)\s*\/\s*\1\b/;
|
||||
|
||||
@@ -41,16 +34,10 @@ const ALLOWED: Record<string, string> = {
|
||||
"Prints a compression ratio into an error message.",
|
||||
};
|
||||
|
||||
function strip(text: string): string {
|
||||
return text
|
||||
.replace(/\/\*[\s\S]*?\*\//g, "")
|
||||
.replace(/(^|[^:])\/\/.*$/gm, "$1");
|
||||
}
|
||||
|
||||
describe("provider clients round through importValue", () => {
|
||||
const files = walkSourceFiles(LIB, { floor: 1000 }).filter(
|
||||
(f) =>
|
||||
PROVIDER_DIRS.some((d) => f.startsWith(`${d}/`)) &&
|
||||
ROUNDING_DIRS.some((d) => f.startsWith(`${d}/`)) &&
|
||||
!f.includes("__tests__") &&
|
||||
!f.endsWith(".test.ts"),
|
||||
);
|
||||
@@ -63,7 +50,7 @@ describe("provider clients round through importValue", () => {
|
||||
const offenders = files.filter(
|
||||
(f) =>
|
||||
!(f in ALLOWED) &&
|
||||
ROUNDING.test(strip(readFileSync(join(LIB, f), "utf8"))),
|
||||
ROUNDING.test(stripComments(readFileSync(join(LIB, f), "utf8"))),
|
||||
);
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user