Skip to content

Commit bd40805

Browse files
committed
fixed response interface
1 parent df25822 commit bd40805

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/constants/responses.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ export const INTERNAL_SERVER_ERROR =
2121

2222
export const RETRY_COMMAND =
2323
"Oops, we didn't catch that! Please use the command again.";
24+
25+
export const ROLE_ADDED = "Role added successfully";

src/controllers/guildRoleHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function createGuildRoleHandler(request: IRequest, env: env) {
2222
const body: createNewRole = await request.json();
2323

2424
const res = await createGuildRole(body, env);
25+
console.log(res);
2526
return new JSONResponse(res);
2627
} catch (err) {
2728
return new JSONResponse(response.BAD_SIGNATURE);

src/typeDefinitions/discordMessage.types.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,17 @@ export interface memberGroupRole {
3838
userid: string;
3939
roleid: string;
4040
}
41+
42+
export interface guildRoleResponse {
43+
id: string;
44+
name: string;
45+
color: number;
46+
hoist: boolean;
47+
icon?: string;
48+
unicode_emoji?: string;
49+
position: number;
50+
permissions: string;
51+
managed: boolean;
52+
mentionable: boolean;
53+
tags?: object;
54+
}

src/utils/guildRole.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { INTERNAL_SERVER_ERROR } from "../constants/responses";
1+
import { INTERNAL_SERVER_ERROR, ROLE_ADDED } from "../constants/responses";
22
import { DISCORD_BASE_URL } from "../constants/urls";
33
import { env } from "../typeDefinitions/default.types";
44
import {
55
createNewRole,
6+
guildRoleResponse,
67
memberGroupRole,
78
} from "../typeDefinitions/discordMessage.types";
89

9-
export async function createGuildRole(body: createNewRole, env: env) {
10+
export async function createGuildRole(
11+
body: createNewRole,
12+
env: env
13+
): Promise<guildRoleResponse | string> {
1014
const createGuildRoleUrl = `${DISCORD_BASE_URL}/guilds/${env.DISCORD_GUILD_ID}/roles`;
1115
const data = {
1216
...body,
@@ -43,7 +47,7 @@ export async function addGroupRole(body: memberGroupRole, env: env) {
4347
},
4448
});
4549
if (response.ok) {
46-
return { message: "Role added successfully" };
50+
return { message: ROLE_ADDED };
4751
} else {
4852
return INTERNAL_SERVER_ERROR;
4953
}

tests/unit/guildRole.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("createGuildRole", () => {
4545

4646
const result = await createGuildRole(dummyCreateBody, guildEnv);
4747

48-
expect(result).toEqual({});
48+
expect(result).toEqual(mockResponse);
4949
expect(global.fetch).toHaveBeenCalledWith(
5050
`https://discord.com/api/v10/guilds/${guildEnv.DISCORD_GUILD_ID}/roles`,
5151
{

0 commit comments

Comments
 (0)