Skip to content

Commit 4f20eed

Browse files
authored
Feat : Converting maven's first & last name to uppercase (#1941)
* Feat : Converting maven's first & last name to uppercase * Chore : Added a comment for further implementation
1 parent 2afa3bc commit 4f20eed

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

test/unit/utils/users.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,50 @@ describe("users", function () {
166166
expect(nickname).to.be.equal(`${username.substring(0, usernameLen)} ${oooMessage}`);
167167
});
168168

169+
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 () {
170+
const { username } = userData;
171+
const from = new Date();
172+
const until = new Date();
173+
const nickname = usersUtils.generateOOONickname(username, from.getTime(), until.getTime(), [
174+
config.get("discordMavenRoleId"),
175+
]);
176+
177+
const fromDate = from.getDate();
178+
const untilDate = until.getDate();
179+
const fromMonth = months[from.getMonth()];
180+
const untilMonth = months[until.getMonth()];
181+
182+
const oooMessage = `(OOO ${fromMonth} ${fromDate} - ${untilMonth} ${untilDate})`;
183+
const oooMessageLen = oooMessage.length;
184+
const usernameLen = discordNicknameLength - oooMessageLen - 1;
185+
expect(nickname).to.be.equal(
186+
`${username
187+
.split("-")
188+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
189+
.join("-")
190+
.substring(0, usernameLen)} ${oooMessage}`
191+
);
192+
});
169193
it("should return username of the user as nickname when only username is passed and not from and until date ", async function () {
170194
const { username } = userData;
171195
const nickname = usersUtils.generateOOONickname(username);
172196

173197
expect(nickname).to.be.equal(username);
174198
});
199+
200+
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 () {
201+
const { username } = userData;
202+
const nickname = usersUtils.generateOOONickname(username, undefined, undefined, [
203+
config.get("discordMavenRoleId"),
204+
]);
205+
206+
expect(nickname).to.be.equal(
207+
username
208+
.split("-")
209+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
210+
.join("-")
211+
);
212+
});
175213
});
176214

177215
describe("updateNickname", function () {

utils/users.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,17 @@ const parseSearchQuery = (queryString) => {
246246
* @param {string} username - The discord username of the user.
247247
* @returns {string} - Nickname of the user.
248248
*/
249-
const generateOOONickname = (username = "", from, until) => {
249+
const generateOOONickname = (currentUsername = "", from, until, discordRoles) => {
250+
// TODO : Update this function when we start storing the discord roles in the database
251+
let username = currentUsername;
252+
const discordMavenRoleId = config.get("discordMavenRoleId");
253+
254+
if (discordRoles?.includes(discordMavenRoleId)) {
255+
username = username
256+
.split("-")
257+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
258+
.join("-");
259+
}
250260
if (!from && !until) return username;
251261
const untilDate = new Date(Number(until));
252262
const untilDay = untilDate.getDate();

0 commit comments

Comments
 (0)