Skip to content

Commit

Permalink
Feat : Added discordJoinedAt key (#214)
Browse files Browse the repository at this point in the history
* Feat : Added discordJoinedAt key

Desc : Passing discordJoinedAt field along with rest of the fields while saving token

* Test : Updated tests based on new payload
  • Loading branch information
joyguptaa authored Apr 4, 2024
1 parent 5a7bcab commit c12626c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/controllers/baseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function baseHandler(
message.member.user.avatar,
message.member.user.username,
message.member.user.discriminator,
message.member.joined_at,
env
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/verifyCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function verifyCommand(
userAvatarHash: string,
userName: string,
discriminator: string,
discordJoinedAt: string,
env: env
) {
const token = await generateUniqueToken();
Expand All @@ -24,6 +25,7 @@ export async function verifyCommand(
userAvatarHash,
userName,
discriminator,
discordJoinedAt,
env
);
if (response?.status === 201 || response?.status === 200) {
Expand Down
1 change: 1 addition & 0 deletions src/typeDefinitions/discordMessage.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface messageRequestDataOptions {
export interface messageRequestMember {
user: messageMember;
nick?: string;
joined_at: string;
}

export interface messageMember {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/sendUserDiscordData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const sendUserDiscordData = async (
userAvatarHash: string,
userName: string,
discriminator: string,
discordJoinedAt: string,
env: env
) => {
const authToken = await jwt.sign(
Expand All @@ -24,6 +25,7 @@ export const sendUserDiscordData = async (
userAvatar: `${DISCORD_AVATAR_BASE_URL}/${discordId}/${userAvatarHash}.jpg`,
userName: userName,
discriminator: discriminator,
discordJoinedAt: discordJoinedAt,
expiry: Date.now() + 1000 * 60 * 2,
},
};
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const dummyHelloMessage: discordMessageRequest = {
avatar: "d1eaa8f8ab5e8235e08e659aef5dfeac",
discriminator: "1234",
},
joined_at: "2021-07-25T19:25:16.172000+00:00",
},
guild_id: 123456,
channel_id: 123456,
Expand All @@ -38,6 +39,7 @@ export const dummyVerifyMessage: discordMessageRequest = {
avatar: "d1eaa8f8ab5e8235e08e659aef5dfeac",
discriminator: "1234",
},
joined_at: "2021-07-25T19:25:16.172000+00:00",
},
guild_id: 123456,
channel_id: 123456,
Expand Down Expand Up @@ -175,6 +177,7 @@ export const discordUserData = {
userAvatar: "https://cdn.discordapp.com/avatars/1/userAvatarHash.jpg",
userName: "userName",
discriminator: "discriminator",
discordJoinedAt: "2021-07-25T19:25:16.172000+00:00",
expiry: mockDateNow + 1000 * 60 * 2,
},
};
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/handlers/verifyCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe("verifyCommand", () => {
"userAvatarHash",
"userName",
"discriminator",
"2021-07-25T19:25:16.172000+00:00",
env
);

Expand Down Expand Up @@ -77,6 +78,7 @@ describe("verifyCommand", () => {
"sjkhdkjashdksjh",
"test user",
"sndbhsbgdj",
"2021-07-25T19:25:16.172000+00:00",
env
);

Expand Down

0 comments on commit c12626c

Please sign in to comment.