fix: RSS pubDate timezone issue with backend test (#6422) (#6805)

This commit is contained in:
Taejung Heo
2026-01-25 22:07:36 +09:00
committed by GitHub
parent 0b1161c6fb
commit 0d64cd6915
2 changed files with 38 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ const analytics = require("../analytics/analytics");
const { marked } = require("marked");
const { Feed } = require("feed");
const config = require("../config");
const dayjs = require("dayjs");
const { setting } = require("../util-server");
const {
@@ -100,7 +101,7 @@ class StatusPage extends BeanModel {
description: `${heartbeat.name} has been down since ${heartbeat.time} UTC`,
id: `${heartbeat.monitorID}-${heartbeat.time}`,
link: feedUrl,
date: new Date(heartbeat.time),
date: dayjs.utc(heartbeat.time).toDate(),
});
});

View File

@@ -1,6 +1,8 @@
const { describe, test } = require("node:test");
const { describe, test, mock } = require("node:test");
const assert = require("node:assert");
const StatusPage = require("../../server/model/status_page");
const dayjs = require("dayjs");
const utc = require("dayjs/plugin/utc");
const {
STATUS_PAGE_ALL_UP,
STATUS_PAGE_ALL_DOWN,
@@ -8,6 +10,8 @@ const {
STATUS_PAGE_MAINTENANCE,
} = require("../../src/util");
dayjs.extend(utc);
describe("StatusPage", () => {
describe("getStatusDescription()", () => {
test("returns 'No Services' when status is -1", () => {
@@ -40,4 +44,35 @@ describe("StatusPage", () => {
assert.strictEqual(description, "?");
});
});
describe("renderRSS()", () => {
const MOCK_FEED_URL = "http://localhost:3001/status/test";
test("pubDate uses UTC timezone for heartbeat.time without timezone info", async () => {
const mockStatusPage = {
title: "Test Status Page",
};
const mockHeartbeats = [
{
name: "Test Monitor",
monitorID: 1,
time: "2026-01-24 13:16:25.400",
},
];
mock.method(StatusPage, "getRSSPageData", async () => ({
heartbeats: mockHeartbeats,
statusDescription: "All Systems Operational",
}));
try {
const rss = await StatusPage.renderRSS(mockStatusPage, MOCK_FEED_URL);
assert.ok(rss.includes("<pubDate>Sat, 24 Jan 2026 13:16:25 GMT</pubDate>"));
} finally {
mock.restoreAll();
}
});
});
});