Skip to content

Commit

Permalink
Merge branch 'develop' into bugFix/discord-role-vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
Achintya-Chatterjee authored Mar 7, 2024
2 parents 641643b + 4f20eed commit 854467e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
38 changes: 38 additions & 0 deletions test/unit/utils/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,50 @@ describe("users", function () {
expect(nickname).to.be.equal(`${username.substring(0, usernameLen)} ${oooMessage}`);
});

it("should return first letters of nickname in capital case of the mavens with from and until date when username, from and until OOO dates are passed", async function () {
const { username } = userData;
const from = new Date();
const until = new Date();
const nickname = usersUtils.generateOOONickname(username, from.getTime(), until.getTime(), [
config.get("discordMavenRoleId"),
]);

const fromDate = from.getDate();
const untilDate = until.getDate();
const fromMonth = months[from.getMonth()];
const untilMonth = months[until.getMonth()];

const oooMessage = `(OOO ${fromMonth} ${fromDate} - ${untilMonth} ${untilDate})`;
const oooMessageLen = oooMessage.length;
const usernameLen = discordNicknameLength - oooMessageLen - 1;
expect(nickname).to.be.equal(
`${username
.split("-")
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join("-")
.substring(0, usernameLen)} ${oooMessage}`
);
});
it("should return username of the user as nickname when only username is passed and not from and until date ", async function () {
const { username } = userData;
const nickname = usersUtils.generateOOONickname(username);

expect(nickname).to.be.equal(username);
});

it("should return first letters of nickname in capital case of the mavens as nickname when only username is passed and not from and until date ", async function () {
const { username } = userData;
const nickname = usersUtils.generateOOONickname(username, undefined, undefined, [
config.get("discordMavenRoleId"),
]);

expect(nickname).to.be.equal(
username
.split("-")
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join("-")
);
});
});

describe("updateNickname", function () {
Expand Down
12 changes: 11 additions & 1 deletion utils/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,17 @@ const parseSearchQuery = (queryString) => {
* @param {string} username - The discord username of the user.
* @returns {string} - Nickname of the user.
*/
const generateOOONickname = (username = "", from, until) => {
const generateOOONickname = (currentUsername = "", from, until, discordRoles) => {
// TODO : Update this function when we start storing the discord roles in the database
let username = currentUsername;
const discordMavenRoleId = config.get("discordMavenRoleId");

if (discordRoles?.includes(discordMavenRoleId)) {
username = username
.split("-")
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join("-");
}
if (!from && !until) return username;
const untilDate = new Date(Number(until));
const untilDay = untilDate.getDate();
Expand Down

0 comments on commit 854467e

Please sign in to comment.