Skip to content

Commit bdbb0c6

Browse files
authored
feat: add more feilds to send for API (#222)
* feat: add more feilds to send for API * feat: add env url and userName * refactor: change taske update message * refactor: change task update message * refactor: add a line before complted
1 parent 4aec478 commit bdbb0c6

File tree

8 files changed

+77
-19
lines changed

8 files changed

+77
-19
lines changed

config/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
RDS_TRACKING_CHANNEL_URL,
1010
DEVELOPMENT_RDS_TRACKING_CHANNEL_URL,
1111
STAGING_RDS_TRACKING_CHANNEL_URL,
12+
RDS_STATUS_SITE_URL,
13+
RDS_STAGING_STATUS_SITE_URL,
1214
} from "../src/constants/urls";
1315
import {
1416
DISCORD_PROFILE_SERVICE_HELP_GROUP,
@@ -23,19 +25,22 @@ const config = (env: env) => {
2325
VERIFICATION_SITE_URL: VERIFICATION_SITE_URL,
2426
TRACKING_CHANNEL_URL: RDS_TRACKING_CHANNEL_URL,
2527
PROFILE_SERVICE_HELP_GROUP_ID: DISCORD_PROFILE_SERVICE_HELP_GROUP,
28+
RDS_STATUS_SITE_URL: RDS_STATUS_SITE_URL,
2629
},
2730
staging: {
2831
RDS_BASE_API_URL: RDS_BASE_STAGING_API_URL,
2932
VERIFICATION_SITE_URL: STAGING_VERIFICATION_SITE_URL,
3033
TRACKING_CHANNEL_URL: STAGING_RDS_TRACKING_CHANNEL_URL,
3134
PROFILE_SERVICE_HELP_GROUP_ID: DISCORD_PROFILE_SERVICE_STAGING_HELP_GROUP,
35+
RDS_STATUS_SITE_URL: RDS_STAGING_STATUS_SITE_URL,
3236
},
3337
default: {
3438
RDS_BASE_API_URL: RDS_BASE_DEVELOPMENT_API_URL,
3539
VERIFICATION_SITE_URL: DEVELOPMENT_VERIFICATION_SITE_URL,
3640
TRACKING_CHANNEL_URL: DEVELOPMENT_RDS_TRACKING_CHANNEL_URL,
3741
PROFILE_SERVICE_HELP_GROUP_ID:
3842
DISCORD_PROFILE_SERVICE_DEVELOPMENT_HELP_GROUP,
43+
RDS_STATUS_SITE_URL: RDS_STATUS_SITE_URL,
3944
},
4045
};
4146

src/constants/urls.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export const DEVELOPMENT_RDS_TRACKING_CHANNEL_URL =
2020
"https://discord.com/api/v10/channels/1136583634845962261/messages";
2121

2222
export const RDS_STATUS_SITE_URL = "https://status.realdevsquad.com";
23+
export const RDS_STAGING_STATUS_SITE_URL =
24+
"https://staging-status.realdevsquad.com";

src/controllers/taskUpdatesHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const sendTaskUpdatesHandler = async (request: IRequest, env: env) => {
1414
try {
1515
await verifyNodejsBackendAuthToken(authHeader, env);
1616
const updates: TaskUpdates = await request.json();
17-
const { completed, planned, blockers } = updates.content;
18-
await sendTaskUpdate(completed, planned, blockers, env);
17+
const { completed, planned, blockers, userName, taskId } = updates.content;
18+
await sendTaskUpdate(completed, planned, blockers, userName, taskId, env);
1919
return new JSONResponse(
2020
"Task update sent on Discord's tracking-updates channel."
2121
);

src/typeDefinitions/default.types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface variables {
1111
VERIFICATION_SITE_URL: string;
1212
TRACKING_CHANNEL_URL: string;
1313
PROFILE_SERVICE_HELP_GROUP_ID: string;
14+
RDS_STATUS_SITE_URL: string;
1415
}
1516

1617
export interface discordCommand {

src/typeDefinitions/taskUpdate.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ export interface TaskUpdates {
33
completed: string;
44
planned: string;
55
blockers: string;
6+
userName: string;
7+
taskId: string;
68
};
79
}

src/utils/sendTaskUpdates.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ export async function sendTaskUpdate(
55
completed: string,
66
planned: string,
77
blockers: string,
8+
userName: string,
9+
taskId: string,
810
env: env
911
): Promise<void> {
10-
const formattedString = `**Completed**: ${completed}\n\n**Planned**: ${planned}\n\n**Blockers**: ${blockers}`;
12+
const taskUrl = config(env).RDS_STATUS_SITE_URL + `/tasks/${taskId}`;
13+
const formattedString =
14+
`${userName} added an update to their task: <${taskUrl}>\n` +
15+
`\n**Completed**\n${completed}\n\n` +
16+
`**Planned**\n${planned}\n\n` +
17+
`**Blockers**\n${blockers}`;
1118
const bodyObj = {
1219
content: formattedString,
1320
};

tests/unit/handlers/taskUpdateHandler.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ describe("sendTaskUpdatesHandler", () => {
1919
completed: "Wrote test cases",
2020
planned: "Will test the feature at staging.",
2121
blockers: "NA",
22+
userName: "12345678910",
23+
taskId: "79wMEIek990",
2224
},
2325
};
2426
afterEach(() => {
2527
jest.clearAllMocks();
2628
});
2729

2830
it("sendTaskUpdate function should return undefined after successfully sending the message", async () => {
29-
const { completed, planned, blockers } = mockData.content;
31+
const { completed, planned, blockers, userName, taskId } = mockData.content;
3032
const response = await sendTaskUpdate(
3133
completed,
3234
planned,
3335
blockers,
36+
userName,
37+
taskId,
3438
mockEnv
3539
);
3640
expect(response).toBe(undefined);

tests/unit/utils/sendTasksUpdates.test.ts

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ describe("sendTaskUpdate function", () => {
77
const completed = "Task completed successfully";
88
const planned = "Plan for the next phase";
99
const blockers = "No blockers";
10-
10+
const userName = "Tejas";
11+
const taskId = "69nduIn210";
12+
const taskUrl = config(mockEnv).RDS_STATUS_SITE_URL + `/tasks/${taskId}`;
1113
const assertFetchCall = (url: string, bodyObj: any, mockEnv: any) => {
1214
expect(global.fetch).toHaveBeenCalledWith(url, {
1315
method: "POST",
@@ -25,7 +27,11 @@ describe("sendTaskUpdate function", () => {
2527

2628
test("should send the task update to discord tracking channel when all fields are present", async () => {
2729
const url = config(mockEnv).TRACKING_CHANNEL_URL;
28-
const formattedString = `**Completed**: ${completed}\n\n**Planned**: ${planned}\n\n**Blockers**: ${blockers}`;
30+
const formattedString =
31+
`${userName} added an update to their task: <${taskUrl}>\n` +
32+
`\n**Completed**\n${completed}\n\n` +
33+
`**Planned**\n${planned}\n\n` +
34+
`**Blockers**\n${blockers}`;
2935
const bodyObj = {
3036
content: formattedString,
3137
};
@@ -34,14 +40,25 @@ describe("sendTaskUpdate function", () => {
3440
.spyOn(global, "fetch")
3541
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
3642

37-
await sendTaskUpdate(completed, planned, blockers, mockEnv);
43+
await sendTaskUpdate(
44+
completed,
45+
planned,
46+
blockers,
47+
userName,
48+
taskId,
49+
mockEnv
50+
);
3851

3952
assertFetchCall(url, bodyObj, mockEnv);
4053
});
4154

4255
test("should send the task update to discord tracking channel when only completed is present", async () => {
4356
const url = config(mockEnv).TRACKING_CHANNEL_URL;
44-
const formattedString = `**Completed**: ${completed}\n\n**Planned**: \n\n**Blockers**: `;
57+
const formattedString =
58+
`${userName} added an update to their task: <${taskUrl}>\n` +
59+
`\n**Completed**\n${completed}\n\n` +
60+
`**Planned**\n\n\n` +
61+
`**Blockers**\n`;
4562
const bodyObj = {
4663
content: formattedString,
4764
};
@@ -50,14 +67,18 @@ describe("sendTaskUpdate function", () => {
5067
.spyOn(global, "fetch")
5168
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
5269

53-
await sendTaskUpdate(completed, "", "", mockEnv);
70+
await sendTaskUpdate(completed, "", "", userName, taskId, mockEnv);
5471

5572
assertFetchCall(url, bodyObj, mockEnv);
5673
});
5774

5875
test("should send the task update to discord tracking channel when only planned is present", async () => {
5976
const url = config(mockEnv).TRACKING_CHANNEL_URL;
60-
const formattedString = `**Completed**: \n\n**Planned**: ${planned}\n\n**Blockers**: `;
77+
const formattedString =
78+
`${userName} added an update to their task: <${taskUrl}>\n` +
79+
`\n**Completed**\n\n\n` +
80+
`**Planned**\n${planned}\n\n` +
81+
`**Blockers**\n`;
6182
const bodyObj = {
6283
content: formattedString,
6384
};
@@ -66,14 +87,18 @@ describe("sendTaskUpdate function", () => {
6687
.spyOn(global, "fetch")
6788
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
6889

69-
await sendTaskUpdate("", planned, "", mockEnv);
90+
await sendTaskUpdate("", planned, "", userName, taskId, mockEnv);
7091

7192
assertFetchCall(url, bodyObj, mockEnv);
7293
});
7394

7495
test("should send the task update to discord tracking channel when only blockers is present", async () => {
7596
const url = config(mockEnv).TRACKING_CHANNEL_URL;
76-
const formattedString = `**Completed**: \n\n**Planned**: \n\n**Blockers**: ${blockers}`;
97+
const formattedString =
98+
`${userName} added an update to their task: <${taskUrl}>\n` +
99+
`\n**Completed**\n\n\n` +
100+
`**Planned**\n\n\n` +
101+
`**Blockers**\n${blockers}`;
77102
const bodyObj = {
78103
content: formattedString,
79104
};
@@ -82,14 +107,18 @@ describe("sendTaskUpdate function", () => {
82107
.spyOn(global, "fetch")
83108
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
84109

85-
await sendTaskUpdate("", "", blockers, mockEnv);
110+
await sendTaskUpdate("", "", blockers, userName, taskId, mockEnv);
86111

87112
assertFetchCall(url, bodyObj, mockEnv);
88113
});
89114

90115
test("should send the task update to discord tracking channel when only completed and planned are present", async () => {
91116
const url = config(mockEnv).TRACKING_CHANNEL_URL;
92-
const formattedString = `**Completed**: ${completed}\n\n**Planned**: ${planned}\n\n**Blockers**: `;
117+
const formattedString =
118+
`${userName} added an update to their task: <${taskUrl}>\n` +
119+
`\n**Completed**\n${completed}\n\n` +
120+
`**Planned**\n${planned}\n\n` +
121+
`**Blockers**\n`;
93122
const bodyObj = {
94123
content: formattedString,
95124
};
@@ -98,14 +127,18 @@ describe("sendTaskUpdate function", () => {
98127
.spyOn(global, "fetch")
99128
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
100129

101-
await sendTaskUpdate(completed, planned, "", mockEnv);
130+
await sendTaskUpdate(completed, planned, "", userName, taskId, mockEnv);
102131

103132
assertFetchCall(url, bodyObj, mockEnv);
104133
});
105134

106135
test("should send the task update to discord tracking channel when only completed and blockers are present", async () => {
107136
const url = config(mockEnv).TRACKING_CHANNEL_URL;
108-
const formattedString = `**Completed**: ${completed}\n\n**Planned**: \n\n**Blockers**: ${blockers}`;
137+
const formattedString =
138+
`${userName} added an update to their task: <${taskUrl}>\n` +
139+
`\n**Completed**\n${completed}\n\n` +
140+
`**Planned**\n\n\n` +
141+
`**Blockers**\n${blockers}`;
109142
const bodyObj = {
110143
content: formattedString,
111144
};
@@ -114,14 +147,18 @@ describe("sendTaskUpdate function", () => {
114147
.spyOn(global, "fetch")
115148
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
116149

117-
await sendTaskUpdate(completed, "", blockers, mockEnv);
150+
await sendTaskUpdate(completed, "", blockers, userName, taskId, mockEnv);
118151

119152
assertFetchCall(url, bodyObj, mockEnv);
120153
});
121154

122155
test("should send the task update to discord tracking channel when only planned and blockers are present", async () => {
123156
const url = config(mockEnv).TRACKING_CHANNEL_URL;
124-
const formattedString = `**Completed**: \n\n**Planned**: ${planned}\n\n**Blockers**: ${blockers}`;
157+
const formattedString =
158+
`${userName} added an update to their task: <${taskUrl}>\n` +
159+
`\n**Completed**\n\n\n` +
160+
`**Planned**\n${planned}\n\n` +
161+
`**Blockers**\n${blockers}`;
125162
const bodyObj = {
126163
content: formattedString,
127164
};
@@ -130,7 +167,7 @@ describe("sendTaskUpdate function", () => {
130167
.spyOn(global, "fetch")
131168
.mockImplementation(() => Promise.resolve(new JSONResponse("")));
132169

133-
await sendTaskUpdate("", planned, blockers, mockEnv);
170+
await sendTaskUpdate("", planned, blockers, userName, taskId, mockEnv);
134171

135172
assertFetchCall(url, bodyObj, mockEnv);
136173
});

0 commit comments

Comments
 (0)