Files
MikrotikManager/backend/src/services/backup-dto.test.ts
T

15 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict"
import { test } from "node:test"
import { mapBackupEntry } from "./backup-dto.js"
const row = { id: "backup", serverId: 1, serverName: "router", filename: "config.rsc", sizeBytes: 0, createdAt: "2026-10-01 07:00:00.123+07", kind: "manual" as const, notes: null, storage: "local" as const, s3Key: null, s3Etag: null, uploadError: null }
test("PostgreSQL timestamp format is normalized to ISO with the same instant", () => {
const result = mapBackupEntry(row); assert.equal(result.createdAt, "2026-10-01T00:00:00.123Z"); assert.equal(result.sizeBytes, 0); assert.equal(result.serverId, 1)
})
test("removed server and partial S3 failure remain explicit", () => {
const result = mapBackupEntry({ ...row, serverId: null, uploadError: "S3 unavailable" })
assert.equal(result.serverId, null); assert.equal(result.storage, "local"); assert.equal(result.uploadError, "S3 unavailable")
})
test("invalid timestamps and sizes do not turn into truthful backup metadata", () => {
assert.throws(() => mapBackupEntry({ ...row, createdAt: "bad" })); assert.throws(() => mapBackupEntry({ ...row, sizeBytes: -1 }))
})