import assert from "node:assert/strict"
import { hasPermission, permissionForRequest } from "./permissions.js"

assert.equal(hasPermission(["mm:servers:write"], "mm:servers:read"), true)
assert.equal(hasPermission(["mm:servers:admin"], "mm:servers:write"), true)
assert.equal(hasPermission(["mm:servers:read"], "mm:servers:write"), false)

assert.equal(
  permissionForRequest("GET", "/api/servers"),
  "mm:servers:read",
)
assert.equal(
  permissionForRequest("POST", "/api/servers"),
  "mm:servers:write",
)
assert.equal(
  permissionForRequest("GET", "/api/system/database/backup"),
  "mm:settings:admin",
)
assert.equal(
  permissionForRequest("GET", "/api/unknown-thing"),
  "mm:dashboard:read",
)

console.log("permissions.test.ts: ok")
