Skip to content

Commit

Permalink
unit test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy committed Mar 8, 2024
1 parent 0149ac3 commit f9d2961
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 97 deletions.
10 changes: 5 additions & 5 deletions src/server/utils/notifications/send-notification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
})
Expand All @@ -45,15 +45,15 @@ 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)
expect(post).toHaveBeenCalledTimes(1)
})
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [],
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export const gchatDegradationTemplate = (scenarioName: string, url) => {
subtitle: `Performance Degradation Detected for scenario: ${scenarioName}`,
imageUrl: "",
},
sections: [{
widgets: [],
}],
sections: [],
}],
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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" },
}],
})
})
})

0 comments on commit f9d2961

Please sign in to comment.