diff --git a/src/server/utils/notifications/send-notification.spec.ts b/src/server/utils/notifications/send-notification.spec.ts index 4b4f743..294cf88 100644 --- a/src/server/utils/notifications/send-notification.spec.ts +++ b/src/server/utils/notifications/send-notification.spec.ts @@ -3,11 +3,11 @@ import { sendReportNotifications } from "./send-notification" const linkUrl = require("./link-url") import axios from "axios" const scenarioNotifications = require("../../queries/scenario") -const msTeamsTemplate = require("./templates/ms-teams-template") +const msTeamsTemplate = require("./templates/report/ms-teams-template") jest.mock("axios") -jest.mock("./templates/ms-teams-template") +jest.mock("./templates/report/ms-teams-template") jest.mock("../../../db/db") const OVERVIEW = { @@ -33,7 +33,7 @@ describe("sendNotification", () => { expect(spy).toHaveBeenCalledTimes(1) }) it("should trigger `scenarioNotifications` query", async () => { - const spy = jest.spyOn(scenarioNotifications, "scenarioNotifications") + const spy = jest.spyOn(scenarioNotifications, "scenarioNotificationsByType") await sendReportNotifications("test", "test", "id", OVERVIEW) expect(spy).toHaveBeenCalledTimes(1) }) @@ -45,7 +45,7 @@ describe("sendNotification", () => { it("should try to send notification request when found in db", async () => { const spy = jest.spyOn(msTeamsTemplate, "msTeamsTemplate") db.manyOrNone = jest.fn().mockImplementation(() => - Promise.resolve([{ url: "test", name: "test-name", type: "ms-teams" }])) + Promise.resolve([{ url: "test", name: "test-name", channel: "ms-teams" }])) const post = axios.post = jest.fn().mockImplementation(() => Promise.resolve({})) await sendReportNotifications("test", "test", "id", OVERVIEW) expect(spy).toHaveBeenCalledTimes(1) @@ -53,7 +53,7 @@ describe("sendNotification", () => { }) it("should not throw an error when request failed", () => { db.manyOrNone = jest.fn().mockImplementation(() => - Promise.resolve([{ url: "test", name: "test-name", type: "ms-teams" }])) + Promise.resolve([{ url: "test", name: "test-name", channel: "ms-teams" }])) axios.post = jest.fn().mockImplementation(() => Promise.reject(new Error("failed"))) expect(async () => { await sendReportNotifications("test", "test", "id", OVERVIEW) diff --git a/src/server/utils/notifications/templates/degradation/gchat-degradation-template.spec.ts b/src/server/utils/notifications/templates/degradation/gchat-degradation-template.spec.ts index 2160f6e..d1b5444 100644 --- a/src/server/utils/notifications/templates/degradation/gchat-degradation-template.spec.ts +++ b/src/server/utils/notifications/templates/degradation/gchat-degradation-template.spec.ts @@ -8,38 +8,10 @@ describe("GChat Degradation template", () => { { header: { imageUrl: "", - subtitle: "Performance Report for scenario: scenarioName", + subtitle: "Performance Degradation Detected for scenario: scenarioName", title: "JTL Reporter", }, sections: [ - { - widgets: [ - { - keyValue: { - content: "0 %", - topLabel: "Error Rate", - }, - }, - { - keyValue: { - content: "10 ms", - topLabel: "90% percentile", - }, - }, - { - keyValue: { - content: "10 reqs/s", - topLabel: "Throughput", - }, - }, - { - keyValue: { - content: "1 min", - topLabel: "Duration", - }, - }, - ], - }, { widgets: [ { @@ -71,39 +43,10 @@ describe("GChat Degradation template", () => { { header: { imageUrl: "", - subtitle: "Performance Report for scenario: scenarioName", + subtitle: "Performance Degradation Detected for scenario: scenarioName", title: "JTL Reporter", }, - sections: [ - { - widgets: [ - { - keyValue: { - content: "0 %", - topLabel: "Error Rate", - }, - }, - { - keyValue: { - content: "10 ms", - topLabel: "90% percentile", - }, - }, - { - keyValue: { - content: "10 reqs/s", - topLabel: "Throughput", - }, - }, - { - keyValue: { - content: "1 min", - topLabel: "Duration", - }, - }, - ], - }, - ], + sections: [], }, ], } diff --git a/src/server/utils/notifications/templates/degradation/gchat-degradation-template.ts b/src/server/utils/notifications/templates/degradation/gchat-degradation-template.ts index 022496e..a5feec1 100644 --- a/src/server/utils/notifications/templates/degradation/gchat-degradation-template.ts +++ b/src/server/utils/notifications/templates/degradation/gchat-degradation-template.ts @@ -7,9 +7,7 @@ export const gchatDegradationTemplate = (scenarioName: string, url) => { subtitle: `Performance Degradation Detected for scenario: ${scenarioName}`, imageUrl: "", }, - sections: [{ - widgets: [], - }], + sections: [], }], } diff --git a/src/server/utils/notifications/templates/degradation/ms-teams-degradation-template.spec.ts b/src/server/utils/notifications/templates/degradation/ms-teams-degradation-template.spec.ts index 1f66f0a..8a48d40 100644 --- a/src/server/utils/notifications/templates/degradation/ms-teams-degradation-template.spec.ts +++ b/src/server/utils/notifications/templates/degradation/ms-teams-degradation-template.spec.ts @@ -16,16 +16,9 @@ describe("MS Teams Degradation template", () => { type: "TextBlock", size: "Medium", weight: "Bolder", - text: "Performance Report for scenario: scenarioName", + text: "Performance Degradation Detected for scenario: scenarioName", }, - { - type: "FactSet", - facts: [ - { title: "Error Rate", value: "0 %" }, - { title: "90% percentile", value: "10 ms" }, - { title: "Throughput", value: "10 reqs/s" }, - { title: "Duration", value: "1 min" }], - }], + ], actions: [ { type: "Action.OpenUrl", title: "View", url: "http://localhost" }], $schema: "http://adaptivecards.io/schemas/adaptive-card.json", @@ -49,16 +42,9 @@ describe("MS Teams Degradation template", () => { type: "TextBlock", size: "Medium", weight: "Bolder", - text: "Performance Report for scenario: scenarioName", + text: "Performance Degradation Detected for scenario: scenarioName", }, - { - type: "FactSet", - facts: [ - { title: "Error Rate", value: "0 %" }, - { title: "90% percentile", value: "10 ms" }, - { title: "Throughput", value: "10 reqs/s" }, - { title: "Duration", value: "1 min" }], - }], + ], actions: [], $schema: "http://adaptivecards.io/schemas/adaptive-card.json", version: "1.2", diff --git a/src/server/utils/notifications/templates/degradation/slack-degradation-template.spec.ts b/src/server/utils/notifications/templates/degradation/slack-degradation-template.spec.ts index acf098b..e087f1b 100644 --- a/src/server/utils/notifications/templates/degradation/slack-degradation-template.spec.ts +++ b/src/server/utils/notifications/templates/degradation/slack-degradation-template.spec.ts @@ -7,12 +7,12 @@ describe("Slack Degradation template", () => { expect(template).toEqual({ blocks: [ { type: "header", text: { type: "plain_text", text: "JTL Reporter" } }, - { type: "header", text: { type: "plain_text", - text: "Performance Report for scenario: scenarioName" } }, - { type: "divider" }, { type: "section", fields: [{ type: "mrkdwn", text: "*Error Rate*\n0%" }] }, - { type: "section", fields: [{ type: "mrkdwn", text: "*90% percentile*\n10 ms" }] }, - { type: "section", fields: [{ type: "mrkdwn", text: "*Throughput*\n10 reqs/s" }] }, - { type: "section", fields: [{ type: "mrkdwn", text: "*Duration*\n1 min" }] }, + { + type: "header", text: { + type: "plain_text", + text: "Performance Degradation Detected for scenario: scenarioName", + }, + }, { type: "section", fields: { @@ -32,11 +32,10 @@ describe("Slack Degradation template", () => { expect(template).toEqual({ blocks: [ { type: "header", text: { type: "plain_text", text: "JTL Reporter" } }, - { type: "header", text: { type: "plain_text", text: "Performance Report for scenario: scenarioName" } }, - { type: "divider" }, { type: "section", fields: [{ type: "mrkdwn", text: "*Error Rate*\n0%" }] }, - { type: "section", fields: [{ type: "mrkdwn", text: "*90% percentile*\n10 ms" }] }, - { type: "section", fields: [{ type: "mrkdwn", text: "*Throughput*\n10 reqs/s" }] }, - { type: "section", fields: [{ type: "mrkdwn", text: "*Duration*\n1 min" }] }], + { + type: "header", + text: { type: "plain_text", text: "Performance Degradation Detected for scenario: scenarioName" }, + }], }) }) })