generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connect discord-slash-command /task/update api (#2016)
* feat: connect discord-slash-command /task/update api * remove: failing test cases * Tests fixed * Tests fixed * feat: add test cases for sendTaskUpdate * refactor * fix parameteres * fix: test case coverage * refactor: fetchStub to fetchMock --------- Co-authored-by: Lakshay Manchanda <lakshaymanchanda73@gmail.com> Co-authored-by: Lakshay Manchanda <45519620+lakshayman@users.noreply.github.com>
- Loading branch information
1 parent
1f4d942
commit 4e3a6d4
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import chai from "chai"; | ||
import sinon from "sinon"; | ||
import { sendTaskUpdate } from "../../../utils/sendTaskUpdate"; | ||
const { expect } = chai; | ||
|
||
describe("sendTaskUpdate function", function () { | ||
let fetchMock; | ||
|
||
beforeEach(function () { | ||
fetchMock = sinon.stub(global, "fetch"); | ||
}); | ||
|
||
afterEach(function () { | ||
fetchMock.restore(); | ||
}); | ||
|
||
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"); | ||
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"); | ||
} catch (err) { | ||
expect(err).to.be.equal(error); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { generateCloudFlareHeaders } from "../utils/discord-actions.js"; | ||
const DISCORD_BASE_URL = config.get("services.discordBot.baseUrl"); | ||
|
||
export const sendTaskUpdate = async (completed, blockers, planned) => { | ||
try { | ||
const headers = generateCloudFlareHeaders(); | ||
const body = { | ||
content: { | ||
completed, | ||
blockers, | ||
planned, | ||
}, | ||
}; | ||
await fetch(`${DISCORD_BASE_URL}/task/update`, { | ||
method: "POST", | ||
headers, | ||
body: JSON.stringify(body), | ||
}); | ||
} catch (error) { | ||
logger.error("Something went wrong", error); | ||
throw error; | ||
} | ||
}; |