Skip to content

Commit 91d187e

Browse files
authored
Merge pull request #235 from Real-Dev-Squad/develop
2 parents e209a4b + 648a7fa commit 91d187e

File tree

5 files changed

+53
-69
lines changed

5 files changed

+53
-69
lines changed

src/controllers/taskUpdatesHandler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ export const sendTaskUpdatesHandler = async (request: IRequest, env: env) => {
1313
}
1414
try {
1515
await verifyNodejsBackendAuthToken(authHeader, env);
16-
const updates: TaskUpdates = await request.json();
17-
const { completed, planned, blockers, userName, taskId, taskTitle } =
18-
updates.content;
19-
await sendTaskUpdate(
16+
const { content } = await request.json();
17+
const {
2018
completed,
2119
planned,
2220
blockers,
2321
userName,
2422
taskId,
2523
taskTitle,
24+
}: TaskUpdates = content;
25+
await sendTaskUpdate(
26+
{ completed, planned, blockers, userName, taskId, taskTitle },
2627
env
2728
);
2829
return new JSONResponse(response.TASK_UPDATE_SENT_MESSAGE);
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
export interface TaskUpdates {
2-
content: {
3-
completed: string;
4-
planned: string;
5-
blockers: string;
6-
userName: string;
7-
taskId: string;
8-
taskTitle: string;
9-
};
2+
completed: string;
3+
planned: string;
4+
blockers: string;
5+
userName: string;
6+
taskId?: string;
7+
taskTitle?: string;
108
}

src/utils/sendTaskUpdates.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { env } from "../typeDefinitions/default.types";
22
import config from "../../config/config";
3+
import { TaskUpdates } from "../typeDefinitions/taskUpdate";
34

45
export async function sendTaskUpdate(
5-
completed: string,
6-
planned: string,
7-
blockers: string,
8-
userName: string,
9-
taskId: string,
10-
taskTitle: string,
6+
{ completed, planned, blockers, userName, taskId, taskTitle }: TaskUpdates,
117
env: env
128
): Promise<void> {
13-
const taskUrl = config(env).RDS_STATUS_SITE_URL + `/tasks/${taskId}`;
9+
const taskUrl = taskId
10+
? config(env).RDS_STATUS_SITE_URL + `/tasks/${taskId}`
11+
: "";
12+
13+
const progressTitle = taskId
14+
? `**${userName}** added an update to their task: [${taskTitle}](<${taskUrl}>)`
15+
: `**${userName}** added a standup update`;
1416
const formattedString =
15-
`**${userName}** added an update to their task: [${taskTitle}](<${taskUrl}>)\n` +
17+
`${progressTitle}\n` +
1618
`\n**Completed**\n${completed}\n\n` +
1719
`**Planned**\n${planned}\n\n` +
1820
`**Blockers**\n${blockers}`;

tests/unit/handlers/taskUpdateHandler.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ describe("sendTaskUpdatesHandler", () => {
2929
const { completed, planned, blockers, userName, taskId, taskTitle } =
3030
mockData.content;
3131
const response = await sendTaskUpdate(
32-
completed,
33-
planned,
34-
blockers,
35-
userName,
36-
taskId,
37-
taskTitle,
32+
{ completed, planned, blockers, userName, taskId, taskTitle },
3833
mockEnv
3934
);
4035
expect(response).toBe(undefined);

tests/unit/utils/sendTasksUpdates.test.ts

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ describe("sendTaskUpdate function", () => {
4444

4545
await expect(
4646
sendTaskUpdate(
47-
completed,
48-
planned,
49-
blockers,
50-
userName,
51-
taskId,
52-
taskTitle,
47+
{ completed, planned, blockers, userName, taskId, taskTitle },
5348
mockEnv
5449
)
5550
).rejects.toThrowError("Failed to send task update: 400 - Bad Request");
@@ -73,12 +68,7 @@ describe("sendTaskUpdate function", () => {
7368
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
7469

7570
await sendTaskUpdate(
76-
completed,
77-
planned,
78-
blockers,
79-
userName,
80-
taskId,
81-
taskTitle,
71+
{ completed, planned, blockers, userName, taskId, taskTitle },
8272
mockEnv
8373
);
8474

@@ -101,12 +91,7 @@ describe("sendTaskUpdate function", () => {
10191
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
10292

10393
await sendTaskUpdate(
104-
completed,
105-
"",
106-
"",
107-
userName,
108-
taskId,
109-
taskTitle,
94+
{ completed, planned: "", blockers: "", userName, taskId, taskTitle },
11095
mockEnv
11196
);
11297

@@ -128,7 +113,10 @@ describe("sendTaskUpdate function", () => {
128113
.spyOn(global, "fetch")
129114
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
130115

131-
await sendTaskUpdate("", planned, "", userName, taskId, taskTitle, mockEnv);
116+
await sendTaskUpdate(
117+
{ completed: "", planned, blockers: "", userName, taskId, taskTitle },
118+
mockEnv
119+
);
132120

133121
assertFetchCall(url, bodyObj, mockEnv);
134122
});
@@ -149,12 +137,7 @@ describe("sendTaskUpdate function", () => {
149137
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
150138

151139
await sendTaskUpdate(
152-
"",
153-
"",
154-
blockers,
155-
userName,
156-
taskId,
157-
taskTitle,
140+
{ completed: "", planned: "", blockers, userName, taskId, taskTitle },
158141
mockEnv
159142
);
160143

@@ -177,12 +160,7 @@ describe("sendTaskUpdate function", () => {
177160
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
178161

179162
await sendTaskUpdate(
180-
completed,
181-
planned,
182-
"",
183-
userName,
184-
taskId,
185-
taskTitle,
163+
{ completed, planned, blockers: "", userName, taskId, taskTitle },
186164
mockEnv
187165
);
188166

@@ -205,12 +183,7 @@ describe("sendTaskUpdate function", () => {
205183
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
206184

207185
await sendTaskUpdate(
208-
completed,
209-
"",
210-
blockers,
211-
userName,
212-
taskId,
213-
taskTitle,
186+
{ completed, planned: "", blockers, userName, taskId, taskTitle },
214187
mockEnv
215188
);
216189

@@ -233,15 +206,30 @@ describe("sendTaskUpdate function", () => {
233206
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
234207

235208
await sendTaskUpdate(
236-
"",
237-
planned,
238-
blockers,
239-
userName,
240-
taskId,
241-
taskTitle,
209+
{ completed: "", planned, blockers, userName, taskId, taskTitle },
242210
mockEnv
243211
);
244212

245213
assertFetchCall(url, bodyObj, mockEnv);
246214
});
215+
216+
test("should send the standup update to discord tracking channel when task id is absent", async () => {
217+
const url = config(mockEnv).TRACKING_CHANNEL_URL;
218+
const formattedString =
219+
`**${userName}** added a standup update\n` +
220+
`\n**Completed**\n${completed}\n\n` +
221+
`**Planned**\n${planned}\n\n` +
222+
`**Blockers**\n${blockers}`;
223+
const bodyObj = {
224+
content: formattedString,
225+
};
226+
227+
jest
228+
.spyOn(global, "fetch")
229+
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
230+
231+
await sendTaskUpdate({ completed, planned, blockers, userName }, mockEnv);
232+
233+
assertFetchCall(url, bodyObj, mockEnv);
234+
});
247235
});

0 commit comments

Comments
 (0)