From 2952574a5b2519b374faa23766bfacab07cd9c9e Mon Sep 17 00:00:00 2001 From: TEJAS <98630752+tejaskh3@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:58:20 +0530 Subject: [PATCH] feat: add fields to the util (#2026) --- controllers/progresses.js | 4 ++-- test/unit/utils/sendTaskUpdate.test.js | 10 ++++++++-- utils/sendTaskUpdate.js | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/controllers/progresses.js b/controllers/progresses.js index 7dd658d45..41b51a9fb 100644 --- a/controllers/progresses.js +++ b/controllers/progresses.js @@ -46,11 +46,11 @@ const { PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, PROGRESS_DOCUMENT_CREATED_SUCCEED const createProgress = async (req, res) => { const { - body: { type, completed, planned, blockers }, + body: { type, completed, planned, blockers, taskId }, } = req; try { const data = await createProgressDocument({ ...req.body, userId: req.userData.id }); - await sendTaskUpdate(completed, blockers, planned); + await sendTaskUpdate(completed, blockers, planned, req.userData.username, taskId); return res.status(201).json({ data, message: `${type.charAt(0).toUpperCase() + type.slice(1)} ${PROGRESS_DOCUMENT_CREATED_SUCCEEDED}`, diff --git a/test/unit/utils/sendTaskUpdate.test.js b/test/unit/utils/sendTaskUpdate.test.js index 5302fa86c..a44f06ac0 100644 --- a/test/unit/utils/sendTaskUpdate.test.js +++ b/test/unit/utils/sendTaskUpdate.test.js @@ -17,7 +17,13 @@ describe("sendTaskUpdate function", function () { it("should send task update successfully", async function () { fetchMock.resolves({ ok: true }); - const result = await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase"); + const result = await sendTaskUpdate( + "Task completed", + "No blockers", + "Plan for the next phase", + "userName", + "taskId" + ); expect(result).to.equal(undefined); }); @@ -25,7 +31,7 @@ describe("sendTaskUpdate function", function () { const error = new Error("Error"); fetchMock.rejects(error); try { - await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase"); + await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase", "userName", "taskId"); } catch (err) { expect(err).to.be.equal(error); } diff --git a/utils/sendTaskUpdate.js b/utils/sendTaskUpdate.js index d990725c3..933df8ca4 100644 --- a/utils/sendTaskUpdate.js +++ b/utils/sendTaskUpdate.js @@ -1,7 +1,7 @@ import { generateCloudFlareHeaders } from "../utils/discord-actions.js"; const DISCORD_BASE_URL = config.get("services.discordBot.baseUrl"); -export const sendTaskUpdate = async (completed, blockers, planned) => { +export const sendTaskUpdate = async (completed, blockers, planned, userName, taskId) => { try { const headers = generateCloudFlareHeaders(); const body = { @@ -9,6 +9,8 @@ export const sendTaskUpdate = async (completed, blockers, planned) => { completed, blockers, planned, + userName, + taskId, }, }; await fetch(`${DISCORD_BASE_URL}/task/update`, {