mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Rename verifiedPackages to totalPackages, fix e2e tests
This commit is contained in:
parent
e4c40330f7
commit
378b0ac7c9
11 changed files with 89 additions and 59 deletions
|
|
@ -63,11 +63,11 @@ export async function main(args) {
|
|||
}
|
||||
|
||||
const auditStats = getAuditStats();
|
||||
if (auditStats.verifiedPackages > 0) {
|
||||
if (auditStats.totalPackages > 0) {
|
||||
ui.emptyLine();
|
||||
ui.writeInformation(
|
||||
`${chalk.green("✔")} Safe-chain: Scanned ${
|
||||
auditStats.verifiedPackages
|
||||
auditStats.totalPackages
|
||||
} packages, no malware found.`
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import {
|
|||
|
||||
/**
|
||||
* @typedef {Object} AuditStats
|
||||
* @property {number} verifiedPackages
|
||||
* @property {number} totalPackages
|
||||
* @property {number} safePackages
|
||||
* @property {number} malwarePackages
|
||||
*/
|
||||
|
|
@ -29,7 +29,7 @@ import {
|
|||
* @type AuditStats
|
||||
*/
|
||||
const auditStats = {
|
||||
verifiedPackages: 0,
|
||||
totalPackages: 0,
|
||||
safePackages: 0,
|
||||
malwarePackages: 0,
|
||||
};
|
||||
|
|
@ -77,7 +77,7 @@ export async function auditChanges(changes) {
|
|||
allowedChanges.push(change);
|
||||
}
|
||||
|
||||
auditStats.verifiedPackages += 1;
|
||||
auditStats.totalPackages += 1;
|
||||
}
|
||||
|
||||
const auditResults = {
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ describe("audit/index", async () => {
|
|||
it("should return audit stats object with correct structure", () => {
|
||||
const stats = getAuditStats();
|
||||
|
||||
assert.ok(stats.hasOwnProperty("verifiedPackages"));
|
||||
assert.ok(stats.hasOwnProperty("totalPackages"));
|
||||
assert.ok(stats.hasOwnProperty("safePackages"));
|
||||
assert.ok(stats.hasOwnProperty("malwarePackages"));
|
||||
assert.equal(typeof stats.verifiedPackages, "number");
|
||||
assert.equal(typeof stats.totalPackages, "number");
|
||||
assert.equal(typeof stats.safePackages, "number");
|
||||
assert.equal(typeof stats.malwarePackages, "number");
|
||||
});
|
||||
|
|
@ -120,11 +120,11 @@ describe("audit/index", async () => {
|
|||
assert.equal(mockIsMalware.mock.calls.length, 2);
|
||||
});
|
||||
|
||||
it("should increment verifiedPackages counter for each package", async () => {
|
||||
it("should increment totalPackages counter for each package", async () => {
|
||||
mockIsMalware.mock.mockImplementation(() => false);
|
||||
|
||||
const statsBefore = getAuditStats();
|
||||
const initialCount = statsBefore.verifiedPackages;
|
||||
const initialCount = statsBefore.totalPackages;
|
||||
|
||||
const changes = [
|
||||
{ name: "pkg1", version: "1.0.0", type: "add" },
|
||||
|
|
@ -134,7 +134,7 @@ describe("audit/index", async () => {
|
|||
await auditChanges(changes);
|
||||
|
||||
const statsAfter = getAuditStats();
|
||||
assert.equal(statsAfter.verifiedPackages, initialCount + 3);
|
||||
assert.equal(statsAfter.totalPackages, initialCount + 3);
|
||||
});
|
||||
|
||||
it("should increment safePackages counter for safe packages", async () => {
|
||||
|
|
@ -173,7 +173,7 @@ describe("audit/index", async () => {
|
|||
mockIsMalware.mock.mockImplementation(() => false);
|
||||
|
||||
const statsBefore = getAuditStats();
|
||||
const initialVerified = statsBefore.verifiedPackages;
|
||||
const initialCount = statsBefore.totalPackages;
|
||||
|
||||
// First call
|
||||
await auditChanges([{ name: "pkg1", version: "1.0.0", type: "add" }]);
|
||||
|
|
@ -182,7 +182,7 @@ describe("audit/index", async () => {
|
|||
await auditChanges([{ name: "pkg2", version: "2.0.0", type: "add" }]);
|
||||
|
||||
const statsAfter = getAuditStats();
|
||||
assert.equal(statsAfter.verifiedPackages, initialVerified + 2);
|
||||
assert.equal(statsAfter.totalPackages, initialCount + 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue