Skip to content

Commit

Permalink
fix response and write test
Browse files Browse the repository at this point in the history
  • Loading branch information
anishpawaskar committed Jan 10, 2024
1 parent 7d09d30 commit e0d0a91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/formatTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export function generateTaskResponseMessage(
formattedTasks: string[],
status: string
) {
const title = `## ${formatStatusToTitleCase(status)} Tasks of ${nickName}`;
const title =
formattedTasks.length !== 0
? `## ${formatStatusToTitleCase(status)} Tasks of ${nickName}`
: `## ${nickName} doesn't have any in-progress task`;
const tasks = formattedTasks.join("\n\n");
const allTaskLink = `[→ All Tasks](${RDS_STATUS_SITE_URL}/tasks?q=status:all+assignee:${nickName})
`;
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/utils/formatTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("Test generateTaskResponseMessage function", () => {

it("Should return a string with task details", () => {
const formattedTasks = tasks.tasks.map((task: task) => formatTask(task));
console.log("format task frm fail", formattedTasks.length);
const responseMessage = generateTaskResponseMessage(
"sunny-s",
formattedTasks,
Expand Down Expand Up @@ -64,4 +65,18 @@ describe("Test generateTaskResponseMessage function", () => {
const expectedResponseMessage = `${expectedMessage}\n${task1}\n\n${task2}\n${allTaskURL}\n`;
expect(responseMessage).toBe(expectedResponseMessage);
});

it("should return a string if user don't have any in-progress task", () => {
const formattedTasks: [] = [];
console.log("format task frm fail", formattedTasks.length);
const responseMessage = generateTaskResponseMessage(
"anish-pawaskar",
formattedTasks,
"IN_PROGRESS"
);
const expectedMessage = `## anish-pawaskar doesn't have any in-progress task`;
const allTaskURL = `[→ All Tasks](https://status.realdevsquad.com/tasks?q=status:all+assignee:anish-pawaskar)`;
const expectedResponseMessage = `${expectedMessage}\n\n${allTaskURL}\n`;
expect(responseMessage).toBe(expectedResponseMessage);
});
});

0 comments on commit e0d0a91

Please sign in to comment.