From c12626c3e5488ee34b3f042a907290af673f3d78 Mon Sep 17 00:00:00 2001 From: Joy <56365512+ardourApeX@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:41:07 +0530 Subject: [PATCH] Feat : Added discordJoinedAt key (#214) * Feat : Added discordJoinedAt key Desc : Passing discordJoinedAt field along with rest of the fields while saving token * Test : Updated tests based on new payload --- src/controllers/baseHandler.ts | 1 + src/controllers/verifyCommand.ts | 2 ++ src/typeDefinitions/discordMessage.types.d.ts | 1 + src/utils/sendUserDiscordData.ts | 2 ++ tests/fixtures/fixture.ts | 3 +++ tests/unit/handlers/verifyCommand.test.ts | 2 ++ 6 files changed, 11 insertions(+) diff --git a/src/controllers/baseHandler.ts b/src/controllers/baseHandler.ts index 22219b80..f41087fa 100644 --- a/src/controllers/baseHandler.ts +++ b/src/controllers/baseHandler.ts @@ -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 ); } diff --git a/src/controllers/verifyCommand.ts b/src/controllers/verifyCommand.ts index 93d7a0b2..f430495e 100644 --- a/src/controllers/verifyCommand.ts +++ b/src/controllers/verifyCommand.ts @@ -14,6 +14,7 @@ export async function verifyCommand( userAvatarHash: string, userName: string, discriminator: string, + discordJoinedAt: string, env: env ) { const token = await generateUniqueToken(); @@ -24,6 +25,7 @@ export async function verifyCommand( userAvatarHash, userName, discriminator, + discordJoinedAt, env ); if (response?.status === 201 || response?.status === 200) { diff --git a/src/typeDefinitions/discordMessage.types.d.ts b/src/typeDefinitions/discordMessage.types.d.ts index f46be204..451a712d 100644 --- a/src/typeDefinitions/discordMessage.types.d.ts +++ b/src/typeDefinitions/discordMessage.types.d.ts @@ -73,6 +73,7 @@ export interface messageRequestDataOptions { export interface messageRequestMember { user: messageMember; nick?: string; + joined_at: string; } export interface messageMember { diff --git a/src/utils/sendUserDiscordData.ts b/src/utils/sendUserDiscordData.ts index b906c783..29153f36 100644 --- a/src/utils/sendUserDiscordData.ts +++ b/src/utils/sendUserDiscordData.ts @@ -9,6 +9,7 @@ export const sendUserDiscordData = async ( userAvatarHash: string, userName: string, discriminator: string, + discordJoinedAt: string, env: env ) => { const authToken = await jwt.sign( @@ -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, }, }; diff --git a/tests/fixtures/fixture.ts b/tests/fixtures/fixture.ts index a6aadcbd..ea16d7dc 100644 --- a/tests/fixtures/fixture.ts +++ b/tests/fixtures/fixture.ts @@ -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, @@ -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, @@ -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, }, }; diff --git a/tests/unit/handlers/verifyCommand.test.ts b/tests/unit/handlers/verifyCommand.test.ts index 35dc831b..8f566293 100644 --- a/tests/unit/handlers/verifyCommand.test.ts +++ b/tests/unit/handlers/verifyCommand.test.ts @@ -40,6 +40,7 @@ describe("verifyCommand", () => { "userAvatarHash", "userName", "discriminator", + "2021-07-25T19:25:16.172000+00:00", env ); @@ -77,6 +78,7 @@ describe("verifyCommand", () => { "sjkhdkjashdksjh", "test user", "sndbhsbgdj", + "2021-07-25T19:25:16.172000+00:00", env );