From db8d2ea9c7e820f7039352f8a043fc827fcaa460 Mon Sep 17 00:00:00 2001 From: Joy <56365512+joyguptaa@users.noreply.github.com> Date: Fri, 9 Aug 2024 00:26:38 +0530 Subject: [PATCH 1/2] Chore : Added a delay in mention-each command (#231) Desc : As there is no other way to add a delay in callbacks provided to ctx.waitUntil, faking a promise is the only way left Co-authored-by: Amit Prakash <34869115+iamitprakash@users.noreply.github.com> --- src/utils/guildRole.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/guildRole.ts b/src/utils/guildRole.ts index 11eb34cb..9efb252e 100644 --- a/src/utils/guildRole.ts +++ b/src/utils/guildRole.ts @@ -157,6 +157,7 @@ export async function mentionEachUserInMessage({ }) { const batchSize = 5; let waitTillNextAPICall = 0; + await new Promise((resolve) => setTimeout(resolve, 1000)); try { const failedUsers: Array = []; for (let i = 0; i < userIds.length; i += batchSize) { From 648a7faca30ec767bf41a1d112f5cadc2e260a57 Mon Sep 17 00:00:00 2001 From: Shubham Sharma <68867418+skv93-coder@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:29:28 +0530 Subject: [PATCH 2/2] Fixed passing of undefined in tacking update channel. (#232) Co-authored-by: Shubham Sharma Co-authored-by: Amit Prakash <34869115+iamitprakash@users.noreply.github.com> --- src/controllers/taskUpdatesHandler.ts | 9 ++- src/typeDefinitions/taskUpdate.d.ts | 14 ++-- src/utils/sendTaskUpdates.ts | 18 +++-- tests/unit/handlers/taskUpdateHandler.test.ts | 7 +- tests/unit/utils/sendTasksUpdates.test.ts | 74 ++++++++----------- 5 files changed, 53 insertions(+), 69 deletions(-) diff --git a/src/controllers/taskUpdatesHandler.ts b/src/controllers/taskUpdatesHandler.ts index a509d80a..fda61a3f 100644 --- a/src/controllers/taskUpdatesHandler.ts +++ b/src/controllers/taskUpdatesHandler.ts @@ -13,16 +13,17 @@ export const sendTaskUpdatesHandler = async (request: IRequest, env: env) => { } try { await verifyNodejsBackendAuthToken(authHeader, env); - const updates: TaskUpdates = await request.json(); - const { completed, planned, blockers, userName, taskId, taskTitle } = - updates.content; - await sendTaskUpdate( + const { content } = await request.json(); + const { completed, planned, blockers, userName, taskId, taskTitle, + }: TaskUpdates = content; + await sendTaskUpdate( + { completed, planned, blockers, userName, taskId, taskTitle }, env ); return new JSONResponse(response.TASK_UPDATE_SENT_MESSAGE); diff --git a/src/typeDefinitions/taskUpdate.d.ts b/src/typeDefinitions/taskUpdate.d.ts index a03c8919..bf81b606 100644 --- a/src/typeDefinitions/taskUpdate.d.ts +++ b/src/typeDefinitions/taskUpdate.d.ts @@ -1,10 +1,8 @@ export interface TaskUpdates { - content: { - completed: string; - planned: string; - blockers: string; - userName: string; - taskId: string; - taskTitle: string; - }; + completed: string; + planned: string; + blockers: string; + userName: string; + taskId?: string; + taskTitle?: string; } diff --git a/src/utils/sendTaskUpdates.ts b/src/utils/sendTaskUpdates.ts index 33d5180a..aeaf87da 100644 --- a/src/utils/sendTaskUpdates.ts +++ b/src/utils/sendTaskUpdates.ts @@ -1,18 +1,20 @@ import { env } from "../typeDefinitions/default.types"; import config from "../../config/config"; +import { TaskUpdates } from "../typeDefinitions/taskUpdate"; export async function sendTaskUpdate( - completed: string, - planned: string, - blockers: string, - userName: string, - taskId: string, - taskTitle: string, + { completed, planned, blockers, userName, taskId, taskTitle }: TaskUpdates, env: env ): Promise { - const taskUrl = config(env).RDS_STATUS_SITE_URL + `/tasks/${taskId}`; + const taskUrl = taskId + ? config(env).RDS_STATUS_SITE_URL + `/tasks/${taskId}` + : ""; + + const progressTitle = taskId + ? `**${userName}** added an update to their task: [${taskTitle}](<${taskUrl}>)` + : `**${userName}** added a standup update`; const formattedString = - `**${userName}** added an update to their task: [${taskTitle}](<${taskUrl}>)\n` + + `${progressTitle}\n` + `\n**Completed**\n${completed}\n\n` + `**Planned**\n${planned}\n\n` + `**Blockers**\n${blockers}`; diff --git a/tests/unit/handlers/taskUpdateHandler.test.ts b/tests/unit/handlers/taskUpdateHandler.test.ts index eb61f89a..564483e4 100644 --- a/tests/unit/handlers/taskUpdateHandler.test.ts +++ b/tests/unit/handlers/taskUpdateHandler.test.ts @@ -29,12 +29,7 @@ describe("sendTaskUpdatesHandler", () => { const { completed, planned, blockers, userName, taskId, taskTitle } = mockData.content; const response = await sendTaskUpdate( - completed, - planned, - blockers, - userName, - taskId, - taskTitle, + { completed, planned, blockers, userName, taskId, taskTitle }, mockEnv ); expect(response).toBe(undefined); diff --git a/tests/unit/utils/sendTasksUpdates.test.ts b/tests/unit/utils/sendTasksUpdates.test.ts index 6ffb6c08..e2cec68f 100644 --- a/tests/unit/utils/sendTasksUpdates.test.ts +++ b/tests/unit/utils/sendTasksUpdates.test.ts @@ -44,12 +44,7 @@ describe("sendTaskUpdate function", () => { await expect( sendTaskUpdate( - completed, - planned, - blockers, - userName, - taskId, - taskTitle, + { completed, planned, blockers, userName, taskId, taskTitle }, mockEnv ) ).rejects.toThrowError("Failed to send task update: 400 - Bad Request"); @@ -73,12 +68,7 @@ describe("sendTaskUpdate function", () => { .mockImplementation(() => Promise.resolve(new JSONResponse(""))); await sendTaskUpdate( - completed, - planned, - blockers, - userName, - taskId, - taskTitle, + { completed, planned, blockers, userName, taskId, taskTitle }, mockEnv ); @@ -101,12 +91,7 @@ describe("sendTaskUpdate function", () => { .mockImplementation(() => Promise.resolve(new JSONResponse(""))); await sendTaskUpdate( - completed, - "", - "", - userName, - taskId, - taskTitle, + { completed, planned: "", blockers: "", userName, taskId, taskTitle }, mockEnv ); @@ -128,7 +113,10 @@ describe("sendTaskUpdate function", () => { .spyOn(global, "fetch") .mockImplementation(() => Promise.resolve(new JSONResponse(""))); - await sendTaskUpdate("", planned, "", userName, taskId, taskTitle, mockEnv); + await sendTaskUpdate( + { completed: "", planned, blockers: "", userName, taskId, taskTitle }, + mockEnv + ); assertFetchCall(url, bodyObj, mockEnv); }); @@ -149,12 +137,7 @@ describe("sendTaskUpdate function", () => { .mockImplementation(() => Promise.resolve(new JSONResponse(""))); await sendTaskUpdate( - "", - "", - blockers, - userName, - taskId, - taskTitle, + { completed: "", planned: "", blockers, userName, taskId, taskTitle }, mockEnv ); @@ -177,12 +160,7 @@ describe("sendTaskUpdate function", () => { .mockImplementation(() => Promise.resolve(new JSONResponse(""))); await sendTaskUpdate( - completed, - planned, - "", - userName, - taskId, - taskTitle, + { completed, planned, blockers: "", userName, taskId, taskTitle }, mockEnv ); @@ -205,12 +183,7 @@ describe("sendTaskUpdate function", () => { .mockImplementation(() => Promise.resolve(new JSONResponse(""))); await sendTaskUpdate( - completed, - "", - blockers, - userName, - taskId, - taskTitle, + { completed, planned: "", blockers, userName, taskId, taskTitle }, mockEnv ); @@ -233,15 +206,30 @@ describe("sendTaskUpdate function", () => { .mockImplementation(() => Promise.resolve(new JSONResponse(""))); await sendTaskUpdate( - "", - planned, - blockers, - userName, - taskId, - taskTitle, + { completed: "", planned, blockers, userName, taskId, taskTitle }, mockEnv ); assertFetchCall(url, bodyObj, mockEnv); }); + + test("should send the standup update to discord tracking channel when task id is absent", async () => { + const url = config(mockEnv).TRACKING_CHANNEL_URL; + const formattedString = + `**${userName}** added a standup update\n` + + `\n**Completed**\n${completed}\n\n` + + `**Planned**\n${planned}\n\n` + + `**Blockers**\n${blockers}`; + const bodyObj = { + content: formattedString, + }; + + jest + .spyOn(global, "fetch") + .mockImplementation(() => Promise.resolve(new JSONResponse(""))); + + await sendTaskUpdate({ completed, planned, blockers, userName }, mockEnv); + + assertFetchCall(url, bodyObj, mockEnv); + }); });