import assert from "node:assert/strict"
import { groupShouldFire } from "./groups.js"
import { cooldownToMs, isCooldownElapsed } from "./cooldown.js"

assert.equal(groupShouldFire("any", []), false)
assert.equal(groupShouldFire("any", [false, false]), false)
assert.equal(groupShouldFire("any", [false, true]), true)
assert.equal(groupShouldFire("all", [true, true]), true)
assert.equal(groupShouldFire("all", [true, false]), false)
assert.equal(groupShouldFire("all", [false, false]), false)

assert.equal(cooldownToMs("1м"), 60_000)
assert.equal(isCooldownElapsed(null, "5м"), true)
assert.equal(isCooldownElapsed(new Date(Date.now() - 6 * 60_000).toISOString(), "5м"), true)
assert.equal(isCooldownElapsed(new Date(Date.now() - 2 * 60_000).toISOString(), "5м"), false)

console.log("alert-engine groups/cooldown tests ok")
