fix(backups): подтверждать настройки и последнюю проверку S3

This commit is contained in:
Denozordec committed 2026-10-01 15:37:00 +07:00
1 parent 8e01666e0e
commit 30bd479a6f
14 files changed
+208 -64

No files matched your search

+9 -1
View File
@@ -1,6 +1,6 @@
import assert from "node:assert/strict"
import { test } from "node:test"
import { backupSchedulePayload } from "./backup-settings"
import { backupSchedulePayload, backupStoragePayload } from "./backup-settings"
const form = { enabled: false, frequency: "daily" as const, hour: "0", minute: "7", weekDay: 0, monthDay: 1, keepCount: "365", format: "rsc" as const }
test("schedule preserves zero, arbitrary minute and explicit all-enabled semantics", () => {
const result = backupSchedulePayload(form, ["1"], true)
@@ -16,3 +16,11 @@ test("unsupported binary schedule requires an explicit format choice", () => {
assert.throws(() => backupSchedulePayload({ ...form, enabled: true, format: "backup" }, ["1"], false))
assert.equal(backupSchedulePayload({ ...form, format: "backup" }, ["1"], false).format, "backup")
})
const storageForm = { provider: "s3" as const, s3Endpoint: "", s3Region: "", s3Bucket: "bucket", s3Prefix: "", s3AccessKeyId: "key", s3SecretAccessKey: "", s3ForcePathStyle: false, keepLocalCopy: false, showPassword: false }
test("S3 requires complete fields, endpoint protocol and a new or existing secret", () => {
assert.throws(() => backupStoragePayload(storageForm))
assert.equal(backupStoragePayload(storageForm, true).s3SecretAccessKey, undefined)
assert.equal(backupStoragePayload({ ...storageForm, s3SecretAccessKey: "new-test-secret" }).s3SecretAccessKey, "new-test-secret")
for (const patch of [{ s3Bucket: " " }, { s3AccessKeyId: " " }, { s3Endpoint: "invalid" }, { s3Endpoint: "ftp://example.test" }, { s3SecretAccessKey: " " }]) assert.throws(() => backupStoragePayload({ ...storageForm, ...patch }, true))
})