Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev to main sync PR #235

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
1 change: 1 addition & 0 deletions src/utils/guildRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = [];
for (let i = 0; i < userIds.length; i += batchSize) {
Expand Down
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);
});
});
Loading