Skip to content

Commit

Permalink
Merge pull request #197 from Real-Dev-Squad/develop
Browse files Browse the repository at this point in the history
Dev to main sync
  • Loading branch information
iamitprakash authored Feb 5, 2024
2 parents 2f12023 + 7f07d77 commit 515256d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/register-commands-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
CURRENT_ENVIRONMENT
BOT_PRIVATE_KEY
RDS_SERVERLESS_PUBLIC_KEY
CRON_JOBS_PUBLIC_KEY
env:
CURRENT_ENVIRONMENT: production
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
Expand All @@ -43,3 +44,4 @@ jobs:
BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}}
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}
RDS_SERVERLESS_PUBLIC_KEY: ${{secrets.RDS_SERVERLESS_PUBLIC_KEY}}
CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}}
2 changes: 2 additions & 0 deletions .github/workflows/register-commands-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ jobs:
DISCORD_GUILD_ID
CURRENT_ENVIRONMENT
BOT_PRIVATE_KEY
CRON_JOBS_PUBLIC_KEY
env:
CURRENT_ENVIRONMENT: staging
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
DISCORD_PUBLIC_KEY: ${{secrets.DISCORD_PUBLIC_KEY}}
DISCORD_TOKEN: ${{secrets.DISCORD_TOKEN}}
BOT_PRIVATE_KEY: ${{secrets.BOT_PRIVATE_KEY}}
DISCORD_GUILD_ID: ${{secrets.DISCORD_GUILD_ID}}
CRON_JOBS_PUBLIC_KEY: ${{secrets.CRON_JOBS_PUBLIC_KEY}}
11 changes: 8 additions & 3 deletions src/controllers/guildRoleHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
createNewRole,
memberGroupRole,
} from "../typeDefinitions/discordMessage.types";
import { verifyAuthToken } from "../utils/verifyAuthToken";
import { verifyAuthToken, verifyCronJobsToken } from "../utils/verifyAuthToken";
import { batchDiscordRequests } from "../utils/batchDiscordRequests";
import { DISCORD_BASE_URL } from "../constants/urls";
import { GROUP_ROLE_ADD } from "../constants/requestsActions";
Expand Down Expand Up @@ -59,8 +59,13 @@ export async function getGuildRolesPostHandler(request: IRequest, env: env) {
const reason = request.headers.get("X-Audit-Log-Reason");

try {
await verifyAuthToken(authHeader, env);
const { action } = request.query;
const { action, dev } = request.query;
//TODO(@Ajeyakrishna-k): remove dev flag https://github.com/Real-Dev-Squad/discord-slash-commands/issues/193
if (dev === "true") {
await verifyCronJobsToken(authHeader, env);
} else {
await verifyAuthToken(authHeader, env);
}

switch (action) {
case GROUP_ROLE_ADD.ADD_ROLE: {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const dummyAddRoleBody: memberGroupRole = {
export const guildEnv = {
DISCORD_GUILD_ID: "1234",
DISCORD_TOKEN: "abcd",
CRON_JOBS_PUBLIC_KEY: "test",
};

export const dummyInviteBody = {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/handlers/guildRoleHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { GROUP_ROLE_ADD } from "../../../src/constants/requestsActions";

jest.mock("../../../src/utils/verifyAuthToken", () => ({
verifyAuthToken: jest.fn().mockReturnValue(true),
verifyCronJobsToken: jest.fn().mockReturnValue(true),
}));

const getGuildRolesSpy = jest.spyOn(guildRoleUtils, "getGuildRoles");
Expand Down

0 comments on commit 515256d

Please sign in to comment.