Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/utils/formatUserDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export function formatUserDetails(userDetails: UserResponseType) {
const userFullName = `**Full Name :** ${userDetails.user?.first_name} ${userDetails.user?.last_name}`;
const discordJoinedAt = `**Joined Server on :** ${convertedTimestamp}`;
const userState = `**State :** ${userDetails.user?.state}`;
const userName = `**UserName :** ${userDetails.user?.username}`;
const userId = `**UserId :** ${userDetails.user?.id}`;

return `## User Details\n${userFullName}\n${discordJoinedAt}\n${userState}`;
return `## User Details\n${userFullName}\n${discordJoinedAt}\n${userState}\n${userName}\n${userId}`;
}
20 changes: 10 additions & 10 deletions tests/fixtures/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const user = {
incompleteUserDetails: false,
discordJoinedAt: "2023-08-08T11:40:42.522000+00:00",
discordId: "858838385330487336",
github_display_name: "Sunny Sahsi",
github_display_name: "John Doe",
updated_at: 1694888822719,
roles: {
archived: false,
Expand All @@ -12,10 +12,10 @@ export const user = {
super_user: false,
archive: false,
},
last_name: "Sahsi",
github_id: "sahsisunny",
first_name: "Sunny",
username: "sunny",
last_name: "Doe",
github_id: "johndoe",
first_name: "John",
username: "johndoe",
state: "ACTIVE",
};

Expand Down Expand Up @@ -179,7 +179,7 @@ export const userWithoutDiscordJoinedAt = {
incompleteUserDetails: false,
discordJoinedAt: "",
discordId: "504855562094247953",
github_display_name: "Jyotsna Mehta",
github_display_name: "John Doe",
updated_at: 1694888822719,
roles: {
archived: false,
Expand All @@ -188,10 +188,10 @@ export const userWithoutDiscordJoinedAt = {
super_user: false,
archive: false,
},
last_name: "Mehta",
github_id: "j24m",
first_name: "Jyotsna",
username: "jyotsna",
last_name: "Doe",
github_id: "johndoe",
first_name: "John",
username: "johndoe",
state: "IDLE",
};

Expand Down
13 changes: 9 additions & 4 deletions tests/unit/utils/formatUserDetails.test.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Can you use dummy user data here

Copy link
Contributor Author

@PeeyushPrashant PeeyushPrashant Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did so because the userFullName and userState also had dummy values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean change the username with a dummy value like john dow, or use Ankush data
as a user can remove from the RDS as Jyotsna is not on RDS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I have added dummy value now

Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@ describe("formatUserDetails function", () => {
it("should format user details correctly", () => {
const formattedDetails = formatUserDetails(userResponse).trim();

const userFullName = `**Full Name :** Sunny Sahsi`;
const userFullName = `**Full Name :** John Doe`;
const discordJoinedAt = `**Joined Server on :** ${convertTimeStamp(
userResponse
)}`;
const userState = `**State :** ACTIVE`;
const userName = `**UserName :** johndoe`;
const userId = `**UserId :** iODXB6ns8jaZB9p0XlBw`;

const expectedFormattedDetails = `## User Details\n${userFullName}\n${discordJoinedAt}\n${userState}`;
const expectedFormattedDetails = `## User Details\n${userFullName}\n${discordJoinedAt}\n${userState}\n${userName}\n${userId}`;
expect(formattedDetails).toEqual(expectedFormattedDetails);
});

it("should return empty string if discordJoinedAt is undefined", () => {
const formattedDetails = formatUserDetails(
userWithoutDiscordJoinedAtResponse
).trim();
const userFullName = `**Full Name :** Jyotsna Mehta`;

const userFullName = `**Full Name :** John Doe`;
const discordJoinedAt = `**Joined Server on :** ${convertTimeStamp(
userWithoutDiscordJoinedAtResponse
)}`;
const userState = `**State :** IDLE`;
const expectedFormattedDetails = `## User Details\n${userFullName}\n${discordJoinedAt}\n${userState}`;
const userName = `**UserName :** johndoe`;
const userId = `**UserId :** DWcTUhbC5lRXfDjZRp06`;
const expectedFormattedDetails = `## User Details\n${userFullName}\n${discordJoinedAt}\n${userState}\n${userName}\n${userId}`;
expect(formattedDetails).toEqual(expectedFormattedDetails);
});
});
Loading