mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Split up newPackagesDatabse into builder, warnigns, cache
This commit is contained in:
parent
f920fc61ac
commit
5b1cd7e8da
10 changed files with 434 additions and 66 deletions
|
|
@ -0,0 +1,63 @@
|
|||
import { describe, it, mock, beforeEach } from "node:test";
|
||||
import assert from "node:assert";
|
||||
|
||||
let writeWarningCalls = [];
|
||||
|
||||
mock.module("../environment/userInteraction.js", {
|
||||
namedExports: {
|
||||
ui: {
|
||||
writeWarning: (msg) => writeWarningCalls.push(msg),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { warnOnceAboutUnavailableDatabase, resetWarningState } = await import(
|
||||
"./newPackagesDatabaseWarnings.js"
|
||||
);
|
||||
|
||||
describe("newPackagesDatabaseWarnings", () => {
|
||||
beforeEach(() => {
|
||||
writeWarningCalls = [];
|
||||
resetWarningState();
|
||||
});
|
||||
|
||||
describe("warnOnceAboutUnavailableDatabase", () => {
|
||||
it("emits a warning containing the error message", () => {
|
||||
warnOnceAboutUnavailableDatabase(new Error("feed unavailable"));
|
||||
|
||||
assert.strictEqual(writeWarningCalls.length, 1);
|
||||
assert.ok(writeWarningCalls[0].includes("feed unavailable"));
|
||||
});
|
||||
|
||||
it("mentions fallback to metadata-based checks in the warning", () => {
|
||||
warnOnceAboutUnavailableDatabase(new Error("timeout"));
|
||||
|
||||
assert.ok(
|
||||
writeWarningCalls[0].includes(
|
||||
"Continuing with metadata-based minimum age checks only"
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("only emits once even when called multiple times", () => {
|
||||
warnOnceAboutUnavailableDatabase(new Error("first"));
|
||||
warnOnceAboutUnavailableDatabase(new Error("second"));
|
||||
warnOnceAboutUnavailableDatabase(new Error("third"));
|
||||
|
||||
assert.strictEqual(writeWarningCalls.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resetWarningState", () => {
|
||||
it("allows the warning to fire again after reset", () => {
|
||||
warnOnceAboutUnavailableDatabase(new Error("first"));
|
||||
assert.strictEqual(writeWarningCalls.length, 1);
|
||||
|
||||
resetWarningState();
|
||||
writeWarningCalls = [];
|
||||
|
||||
warnOnceAboutUnavailableDatabase(new Error("second"));
|
||||
assert.strictEqual(writeWarningCalls.length, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue