mirror of
https://github.com/koichixD/uptime-kuma.git
synced 2026-09-04 09:13:21 +00:00
move the maintenance to the utils test
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
const { describe, test } = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const dayjs = require("dayjs");
|
||||
const { SQL_DATETIME_FORMAT } = require("../../src/util");
|
||||
|
||||
dayjs.extend(require("dayjs/plugin/utc"));
|
||||
dayjs.extend(require("dayjs/plugin/customParseFormat"));
|
||||
|
||||
/**
|
||||
* Tests for maintenance date formatting to ensure compatibility with MariaDB/MySQL.
|
||||
* Issue: MariaDB rejects ISO format dates like '2025-12-19T01:04:02.129Z'
|
||||
* Fix: Use SQL_DATETIME_FORMAT ('YYYY-MM-DD HH:mm:ss') instead of toISOString()
|
||||
*/
|
||||
describe("Maintenance Date Format - MariaDB Compatibility", () => {
|
||||
test("SQL_DATETIME_FORMAT constant should match MariaDB format", () => {
|
||||
assert.strictEqual(SQL_DATETIME_FORMAT, "YYYY-MM-DD HH:mm:ss");
|
||||
});
|
||||
|
||||
test("format() produces SQL-compatible datetime string", () => {
|
||||
const current = dayjs.utc("2025-12-19T01:04:02.129Z");
|
||||
const sqlFormat = current.utc().format(SQL_DATETIME_FORMAT);
|
||||
|
||||
assert.strictEqual(sqlFormat, "2025-12-19 01:04:02");
|
||||
});
|
||||
|
||||
test("SQL format does not contain ISO markers (T, Z)", () => {
|
||||
const current = dayjs.utc("2025-12-19T01:04:02.129Z");
|
||||
const sqlFormat = current.utc().format(SQL_DATETIME_FORMAT);
|
||||
|
||||
assert.strictEqual(sqlFormat.includes("T"), false, "SQL format should not contain 'T'");
|
||||
assert.strictEqual(sqlFormat.includes("Z"), false, "SQL format should not contain 'Z'");
|
||||
});
|
||||
|
||||
test("SQL format matches YYYY-MM-DD HH:mm:ss pattern", () => {
|
||||
const current = dayjs.utc("2025-12-19T01:04:02.129Z");
|
||||
const sqlFormat = current.utc().format(SQL_DATETIME_FORMAT);
|
||||
const sqlDateTimeRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
|
||||
|
||||
assert.strictEqual(sqlDateTimeRegex.test(sqlFormat), true);
|
||||
});
|
||||
|
||||
test("parsing SQL datetime back to dayjs preserves timestamp", () => {
|
||||
const originalDate = dayjs.utc("2025-12-19T01:04:02.000Z");
|
||||
const sqlFormat = originalDate.utc().format(SQL_DATETIME_FORMAT);
|
||||
const parsedDate = dayjs.utc(sqlFormat, SQL_DATETIME_FORMAT);
|
||||
|
||||
assert.strictEqual(parsedDate.unix(), originalDate.unix());
|
||||
});
|
||||
|
||||
test("formats midnight timestamp correctly", () => {
|
||||
const midnight = dayjs.utc("2025-01-01T00:00:00.000Z");
|
||||
const sqlFormat = midnight.utc().format(SQL_DATETIME_FORMAT);
|
||||
|
||||
assert.strictEqual(sqlFormat, "2025-01-01 00:00:00");
|
||||
});
|
||||
|
||||
test("formats end of day timestamp correctly", () => {
|
||||
const endOfDay = dayjs.utc("2025-12-31T23:59:59.999Z");
|
||||
const sqlFormat = endOfDay.utc().format(SQL_DATETIME_FORMAT);
|
||||
|
||||
assert.strictEqual(sqlFormat, "2025-12-31 23:59:59");
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,12 @@
|
||||
const { describe, test } = require("node:test");
|
||||
const assert = require("node:assert");
|
||||
const dayjs = require("dayjs");
|
||||
|
||||
const { getDaysRemaining, getDaysBetween } = require("../../server/util-server");
|
||||
const { SQL_DATETIME_FORMAT } = require("../../src/util");
|
||||
|
||||
dayjs.extend(require("dayjs/plugin/utc"));
|
||||
dayjs.extend(require("dayjs/plugin/customParseFormat"));
|
||||
|
||||
describe("Server Utilities", () => {
|
||||
test("getDaysBetween() calculates days between dates within same month", () => {
|
||||
@@ -23,4 +28,19 @@ describe("Server Utilities", () => {
|
||||
const days = getDaysRemaining(new Date(2025, 9, 10), new Date(2025, 9, 7));
|
||||
assert.strictEqual(days, -3);
|
||||
});
|
||||
|
||||
test("SQL_DATETIME_FORMAT constant matches MariaDB/MySQL format", () => {
|
||||
assert.strictEqual(SQL_DATETIME_FORMAT, "YYYY-MM-DD HH:mm:ss");
|
||||
});
|
||||
|
||||
test("SQL_DATETIME_FORMAT produces valid SQL datetime string", () => {
|
||||
const current = dayjs.utc("2025-12-19T01:04:02.129Z");
|
||||
const sqlFormat = current.utc().format(SQL_DATETIME_FORMAT);
|
||||
|
||||
assert.strictEqual(sqlFormat, "2025-12-19 01:04:02");
|
||||
|
||||
// Verify it can be parsed back
|
||||
const parsedDate = dayjs.utc(sqlFormat, SQL_DATETIME_FORMAT);
|
||||
assert.strictEqual(parsedDate.unix(), current.unix());
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user