Files
MikrotikManager/backend/src/modules/mcp/interface-events-compatibility-http.test.ts
T

37 lines
2.5 KiB
TypeScript

import assert from "node:assert/strict"
process.env.AUTH_REQUIRED = "true"
process.env.AUTH_JWT_SECRET = "mcp-owned-interface-events-acceptance-secret"
process.env.AUTH_ISSUER = "https://auth.test.local"
const { pool, closePool } = await import("../../db/index.js")
const { applySqlMigrations } = await import("../../db/migrate.js")
const { updateMcpSettings } = await import("./store.js")
const { buildApp } = await import("../../index.js")
const actor = { id: "interface-events-acceptance-owner", apps: ["mm"], permissions: ["mm:settings:admin", "mm:network:admin", "mm:filters:admin", "mm:servers:admin", "mm:dashboard:read"], expiresAt: Date.now() + 3600000 }
let app: Awaited<ReturnType<typeof buildApp>> | undefined
try {
await applySqlMigrations(pool)
assert.equal((await pool.query("SELECT count(*)::int AS n FROM servers")).rows[0].n, 0, "Disposable empty database required")
await pool.query("INSERT INTO servers(id,name,host,port,use_ssl,enabled) VALUES(1,'owned-fixture','127.0.0.1',9,false,false)")
await pool.query("INSERT INTO geoip_settings(id,enabled) VALUES(1,false) ON CONFLICT(id) DO UPDATE SET enabled=false")
await pool.query("INSERT INTO traffic_flow_settings(id) VALUES(1) ON CONFLICT(id) DO NOTHING")
await updateMcpSettings({ enabled: true }, actor)
app = await buildApp({ startScheduler: false }); await app.ready()
const legacyBgpOnly = process.env.MMAPP_OWN_LEGACY_BGP_ONLY === "true"
if (legacyBgpOnly) {
await (await import("./routing-community-context-compatibility-acceptance.js")).acceptRouteCommunityContextCompatibilityMcp(actor, { legacyOnly: true })
} else {
await (await import("../../test/mcp-events-batch.js")).verifyMcpEventsBatch(actor, app)
}
if (!legacyBgpOnly && process.env.MMAPP_OWN_EVENTS_ONLY !== "true") {
await (await import("./wireguard-interface-update-acceptance.js")).acceptWireguardInterfaceUpdate(actor)
await (await import("./routing-community-context-compatibility-acceptance.js")).acceptRouteCommunityContextCompatibilityMcp(actor)
await (await import("./routing-community-context-acceptance.js")).acceptRouteCommunityContextMcp(actor)
await (await import("./routing-community-scoped-acceptance.js")).acceptScopedRouteCommunitySwitch(actor)
}
} finally {
await pool.query("UPDATE servers SET enabled=false").catch(() => {})
await (await import("../../services/scheduler.js")).stopSchedulerForDatabaseOperation()
await (await import("../../services/traffic-flow-ingest.js")).stopTrafficFlowListenerForDatabaseOperation()
await app?.close(); await closePool()
}