-
Notifications
You must be signed in to change notification settings - Fork 56
Raised New PR : (https://github.com/Real-Dev-Squad/discord-slash-commands/pull/98) Added description to the message after using /verify #85 #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
aca37fa
f95a299
06c9f84
bdfabf9
d9d2949
63e3d50
954ad0f
5cf1c55
b765c94
0633f27
c2e7fda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
|
||
import jest from 'jest'; | ||
|
||
const jwt = Object.create({}); | ||
|
||
jwt.sign = jest.fn().mockImplementation(() => { | ||
return "asdasd"; | ||
}); | ||
|
||
export default jwt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
type cloudflareWorkerJwtType = { | ||
sign: () => void; | ||
}; | ||
|
||
const cloudflareWorkerJwt:cloudflareWorkerJwtType = jest.createMockFromModule("jsonwebtoken"); | ||
|
||
function sign() { | ||
return "asd"; | ||
} | ||
|
||
cloudflareWorkerJwt.sign = sign; | ||
|
||
export default cloudflareWorkerJwt; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
const crypto = require("crypto"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not require crypto as it is available globally from node 18 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but now te issue is, this require is not allowed but when I am using import it gives the same error:/ |
||
export const generateUniqueToken = async () => { | ||
const uuidToken = crypto.randomUUID(); | ||
const randomNumber = Math.floor(Math.random() * 1000000); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import * as response from "../../../src/constants/responses"; | ||
import { verifyCommand } from "../../../src/controllers/verifyCommand"; | ||
import config from "../../../config/config"; | ||
import JSONResponse from "../../../src/utils/JsonResponse"; | ||
|
||
type Responsetype = { | ||
data: DataType; | ||
type: number; | ||
}; | ||
|
||
type DataType = { | ||
content: string; | ||
flags: number; | ||
}; | ||
describe("verifyCommand", () => { | ||
test("should return INTERNAL_SERVER_ERROR when response is not ok", async () => { | ||
jest.mock("crypto", () => { | ||
return { | ||
randomUUID: jest.fn(() => "shreya"), | ||
subtle: { digest: jest.fn(() => "123") }, | ||
}; | ||
}); | ||
|
||
jest.mock("../../../src/utils/generateUniqueToken", () => ({ | ||
generateUniqueToken: () => Promise.resolve("jashdkjahskajhd"), | ||
})); | ||
|
||
const mockResponse = response.INTERNAL_SERVER_ERROR; | ||
jest | ||
.spyOn(global, "fetch") | ||
.mockImplementation(() => | ||
Promise.resolve(new JSONResponse(mockResponse)) | ||
); | ||
|
||
const env = { | ||
BOT_PUBLIC_KEY: "xyz", | ||
DISCORD_GUILD_ID: "123", | ||
DISCORD_TOKEN: "abc", | ||
}; | ||
|
||
const result = await verifyCommand( | ||
1233434, | ||
"sjkhdkjashdksjh", | ||
"test user", | ||
"sndbhsbgdj", | ||
env | ||
); | ||
|
||
expect(global.fetch).toHaveBeenCalledWith( | ||
`http://localhost:3000/external-accounts`, | ||
expect.objectContaining({ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer asd`, | ||
}, | ||
}) | ||
); | ||
|
||
const response_: Responsetype = await result.json(); | ||
expect(response_.data.content).toContain(""); | ||
}); | ||
|
||
test("should return JSON response when response is ok", async () => { | ||
const mockResponse = {}; | ||
|
||
jest | ||
.spyOn(global, "fetch") | ||
.mockImplementation(() => | ||
Promise.resolve(new JSONResponse(mockResponse)) | ||
); | ||
|
||
const env = { | ||
BOT_PUBLIC_KEY: "xyz", | ||
DISCORD_GUILD_ID: "123", | ||
DISCORD_TOKEN: "abc", | ||
}; | ||
|
||
const result = await verifyCommand( | ||
1233434, | ||
"sjkhdkjashdksjh", | ||
"test user", | ||
"sndbhsbgdj", | ||
env | ||
); | ||
|
||
const verificationSiteURL = config(env).VERIFICATION_SITE_URL; | ||
const message = `${verificationSiteURL}/discord?token=`; | ||
|
||
expect(global.fetch).toHaveBeenCalledWith( | ||
`http://localhost:3000/external-accounts`, | ||
expect.objectContaining({ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer asd`, | ||
}, | ||
}) | ||
); | ||
|
||
const response_: Responsetype = await result.json(); | ||
|
||
expect(response_.data.content).toContain(message); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we installing the jsonwebToken package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to mock cloudfareworker jwt