From ee25c6b47937a9ddc6a4f2e5d0d0904e08cac5c5 Mon Sep 17 00:00:00 2001 From: Marcos Paulo Diniz Date: Thu, 6 Aug 2026 10:55:11 -0300 Subject: [PATCH] feat(notifications): enrich Rocket.Chat tests --- .../notifications/providers/rocketChat.ts | 28 ++++++++++++++++++- .../notifications/rocketChatProvider.test.ts | 22 +++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/server/src/domain/notifications/providers/rocketChat.ts b/server/src/domain/notifications/providers/rocketChat.ts index 345eec8c3..fb2d05003 100644 --- a/server/src/domain/notifications/providers/rocketChat.ts +++ b/server/src/domain/notifications/providers/rocketChat.ts @@ -4,6 +4,16 @@ import { NotificationProvider } from "@/domain/notifications/providers/INotifica import { getTestMessage } from "@/domain/notifications/providers/utils.js"; import got from "got"; +type RocketChatField = { title: string; value: string; short: boolean }; +type RocketChatAttachment = { + color: string; + title: string; + title_link?: string; + fields?: RocketChatField[]; + ts?: string; +}; +type RocketChatPayload = { text: string; attachments: [RocketChatAttachment] }; + export class RocketChatProvider extends NotificationProvider { async sendTestAlert(notification: Partial): Promise { if (!notification.address) { @@ -12,7 +22,7 @@ export class RocketChatProvider extends NotificationProvider { try { await got.post(notification.address, { - json: { text: getTestMessage() }, + json: this.buildTestPayload(), headers: { "Content-Type": "application/json", }, @@ -31,6 +41,22 @@ export class RocketChatProvider extends NotificationProvider { } } + private buildTestPayload(): RocketChatPayload { + return { + text: getTestMessage(), + attachments: [ + { + color: "#0000FF", + title: "Checkmate test notification", + fields: [ + { title: "Channel", value: "Rocket.Chat", short: true }, + { title: "Status", value: "Test notification", short: true }, + ], + }, + ], + }; + } + async sendMessage(notification: Notification, message: NotificationMessage): Promise { if (!notification.address) { return false; diff --git a/server/test/unit/providers/notifications/rocketChatProvider.test.ts b/server/test/unit/providers/notifications/rocketChatProvider.test.ts index ac9ffc4c1..077892353 100644 --- a/server/test/unit/providers/notifications/rocketChatProvider.test.ts +++ b/server/test/unit/providers/notifications/rocketChatProvider.test.ts @@ -25,7 +25,7 @@ testNotificationProviderContract("RocketChatProvider", { describe("RocketChatProvider", () => { beforeEach(() => mockGotPost.mockReset().mockResolvedValue({})); - it("sends a text-only test alert", async () => { + it("sends a rich test alert without webhook overrides", async () => { const { provider } = createProvider(); const result = await provider.sendTestAlert(makeNotification({ type: "rocket_chat" })); @@ -34,11 +34,29 @@ describe("RocketChatProvider", () => { expect(mockGotPost).toHaveBeenCalledWith( "https://hooks.example.com/webhook", expect.objectContaining({ - json: { text: "This is a test notification from Checkmate" }, + json: { + text: "This is a test notification from Checkmate", + attachments: [ + { + color: "#0000FF", + title: "Checkmate test notification", + fields: [ + { title: "Channel", value: "Rocket.Chat", short: true }, + { title: "Status", value: "Test notification", short: true }, + ], + }, + ], + }, timeout: { request: 30000 }, retry: { limit: 0 }, }) ); + + const payload = mockGotPost.mock.calls[0][1].json; + expect(payload).not.toHaveProperty("alias"); + expect(payload).not.toHaveProperty("avatar"); + expect(payload).not.toHaveProperty("emoji"); + expect(payload).not.toHaveProperty("channel"); }); it("returns false when the test webhook URL is missing", async () => {