Skip to content

Commit

Permalink
feat: add fields to the util (#2026)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaskh3 authored Apr 26, 2024
1 parent 4800b0c commit 2952574
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions controllers/progresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ const { PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, PROGRESS_DOCUMENT_CREATED_SUCCEED

const createProgress = async (req, res) => {
const {
body: { type, completed, planned, blockers },
body: { type, completed, planned, blockers, taskId },
} = req;
try {
const data = await createProgressDocument({ ...req.body, userId: req.userData.id });
await sendTaskUpdate(completed, blockers, planned);
await sendTaskUpdate(completed, blockers, planned, req.userData.username, taskId);
return res.status(201).json({
data,
message: `${type.charAt(0).toUpperCase() + type.slice(1)} ${PROGRESS_DOCUMENT_CREATED_SUCCEEDED}`,
Expand Down
10 changes: 8 additions & 2 deletions test/unit/utils/sendTaskUpdate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ describe("sendTaskUpdate function", function () {
it("should send task update successfully", async function () {
fetchMock.resolves({ ok: true });

const result = await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase");
const result = await sendTaskUpdate(
"Task completed",
"No blockers",
"Plan for the next phase",
"userName",
"taskId"
);
expect(result).to.equal(undefined);
});

it("should throw an error if fails", async function () {
const error = new Error("Error");
fetchMock.rejects(error);
try {
await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase");
await sendTaskUpdate("Task completed", "No blockers", "Plan for the next phase", "userName", "taskId");
} catch (err) {
expect(err).to.be.equal(error);
}
Expand Down
4 changes: 3 additions & 1 deletion utils/sendTaskUpdate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { generateCloudFlareHeaders } from "../utils/discord-actions.js";
const DISCORD_BASE_URL = config.get("services.discordBot.baseUrl");

export const sendTaskUpdate = async (completed, blockers, planned) => {
export const sendTaskUpdate = async (completed, blockers, planned, userName, taskId) => {
try {
const headers = generateCloudFlareHeaders();
const body = {
content: {
completed,
blockers,
planned,
userName,
taskId,
},
};
await fetch(`${DISCORD_BASE_URL}/task/update`, {
Expand Down

0 comments on commit 2952574

Please sign in to comment.