34 lines · 1.3 KB
import { describe, expect, mock, test } from "bun:test";
import { memoryScopes } from "../scoped-db/testing";

const scopes = memoryScopes();
mock.module("../scoped-db", () => scopes.module);

const { loadSecuritySettings, reserveSecurityNumbers, saveSecuritySettings } = await import("./settings");

describe("security settings in RepoState", () => {
  test("defaults, then saved values, per repository", async () => {
    expect((await loadSecuritySettings("r1")).secretScanning).toBe(true);
    await saveSecuritySettings("r1", {
      secretScanning: false,
      pushProtection: true,
      privateReporting: true,
      dependencyGraph: false,
    });
    expect(await loadSecuritySettings("r1")).toEqual({
      secretScanning: false,
      pushProtection: true,
      privateReporting: true,
      dependencyGraph: false,
    });
    expect((await loadSecuritySettings("r2")).pushProtection).toBe(false);
  });

  test("alert numbers are reserved in consecutive blocks per repo and kind", async () => {
    expect(await reserveSecurityNumbers("r1", "code", 3)).toBe(1);
    expect(await reserveSecurityNumbers("r1", "code", 1)).toBe(4);
    expect(await reserveSecurityNumbers("r1", "secret", 1)).toBe(1);
    expect(await reserveSecurityNumbers("r2", "code", 1)).toBe(1);
  });
});