Skip to content

Commit

Permalink
Merge pull request #235 from Real-Dev-Squad/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
iamitprakash authored Aug 24, 2024
2 parents e209a4b + 648a7fa commit 91d187e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 69 deletions.
9 changes: 5 additions & 4 deletions src/controllers/taskUpdatesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions src/typeDefinitions/taskUpdate.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 10 additions & 8 deletions src/utils/sendTaskUpdates.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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}`;
Expand Down
7 changes: 1 addition & 6 deletions tests/unit/handlers/taskUpdateHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
74 changes: 31 additions & 43 deletions tests/unit/utils/sendTasksUpdates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
);

Expand All @@ -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
);

Expand All @@ -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);
});
Expand All @@ -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
);

Expand All @@ -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
);

Expand All @@ -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
);

Expand All @@ -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);
});
});

0 comments on commit 91d187e

Please sign in to comment.