generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 280
Feat : Discord tag for new users #2535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iamitprakash
merged 19 commits into
RealDevSquad:develop
from
Dhirenderchoudhary:feature_flag_remove_OOO
Jan 15, 2026
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b6865d4
feature flag removed for OOO creation
0c4f174
removed a statement
54cbe71
Revert "feature flag removed for OOO creation"
5aeaa1b
changes for feature flag removal
fbabab8
fixed error
9b4b863
errors fixed
9277da1
everything fixed and checked
3028747
developer new tag added on discord
d8ab3e5
changes
27e3d87
added a comment
b2ff193
fixed IIFE
d50ee8d
test added and roles after /verify
e284f4f
added role verification expectations
c01cf4d
Merge branch 'develop' into feature_flag_remove_OOO
MayankBansal12 9900580
Add individual role assertions for Developer and New roles in externa…
f9a7129
Add assertions for unverified role and individual role checks in exte…
90057d7
Add comprehensive role assertions: unverified removal and negative ex…
9610a43
not equal assertion added
c8e8363
fix: use config for unverified role ID assertion
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ const { usersFromRds, getDiscordMembers } = require("../fixtures/discordResponse | |
| const Sinon = require("sinon"); | ||
| const { INTERNAL_SERVER_ERROR } = require("../../constants/errorMessages"); | ||
| const removeDiscordRoleUtils = require("../../utils/removeDiscordRoleFromUser"); | ||
| const addDiscordRoleUtils = require("../../utils/addDiscordRoleToUser"); | ||
| const firestore = require("../../utils/firestore"); | ||
| const userData = require("../fixtures/user/user")(); | ||
| const userModel = firestore.collection("users"); | ||
|
|
@@ -526,7 +527,7 @@ describe("External Accounts", function () { | |
| }); | ||
| }); | ||
|
|
||
| it("Should return 204 when valid action is provided", async function () { | ||
| it("Should return 204 when valid action is provided and assign Developer and New roles", async function () { | ||
| await externalAccountsModel.addExternalAccountData(externalAccountData[2]); | ||
| const getUserResponseBeforeUpdate = await chai | ||
| .request(app) | ||
|
|
@@ -543,13 +544,24 @@ describe("External Accounts", function () { | |
| message: "Role deleted successfully", | ||
| }); | ||
|
|
||
| const addDiscordRoleStub = Sinon.stub(addDiscordRoleUtils, "addDiscordRoleToUser").resolves({ | ||
| success: true, | ||
| message: "Role added successfully", | ||
| }); | ||
|
|
||
| const response = await chai | ||
| .request(app) | ||
| .patch(`/external-accounts/link/${externalAccountData[2].token}`) | ||
| .query({ action: EXTERNAL_ACCOUNTS_POST_ACTIONS.DISCORD_USERS_SYNC }) | ||
| .set("Cookie", `${cookieName}=${newUserJWT}`); | ||
|
|
||
| expect(response).to.have.status(204); | ||
| expect(response).to.have.status(200); | ||
| expect(response.body).to.have.property("message"); | ||
| expect(response.body.message).to.equal("Your discord profile has been linked successfully"); | ||
|
|
||
| expect(addDiscordRoleStub.calledTwice).to.equal(true); | ||
| expect(addDiscordRoleStub.firstCall.args[2]).to.equal("Developer"); | ||
| expect(addDiscordRoleStub.secondCall.args[2]).to.equal("New"); | ||
|
|
||
| const updatedUserDetails = await chai | ||
| .request(app) | ||
|
|
@@ -561,6 +573,39 @@ describe("External Accounts", function () { | |
| expect(updatedUserDetails.body).to.have.property("discordJoinedAt"); | ||
|
|
||
| removeDiscordRoleStub.restore(); | ||
| addDiscordRoleStub.restore(); | ||
| }); | ||
|
|
||
| it("Should return 500 when addDiscordRole fails after successful verification", async function () { | ||
| await externalAccountsModel.addExternalAccountData(externalAccountData[2]); | ||
|
|
||
| const removeDiscordRoleStub = Sinon.stub(removeDiscordRoleUtils, "removeDiscordRoleFromUser").resolves({ | ||
| success: true, | ||
| message: "Role deleted successfully", | ||
| }); | ||
|
|
||
| const addDiscordRoleStub = Sinon.stub(addDiscordRoleUtils, "addDiscordRoleToUser").rejects( | ||
| new Error("Role assignment failed") | ||
| ); | ||
|
|
||
| const response = await chai | ||
| .request(app) | ||
| .patch(`/external-accounts/link/${externalAccountData[2].token}`) | ||
| .query({ action: EXTERNAL_ACCOUNTS_POST_ACTIONS.DISCORD_USERS_SYNC }) | ||
| .set("Cookie", `${cookieName}=${newUserJWT}`); | ||
|
|
||
| expect(response).to.have.status(500); | ||
| expect(response.body).to.be.an("object"); | ||
| expect(response.body).to.have.property("message"); | ||
| expect(response.body.message).to.equal( | ||
| "Your discord profile has been linked but role assignment failed. Please contact admin" | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expecation for unverified tag and negative expectation for new and dev roles are missing |
||
|
|
||
| expect(removeDiscordRoleStub.calledOnce).to.equal(true); | ||
| expect(addDiscordRoleStub.called).to.equal(true); | ||
|
|
||
| removeDiscordRoleStub.restore(); | ||
| addDiscordRoleStub.restore(); | ||
| }); | ||
|
|
||
| it("Should return 500 when removeDiscordRole fails because role doesn't exist", async function () { | ||
|
|
||
This file contains hidden or 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,101 @@ | ||
| import chai from "chai"; | ||
| import Sinon from "sinon"; | ||
| import { logType } from "../../../constants/logs"; | ||
| import { addLog } from "../../../models/logs"; | ||
| import firestore from "../../../utils/firestore"; | ||
| import { addDiscordRoleToUser } from "../../../utils/addDiscordRoleToUser"; | ||
| import discordServices from "../../../services/discordService"; | ||
| import cleanDb from "../../utils/cleanDb"; | ||
| const { expect } = chai; | ||
| const logsModel = firestore.collection("logs"); | ||
|
|
||
| describe("addDiscordRoleToUser", function () { | ||
| let discordId; | ||
| let roleid; | ||
| let addRoleToUserStub; | ||
|
|
||
| beforeEach(async function () { | ||
| discordId = "1234567890"; | ||
| roleid = "9876543210"; | ||
| addRoleToUserStub = Sinon.stub(discordServices, "addRoleToUser"); | ||
| }); | ||
|
|
||
| afterEach(async function () { | ||
| await cleanDb(); | ||
| addRoleToUserStub.restore(); | ||
| }); | ||
|
|
||
| it("should add discord role successfully", async function () { | ||
| await addLog( | ||
| logType.ADD_ROLE_TO_USER_SUCCESS, | ||
| { roleId: roleid, discordId: discordId }, | ||
| { message: "Developer role added successfully to user" } | ||
| ); | ||
|
|
||
| addRoleToUserStub.returns( | ||
| Promise.resolve({ success: true, message: "Role added successfully" }) | ||
| ); | ||
|
|
||
| const isDiscordRoleAdded = await addDiscordRoleToUser(discordId, roleid, "Developer"); | ||
| const successLog = await logsModel | ||
| .where("type", "==", logType.ADD_ROLE_TO_USER_SUCCESS) | ||
| .where("meta.roleId", "==", roleid) | ||
| .where("meta.discordId", "==", discordId) | ||
| .limit(1) | ||
| .get(); | ||
|
|
||
| expect(isDiscordRoleAdded.success).to.be.equal(true); | ||
| expect(isDiscordRoleAdded.message).to.be.equal("Developer role added successfully"); | ||
| expect(successLog.docs[0].data().body.message).to.be.equal("Developer role added successfully to user"); | ||
| }); | ||
|
|
||
| it("should return failure when discord service returns unsuccessful response", async function () { | ||
| addRoleToUserStub.returns( | ||
| Promise.resolve({ success: false, message: "Role not found" }) | ||
| ); | ||
|
|
||
| const isDiscordRoleAdded = await addDiscordRoleToUser(discordId, roleid, "New"); | ||
| const failedLog = await logsModel | ||
| .where("type", "==", logType.ADD_ROLE_TO_USER_FAILED) | ||
| .where("meta.roleId", "==", roleid) | ||
| .where("meta.discordId", "==", discordId) | ||
| .limit(1) | ||
| .get(); | ||
|
|
||
| expect(isDiscordRoleAdded.success).to.be.equal(false); | ||
| expect(isDiscordRoleAdded.message).to.include("Adding New role to discord failed"); | ||
| expect(failedLog.docs[0].data().body.message).to.include("Adding New role to discord failed"); | ||
| }); | ||
|
|
||
| it("should throw an error if adding role to discord failed", async function () { | ||
| addRoleToUserStub.rejects(new Error("Discord API error")); | ||
|
|
||
| const isDiscordRoleAdded = await addDiscordRoleToUser(discordId, roleid, "Developer"); | ||
| const failedLog = await logsModel | ||
| .where("type", "==", logType.ADD_ROLE_TO_USER_FAILED) | ||
| .where("meta.roleId", "==", roleid) | ||
| .where("meta.discordId", "==", discordId) | ||
| .limit(1) | ||
| .get(); | ||
|
|
||
| expect(isDiscordRoleAdded.success).to.be.equal(false); | ||
| expect(isDiscordRoleAdded.message).to.be.equal("Discord API error"); | ||
| expect(failedLog.docs[0].data().body.message).to.be.equal("Discord API error"); | ||
| }); | ||
|
|
||
| it("should handle unknown error response from discord service", async function () { | ||
| addRoleToUserStub.returns(Promise.resolve({ success: false })); | ||
|
|
||
| const isDiscordRoleAdded = await addDiscordRoleToUser(discordId, roleid, "Developer"); | ||
| const failedLog = await logsModel | ||
| .where("type", "==", logType.ADD_ROLE_TO_USER_FAILED) | ||
| .where("meta.roleId", "==", roleid) | ||
| .where("meta.discordId", "==", discordId) | ||
| .limit(1) | ||
| .get(); | ||
|
|
||
| expect(isDiscordRoleAdded.success).to.be.equal(false); | ||
| expect(isDiscordRoleAdded.message).to.include("Unknown error"); | ||
| expect(failedLog.docs[0].data().body.message).to.include("Unknown error"); | ||
| }); | ||
| }); |
Dhirenderchoudhary marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,44 @@ | ||
| import { logType } from "../constants/logs"; | ||
| import { addLog } from "../models/logs"; | ||
| import discordServices from "../services/discordService"; | ||
|
|
||
| const logger = require("./logger"); | ||
|
|
||
Dhirenderchoudhary marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Adds a Discord role to a user using Discord Id. | ||
| * | ||
| * @param {string} discordId - User's Discord ID. | ||
| * @param {string} roleId - Discord Role ID. | ||
| * @param {string} roleName - Role name for logging purposes. | ||
| * | ||
| * @returns {Promise<{ success: boolean; message: string }>} - Result with success status and message. | ||
| */ | ||
| export const addDiscordRoleToUser = async ( | ||
| discordId: string, | ||
| roleId: string, | ||
| roleName: string = "role" | ||
| ): Promise<{ success: boolean; message: string }> => { | ||
| try { | ||
| const response = await discordServices.addRoleToUser(discordId, roleId); | ||
|
|
||
| if (!response.success) { | ||
| const message = `Adding ${roleName} role to discord failed: ${response.message || "Unknown error"}`; | ||
| await addLog(logType.ADD_ROLE_TO_USER_FAILED, { roleId, discordId }, { message }); | ||
| return { success: false, message }; | ||
| } | ||
|
|
||
| await addLog( | ||
| logType.ADD_ROLE_TO_USER_SUCCESS, | ||
| { roleId, discordId }, | ||
| { message: `${roleName} role added successfully to user` } | ||
| ); | ||
|
|
||
| return { success: true, message: `${roleName} role added successfully` }; | ||
| } catch (error) { | ||
| const msg = error instanceof Error ? error.message : String(error); | ||
| logger.error(`Error adding role ${roleId} for user ${discordId}: ${msg}`); | ||
| await addLog(logType.ADD_ROLE_TO_USER_FAILED, { roleId, discordId }, { message: msg }); | ||
|
|
||
| return { success: false, message: msg }; | ||
| } | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.