File tree Expand file tree Collapse file tree 11 files changed +135
-14
lines changed Expand file tree Collapse file tree 11 files changed +135
-14
lines changed Original file line number Diff line number Diff line change 10
10
- run : npm install
11
11
- run : npm run lint-check
12
12
- run : npm run format-check
13
- - run : npm test
Original file line number Diff line number Diff line change
1
+ name : pre-merge-checks
2
+ on :
3
+ pull_request :
4
+ branches : [main, develop]
5
+ jobs :
6
+ Run-Tests :
7
+ runs-on : ubuntu-latest
8
+ steps :
9
+ - uses : actions/checkout@v2
10
+ - run : npm install
11
+ - run : npm test
Original file line number Diff line number Diff line change @@ -6,3 +6,10 @@ export interface discordCommand {
6
6
name : string ;
7
7
description : string ;
8
8
}
9
+
10
+ export interface responseJson {
11
+ type : number ;
12
+ data : {
13
+ content : string ;
14
+ } ;
15
+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export interface discordMessageRequest {
7
7
8
8
export interface messageRequestData {
9
9
name : string ;
10
- options : Array < messageRequestDataOptions > ;
10
+ options ? : Array < messageRequestDataOptions > ;
11
11
}
12
12
13
13
export interface messageRequestDataOptions {
Original file line number Diff line number Diff line change
1
+ import { discordMessageRequest } from "../../src/typeDefinitions/discordMessage.types" ;
2
+ import { InteractionType } from "discord-interactions" ;
3
+
4
+ export const dummyHelloMessage : discordMessageRequest = {
5
+ type : InteractionType . APPLICATION_COMMAND ,
6
+ data : {
7
+ name : "Hello" ,
8
+ } ,
9
+ member : {
10
+ user : {
11
+ id : 123456 ,
12
+ username : "ritik" ,
13
+ } ,
14
+ } ,
15
+ guild_id : 123456 ,
16
+ } ;
17
+
18
+ export const dummyVerifyMessage : discordMessageRequest = {
19
+ type : InteractionType . APPLICATION_COMMAND ,
20
+ data : {
21
+ name : "VERIFY" ,
22
+ } ,
23
+ member : {
24
+ user : {
25
+ id : 123456 ,
26
+ username : "ritik" ,
27
+ } ,
28
+ } ,
29
+ guild_id : 123456 ,
30
+ } ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import { InteractionResponseType } from "discord-interactions" ;
2
+ import { responseJson } from "../../src/typeDefinitions/default.types" ;
3
+ import { discordTextResponse } from "../../src/utils/discordResponse" ;
4
+ import JSONResponse from "../../src/utils/JsonResponse" ;
5
+
6
+ describe ( "Test discordResponse function" , ( ) => {
7
+ it ( "should return a JSONResponse" , ( ) => {
8
+ const response = discordTextResponse ( "Hello" ) ;
9
+ expect ( response ) . toBeInstanceOf ( JSONResponse ) ;
10
+ } ) ;
11
+ it ( "Should have type as channelMessageWithSource" , async ( ) => {
12
+ const response : responseJson = await discordTextResponse ( "Hello" ) . json ( ) ;
13
+ expect ( response ?. type ) . toBe (
14
+ InteractionResponseType . CHANNEL_MESSAGE_WITH_SOURCE
15
+ ) ;
16
+ } ) ;
17
+ it ( "Should contain a content property in data" , async ( ) => {
18
+ const response : responseJson = await discordTextResponse ( "Hello" ) . json ( ) ;
19
+ expect ( response ?. data ) . toHaveProperty ( "content" ) ;
20
+ } ) ;
21
+ it ( "Should have content as hello" , async ( ) => {
22
+ const response : responseJson = await discordTextResponse ( "Hello" ) . json ( ) ;
23
+ expect ( response ?. data . content ) . toBe ( "Hello" ) ;
24
+ } ) ;
25
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { HELLO , VERIFY } from "../../src/constants/commands" ;
2
+ import { getCommandName } from "../../src/utils/getCommandName" ;
3
+
4
+ describe ( "Test getCommandName function" , ( ) => {
5
+ it ( "Returns hello command name in lower case" , ( ) => {
6
+ const commandName = getCommandName ( HELLO ) ;
7
+ expect ( commandName ) . toBe ( "hello" ) ;
8
+ } ) ;
9
+ it ( "Returns Verify command name in lower case" , ( ) => {
10
+ const commandName = getCommandName ( VERIFY ) ;
11
+ expect ( commandName ) . toBe ( "verify" ) ;
12
+ } ) ;
13
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { commandNotFound } from "../../../src/controllers/commandNotFound" ;
2
+ import { responseJson } from "../../../src/typeDefinitions/default.types" ;
3
+ import JSONResponse from "../../../src/utils/JsonResponse" ;
4
+
5
+ describe ( "Test CommandNotFound Handler" , ( ) => {
6
+ it ( "Should return an instance of JSONResponse" , ( ) => {
7
+ const response = commandNotFound ( ) ;
8
+ expect ( response ) . toBeInstanceOf ( JSONResponse ) ;
9
+ } ) ;
10
+ it ( "Should contain text 'Command Not Found'" , async ( ) => {
11
+ const response : responseJson = await commandNotFound ( ) . json ( ) ;
12
+ expect ( response . data . content ) . toBe ( "Command Not Found" ) ;
13
+ } ) ;
14
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { InteractionResponseType } from "discord-interactions" ;
2
+ import { helloCommand } from "../../../src/controllers/helloCommand" ;
3
+ import { responseJson } from "../../../src/typeDefinitions/default.types" ;
4
+ import JSONResponse from "../../../src/utils/JsonResponse" ;
5
+
6
+ describe ( "Test helloCommand function" , ( ) => {
7
+ it ( "Should be an instance of JSONResponse" , ( ) => {
8
+ const response = helloCommand ( 1234 ) ;
9
+ expect ( response ) . toBeInstanceOf ( JSONResponse ) ;
10
+ } ) ;
11
+ it ( "Should have type as channelMessageWithSource" , async ( ) => {
12
+ const response : responseJson = await helloCommand ( 1234 ) . json ( ) ;
13
+ expect ( response ?. type ) . toBe (
14
+ InteractionResponseType . CHANNEL_MESSAGE_WITH_SOURCE
15
+ ) ;
16
+ } ) ;
17
+ it ( "Should have content as 'Hello <@userId>'" , async ( ) => {
18
+ const response : responseJson = await helloCommand ( 1234 ) . json ( ) ;
19
+ expect ( response . data . content ) . toBe ( "Hello <@1234>" ) ;
20
+ } ) ;
21
+ } ) ;
You can’t perform that action at this time.
0 commit comments