feat(notifications): enrich Rocket.Chat tests

This commit is contained in:
Marcos Paulo Diniz committed 2026-08-07 14:55:05 -03:00
1 parent 4b921f4986
commit ee25c6b479
2 files changed
+47 -3

No files matched your search

@@ -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<Notification>): Promise<boolean> {
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<boolean> {
if (!notification.address) {
return false;
@@ -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 () => {