Skip to content

Commit

Permalink
feat: add more feilds to send for API (#222)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tejaskh3 authored Apr 26, 2024
1 parent 4aec478 commit bdbb0c6
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 19 deletions.
5 changes: 5 additions & 0 deletions config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
RDS_TRACKING_CHANNEL_URL,
DEVELOPMENT_RDS_TRACKING_CHANNEL_URL,
STAGING_RDS_TRACKING_CHANNEL_URL,
RDS_STATUS_SITE_URL,
RDS_STAGING_STATUS_SITE_URL,
} from "../src/constants/urls";
import {
DISCORD_PROFILE_SERVICE_HELP_GROUP,
Expand All @@ -23,19 +25,22 @@ const config = (env: env) => {
VERIFICATION_SITE_URL: VERIFICATION_SITE_URL,
TRACKING_CHANNEL_URL: RDS_TRACKING_CHANNEL_URL,
PROFILE_SERVICE_HELP_GROUP_ID: DISCORD_PROFILE_SERVICE_HELP_GROUP,
RDS_STATUS_SITE_URL: RDS_STATUS_SITE_URL,
},
staging: {
RDS_BASE_API_URL: RDS_BASE_STAGING_API_URL,
VERIFICATION_SITE_URL: STAGING_VERIFICATION_SITE_URL,
TRACKING_CHANNEL_URL: STAGING_RDS_TRACKING_CHANNEL_URL,
PROFILE_SERVICE_HELP_GROUP_ID: DISCORD_PROFILE_SERVICE_STAGING_HELP_GROUP,
RDS_STATUS_SITE_URL: RDS_STAGING_STATUS_SITE_URL,
},
default: {
RDS_BASE_API_URL: RDS_BASE_DEVELOPMENT_API_URL,
VERIFICATION_SITE_URL: DEVELOPMENT_VERIFICATION_SITE_URL,
TRACKING_CHANNEL_URL: DEVELOPMENT_RDS_TRACKING_CHANNEL_URL,
PROFILE_SERVICE_HELP_GROUP_ID:
DISCORD_PROFILE_SERVICE_DEVELOPMENT_HELP_GROUP,
RDS_STATUS_SITE_URL: RDS_STATUS_SITE_URL,
},
};

Expand Down
2 changes: 2 additions & 0 deletions src/constants/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export const DEVELOPMENT_RDS_TRACKING_CHANNEL_URL =
"https://discord.com/api/v10/channels/1136583634845962261/messages";

export const RDS_STATUS_SITE_URL = "https://status.realdevsquad.com";
export const RDS_STAGING_STATUS_SITE_URL =
"https://staging-status.realdevsquad.com";
4 changes: 2 additions & 2 deletions src/controllers/taskUpdatesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const sendTaskUpdatesHandler = async (request: IRequest, env: env) => {
try {
await verifyNodejsBackendAuthToken(authHeader, env);
const updates: TaskUpdates = await request.json();
const { completed, planned, blockers } = updates.content;
await sendTaskUpdate(completed, planned, blockers, env);
const { completed, planned, blockers, userName, taskId } = updates.content;
await sendTaskUpdate(completed, planned, blockers, userName, taskId, env);
return new JSONResponse(
"Task update sent on Discord's tracking-updates channel."
);
Expand Down
1 change: 1 addition & 0 deletions src/typeDefinitions/default.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface variables {
VERIFICATION_SITE_URL: string;
TRACKING_CHANNEL_URL: string;
PROFILE_SERVICE_HELP_GROUP_ID: string;
RDS_STATUS_SITE_URL: string;
}

export interface discordCommand {
Expand Down
2 changes: 2 additions & 0 deletions src/typeDefinitions/taskUpdate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export interface TaskUpdates {
completed: string;
planned: string;
blockers: string;
userName: string;
taskId: string;
};
}
9 changes: 8 additions & 1 deletion src/utils/sendTaskUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ export async function sendTaskUpdate(
completed: string,
planned: string,
blockers: string,
userName: string,
taskId: string,
env: env
): Promise<void> {
const formattedString = `**Completed**: ${completed}\n\n**Planned**: ${planned}\n\n**Blockers**: ${blockers}`;
const taskUrl = config(env).RDS_STATUS_SITE_URL + `/tasks/${taskId}`;
const formattedString =
`${userName} added an update to their task: <${taskUrl}>\n` +
`\n**Completed**\n${completed}\n\n` +
`**Planned**\n${planned}\n\n` +
`**Blockers**\n${blockers}`;
const bodyObj = {
content: formattedString,
};
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/handlers/taskUpdateHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ describe("sendTaskUpdatesHandler", () => {
completed: "Wrote test cases",
planned: "Will test the feature at staging.",
blockers: "NA",
userName: "12345678910",
taskId: "79wMEIek990",
},
};
afterEach(() => {
jest.clearAllMocks();
});

it("sendTaskUpdate function should return undefined after successfully sending the message", async () => {
const { completed, planned, blockers } = mockData.content;
const { completed, planned, blockers, userName, taskId } = mockData.content;
const response = await sendTaskUpdate(
completed,
planned,
blockers,
userName,
taskId,
mockEnv
);
expect(response).toBe(undefined);
Expand Down
67 changes: 52 additions & 15 deletions tests/unit/utils/sendTasksUpdates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ describe("sendTaskUpdate function", () => {
const completed = "Task completed successfully";
const planned = "Plan for the next phase";
const blockers = "No blockers";

const userName = "Tejas";
const taskId = "69nduIn210";
const taskUrl = config(mockEnv).RDS_STATUS_SITE_URL + `/tasks/${taskId}`;
const assertFetchCall = (url: string, bodyObj: any, mockEnv: any) => {
expect(global.fetch).toHaveBeenCalledWith(url, {
method: "POST",
Expand All @@ -25,7 +27,11 @@ describe("sendTaskUpdate function", () => {

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

await sendTaskUpdate(completed, planned, blockers, mockEnv);
await sendTaskUpdate(
completed,
planned,
blockers,
userName,
taskId,
mockEnv
);

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

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

await sendTaskUpdate(completed, "", "", mockEnv);
await sendTaskUpdate(completed, "", "", userName, taskId, mockEnv);

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

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

await sendTaskUpdate("", planned, "", mockEnv);
await sendTaskUpdate("", planned, "", userName, taskId, mockEnv);

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

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

await sendTaskUpdate("", "", blockers, mockEnv);
await sendTaskUpdate("", "", blockers, userName, taskId, mockEnv);

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

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

await sendTaskUpdate(completed, planned, "", mockEnv);
await sendTaskUpdate(completed, planned, "", userName, taskId, mockEnv);

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

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

await sendTaskUpdate(completed, "", blockers, mockEnv);
await sendTaskUpdate(completed, "", blockers, userName, taskId, mockEnv);

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

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

await sendTaskUpdate("", planned, blockers, mockEnv);
await sendTaskUpdate("", planned, blockers, userName, taskId, mockEnv);

assertFetchCall(url, bodyObj, mockEnv);
});
Expand Down

0 comments on commit bdbb0c6

Please sign in to comment.