24 lines
1.7 KiB
TypeScript
24 lines
1.7 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { test } from "node:test"
|
|
import type { CertificateIssueJobRow } from "../db/schema.js"
|
|
import { mapCertificateIssueJob } from "./certificate-issue-dto.js"
|
|
|
|
const row: CertificateIssueJobRow = { id: "job-1", serverId: 1, status: "queued", step: "queued", source: "manual", certName: "cert", domainNames: ["test.example"], keyType: "rsa2048", trustStore: "www,api", requestedAt: "2026-10-01T00:00:00Z", startedAt: null, finishedAt: null, error: null }
|
|
test("numeric DB server ID becomes string without altering job target", () => {
|
|
const dto = mapCertificateIssueJob(row)
|
|
assert.equal(dto.serverId, "1"); assert.deepEqual(dto.domainNames, ["test.example"]); assert.equal(dto.status, "queued")
|
|
assert.equal(dto.startedAt, undefined); assert.equal(dto.error, undefined)
|
|
})
|
|
test("real failed runner step and error survive strict contract", () => {
|
|
const dto = mapCertificateIssueJob({ ...row, status: "failed", step: "failed", error: "RouterOS import failed", finishedAt: "2026-10-01T00:01:00Z" })
|
|
assert.equal(dto.status, "failed"); assert.equal(dto.step, "failed"); assert.equal(dto.error, "RouterOS import failed")
|
|
})
|
|
test("legacy JSON domains and done job remain compatible", () => {
|
|
const dto = mapCertificateIssueJob({ ...row, status: "done", step: "done", domainNames: JSON.stringify(["test.example"]) })
|
|
assert.deepEqual(dto.domainNames, ["test.example"]); assert.equal(dto.status, "done")
|
|
})
|
|
test("invalid state and malformed domain values do not become successful DTOs", () => {
|
|
assert.throws(() => mapCertificateIssueJob({ ...row, step: "unexpected" }))
|
|
assert.throws(() => mapCertificateIssueJob({ ...row, domainNames: [null] }))
|
|
})
|