style: apply Biome formatting to enterprise files

This commit is contained in:
SnapOtter
2026-06-14 14:53:44 +08:00
parent 954cfb01a6
commit e7bef34918
23 changed files with 166 additions and 228 deletions
+1 -2
View File
@@ -16,8 +16,7 @@ const apiRequire = createRequire(join(process.cwd(), "apps/api/package.json"));
const pg = apiRequire("pg");
const baseUrl =
process.env.E2E_PG_BASE_URL ||
"postgres://snapotter:snapotter@localhost:5432/snapotter";
process.env.E2E_PG_BASE_URL || "postgres://snapotter:snapotter@localhost:5432/snapotter";
const dbName = process.argv[2];
if (!dbName) {
+3 -6
View File
@@ -1,18 +1,15 @@
import { vi } from "vitest";
import type { EnterpriseFeature } from "@snapotter/enterprise";
import { vi } from "vitest";
export function mockEnterpriseFeatures(features: EnterpriseFeature[]) {
vi.doMock("@snapotter/enterprise", () => ({
isFeatureEnabled: (feature: string) =>
features.includes(feature as EnterpriseFeature),
isFeatureEnabled: (feature: string) => features.includes(feature as EnterpriseFeature),
getActiveLicense: () => ({
org: "test-org",
plan: "enterprise" as const,
features,
seats: 100,
expiresAt: new Date(
Date.now() + 365 * 24 * 60 * 60 * 1000,
).toISOString(),
expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(),
issuedAt: new Date().toISOString(),
}),
initEnterprise: vi.fn(),
+1 -1
View File
@@ -1,7 +1,7 @@
import { eq } from "drizzle-orm";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { db, schema } from "../../apps/api/src/db/index.js";
import { buildTestApp, loginAsAdmin, type TestApp } from "./test-server.js";
import { eq } from "drizzle-orm";
let testApp: TestApp;
let adminToken: string;
@@ -39,9 +39,7 @@ async function setSetting(key: string, value: string): Promise<void> {
expect(res.statusCode).toBe(200);
}
async function fetchAuditLog(
action: string,
): Promise<{ entries: any[]; total: number }> {
async function fetchAuditLog(action: string): Promise<{ entries: any[]; total: number }> {
const res = await testApp.app.inject({
method: "GET",
url: `/api/v1/audit-log?action=${action}`,
+1 -1
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { buildTestApp, loginAsAdmin, type TestApp } from "./test-server.js";
let testApp: TestApp;
+6 -2
View File
@@ -1,5 +1,9 @@
import { describe, it, expect } from "vitest";
import { canonicalize, computeHmac, verifyHmac } from "../../../apps/api/src/lib/audit-integrity.js";
import { describe, expect, it } from "vitest";
import {
canonicalize,
computeHmac,
verifyHmac,
} from "../../../apps/api/src/lib/audit-integrity.js";
describe("audit integrity", () => {
const testKey = Buffer.from("a".repeat(64), "hex");
+3 -3
View File
@@ -1,9 +1,9 @@
import { describe, it, expect } from "vitest";
import { describe, expect, it } from "vitest";
import {
encrypt,
decrypt,
isEncrypted,
deriveAuditHmacKey,
encrypt,
isEncrypted,
} from "../../../apps/api/src/lib/encryption.js";
describe("encryption", () => {
+1 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { ENTERPRISE_FEATURES, PLAN_FEATURES } from "@snapotter/enterprise";
import { describe, expect, it } from "vitest";
describe("enterprise feature flags", () => {
it("includes all Phase 1 flags", () => {
+5 -13
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
describe("enterprise mock", () => {
beforeEach(() => {
@@ -6,9 +6,7 @@ describe("enterprise mock", () => {
});
it("mocks feature enabled", async () => {
const { mockEnterpriseFeatures } = await import(
"../../helpers/enterprise-mock.js"
);
const { mockEnterpriseFeatures } = await import("../../helpers/enterprise-mock.js");
mockEnterpriseFeatures(["audit_export", "siem_forwarding"]);
const { isFeatureEnabled } = await import("@snapotter/enterprise");
expect(isFeatureEnabled("audit_export")).toBe(true);
@@ -17,18 +15,14 @@ describe("enterprise mock", () => {
});
it("mocks no enterprise", async () => {
const { mockNoEnterprise } = await import(
"../../helpers/enterprise-mock.js"
);
const { mockNoEnterprise } = await import("../../helpers/enterprise-mock.js");
mockNoEnterprise();
const { isFeatureEnabled } = await import("@snapotter/enterprise");
expect(isFeatureEnabled("audit_export")).toBe(false);
});
it("returns license payload with correct shape", async () => {
const { mockEnterpriseFeatures } = await import(
"../../helpers/enterprise-mock.js"
);
const { mockEnterpriseFeatures } = await import("../../helpers/enterprise-mock.js");
mockEnterpriseFeatures(["s3_storage", "mfa"]);
const { getActiveLicense } = await import("@snapotter/enterprise");
const license = getActiveLicense();
@@ -41,9 +35,7 @@ describe("enterprise mock", () => {
});
it("returns null license when no enterprise", async () => {
const { mockNoEnterprise } = await import(
"../../helpers/enterprise-mock.js"
);
const { mockNoEnterprise } = await import("../../helpers/enterprise-mock.js");
mockNoEnterprise();
const { getActiveLicense } = await import("@snapotter/enterprise");
expect(getActiveLicense()).toBeNull();
+4 -6
View File
@@ -1,4 +1,4 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("webhook delivery", () => {
beforeEach(() => {
@@ -15,11 +15,9 @@ describe("webhook delivery", () => {
vi.stubGlobal("fetch", fetchMock);
const { deliverWebhook } = await import("../../../apps/api/src/lib/webhook-delivery.js");
const result = await deliverWebhook(
"https://siem.example.com/input",
"Bearer test-token",
[{ event: "LOGIN_SUCCESS", timestamp: "2026-01-01T00:00:00Z" }],
);
const result = await deliverWebhook("https://siem.example.com/input", "Bearer test-token", [
{ event: "LOGIN_SUCCESS", timestamp: "2026-01-01T00:00:00Z" },
]);
expect(result.success).toBe(true);
expect(result.attempts).toBe(1);