Skip to content

Commit bdef426

Browse files
authored
Merge pull request #220 from Real-Dev-Squad/issue-219-online-users-filter
2 parents 3d82b14 + b0f91cd commit bdef426

File tree

5 files changed

+67
-51
lines changed

5 files changed

+67
-51
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"lint-fix": "eslint --fix .",
1414
"format-check": "echo 'Checking the formatting of your code 👨‍💻' && prettier --check . && echo '✅ code matches prettier formatting'",
1515
"format-fix": "prettier --write .",
16+
"fix": "npm run lint-fix && npm run format-fix",
1617
"ngrok": "ngrok http 8787",
1718
"register": "ts-node-esm src/register.ts"
1819
},

src/handlers/scheduledEventHandler.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { env } from "../typeDefinitions/default.types";
22
import { taskOverDueDiscordMembers } from "../utils/taskOverDueDiscordMembers";
3-
import * as error from "../constants/responses";
4-
import { getDiscordIds } from "../utils/getDiscordIds";
53
import config from "../../config/config";
64
import { SUPER_USER_ONE, SUPER_USER_TWO } from "../constants/variables";
75

86
export async function send(env: env): Promise<void> {
97
try {
10-
const assigneeIds: string[] | string = await taskOverDueDiscordMembers();
8+
const discordIds: string[] = await taskOverDueDiscordMembers();
119

12-
//A user might have more than one task which are running red
13-
//so to mention them just once, we are using Set to filter out
14-
const discordIds: string[] | string = await getDiscordIds(assigneeIds);
15-
const uniqueDiscordIds = [...new Set(discordIds)];
10+
const superUsers = [SUPER_USER_ONE, SUPER_USER_TWO];
11+
const filteredDiscordIds = discordIds.filter(
12+
(id) => !superUsers.includes(id)
13+
);
14+
15+
if (filteredDiscordIds.length === 0) {
16+
return;
17+
}
1618

1719
//notifying the two users with the authority.
1820
let stringToBeSent = `<@${SUPER_USER_ONE}> <@${SUPER_USER_TWO}>\nThese people have their task running red:\n`;
1921

2022
let forFormatting = 0;
21-
uniqueDiscordIds.forEach((id) => {
23+
filteredDiscordIds.forEach((id: string) => {
2224
const discordUser = `<@${id}> `;
2325
stringToBeSent += discordUser;
2426
forFormatting++;
@@ -35,7 +37,7 @@ export async function send(env: env): Promise<void> {
3537

3638
const url = config(env).TRACKING_CHANNEL_URL;
3739

38-
const res = await fetch(url, {
40+
await fetch(url, {
3941
method: "POST",
4042
body: JSON.stringify(bodyObj),
4143
headers: {

src/utils/taskOverDueDiscordMembers.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import { RDS_BASE_API_URL } from "../constants/urls";
2-
import {
3-
TaskOverdue,
4-
TaskOverdueResponse,
5-
} from "../typeDefinitions/taskOverdue.types";
6-
import * as errors from "../constants/responses";
2+
import { UserOverdueTaskResponseType } from "../typeDefinitions/rdsUser";
73

8-
export const taskOverDueDiscordMembers = async (): Promise<
9-
string[] | string
10-
> => {
4+
export const taskOverDueDiscordMembers = async (): Promise<string[]> => {
115
try {
12-
const overDueUrl = `${RDS_BASE_API_URL}/tasks?dev=true&status=overdue&size=100`;
6+
const overDueUrl = `${RDS_BASE_API_URL}/users?query=filterBy:overdue_tasks`;
137

148
const response: Response = await fetch(overDueUrl);
15-
const responseObj: TaskOverdueResponse = await response.json();
9+
const responseObj: UserOverdueTaskResponseType = await response.json();
1610

17-
const assigneeIds: string[] = responseObj.tasks.map(
18-
(task: TaskOverdue) => task.assigneeId
11+
const discordIds: string[] = responseObj.users.map(
12+
(user) => user.discordId
1913
);
2014

21-
return assigneeIds;
15+
return discordIds;
2216
} catch (e) {
2317
console.log(e);
2418
throw e;

tests/fixtures/fixture.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -245,30 +245,6 @@ export const userBackendMock: UserBackend = {
245245
},
246246
};
247247

248-
export const taskOverdueMock: TaskOverdueResponse = {
249-
message: "Tasks returned Successfully",
250-
tasks: [
251-
{
252-
id: "1234567",
253-
percentCompleted: 60,
254-
endsOn: "1686528000",
255-
isNoteworthy: false,
256-
createdBy: "random",
257-
assignee: "vineeeet",
258-
title: "task dependsOn",
259-
type: "feature",
260-
status: "SMOKE_TESTING",
261-
assigneeId: "12345",
262-
dependsOn: [
263-
"1NtgKz4lzyiGMHSyBWje",
264-
" HdRj3T603v0L5Pn80GUq",
265-
" C29GgTuPWK32UqcyImsA",
266-
],
267-
startedOn: "1686527000",
268-
},
269-
],
270-
};
271-
272248
export const userStatusMock: UserStatus = {
273249
id: "someId",
274250
userId: "someUserId",
@@ -327,3 +303,45 @@ export const memberGroupRoleResponseList = [
327303
{ userid: "YYYY", roleid: "YYYY", success: true },
328304
{ userid: "ZZZZ", roleid: "ZZZZ", success: true },
329305
];
306+
307+
export const overdueTaskUsers = {
308+
message: "Users returned successfully!",
309+
count: 7,
310+
users: [
311+
{
312+
id: "XAF7rSUvk4p0d098qWYS",
313+
discordId: "154585730465660929",
314+
username: "ankush",
315+
},
316+
{
317+
id: "C2XUDSTtDooWLJ44iBYr",
318+
discordId: "875289457589379102",
319+
username: "vinayak-g",
320+
},
321+
{
322+
id: "DU3gRW3xQY8lRt3DmF6i",
323+
discordId: "987654321098765432",
324+
username: "random_user1",
325+
},
326+
{
327+
id: "wH5f1kuYp3vRZydF70sA",
328+
discordId: "123456789012345678",
329+
username: "random_user2",
330+
},
331+
{
332+
id: "jV8d5ZbEDJc7Mnq6a2g9",
333+
discordId: "567890123456789012",
334+
username: "random_user3",
335+
},
336+
{
337+
id: "qX2zOyB1n7PmIv6TcR8w",
338+
discordId: "890123456789012345",
339+
username: "random_user4",
340+
},
341+
{
342+
id: "pY6cVuA2b5sHgNq9fJ3m",
343+
discordId: "345678901234567890",
344+
username: "random_user5",
345+
},
346+
],
347+
};

tests/unit/utils/taskOverDueDiscordMembers.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { taskOverDueDiscordMembers } from "../../../src/utils/taskOverDueDiscordMembers";
2-
import { taskOverdueMock } from "../../fixtures/fixture";
2+
import { overdueTaskUsers } from "../../fixtures/fixture";
33
import JSONResponse from "../../../src/utils/JsonResponse";
44
import { RDS_BASE_API_URL } from "../../../src/constants/urls";
55

66
describe("taskOverDueDiscordMembers()", () => {
77
test("should return all the tasks which are overdue", async () => {
8-
const mockResponse = taskOverdueMock;
8+
const mockResponse = overdueTaskUsers;
99
jest
1010
.spyOn(global, "fetch")
1111
.mockImplementation(() =>
1212
Promise.resolve(new JSONResponse(mockResponse))
1313
);
1414
const result = await taskOverDueDiscordMembers();
15+
const discordIds = mockResponse.users.map((user) => user.discordId);
1516

16-
expect(result).toEqual([taskOverdueMock.tasks[0].assigneeId]);
17+
expect(result).toEqual(discordIds);
1718

1819
expect(global.fetch).toHaveBeenCalledWith(
19-
`${RDS_BASE_API_URL}/tasks?dev=true&status=overdue&size=100`
20+
`${RDS_BASE_API_URL}/users?query=filterBy:overdue_tasks`
2021
);
2122

2223
expect(global.fetch).toBeCalledTimes(1);
@@ -34,7 +35,7 @@ describe("taskOverDueDiscordMembers()", () => {
3435
}
3536

3637
expect(global.fetch).toHaveBeenCalledWith(
37-
`${RDS_BASE_API_URL}/tasks?dev=true&status=overdue&size=100`
38+
`${RDS_BASE_API_URL}/users?query=filterBy:overdue_tasks`
3839
);
3940
});
4041
});

0 commit comments

Comments
 (0)