@@ -2,34 +2,35 @@ import { environment } from "../../fixtures/config";
2
2
import * as DiscordGroups from "../../../src/utils/fetchDiscordGroupById" ;
3
3
import JSONResponse from "../../../src/utils/JsonResponse" ;
4
4
import { groupInvite } from "../../../src/controllers/groupInvite" ;
5
- import { group } from "../../fixtures/groups" ;
5
+ import { group , invalidGroup } from "../../fixtures/groups" ;
6
6
import { discordTextResponse } from "../../../src/utils/discordResponse" ;
7
7
8
8
describe ( "Test /group-invite command" , ( ) => {
9
- beforeEach ( ( ) => {
10
- jest
11
- . spyOn ( DiscordGroups , "fetchDiscordGroupById" )
12
- . mockImplementation ( ( ) => Promise . resolve ( group ) ) ;
13
- } ) ;
14
-
15
9
afterEach ( ( ) => {
16
10
jest . resetAllMocks ( ) ;
17
11
jest . restoreAllMocks ( ) ;
18
12
} ) ;
19
13
20
14
it ( "Should be an instance of JSONResponse" , async ( ) => {
15
+ jest
16
+ . spyOn ( DiscordGroups , "fetchDiscordGroupById" )
17
+ . mockImplementation ( ( ) => Promise . resolve ( group ) ) ;
18
+
21
19
const response = await groupInvite ( "1" , group . id , environment [ 0 ] ) ;
22
20
23
21
expect ( response ) . toBeInstanceOf ( JSONResponse ) ;
24
22
} ) ;
25
23
26
24
it ( "Should return a discordTextResponse if group is not found" , async ( ) => {
27
- const invalidRoleId = "invalidRoleId" ;
25
+ jest
26
+ . spyOn ( DiscordGroups , "fetchDiscordGroupById" )
27
+ . mockImplementation ( ( ) => Promise . resolve ( invalidGroup ) ) ;
28
+
28
29
const expectedResponse = discordTextResponse (
29
- `<@&${ invalidRoleId } > is not a valid group.`
30
+ `<@&${ invalidGroup . id } > is not a valid group.`
30
31
) ;
31
32
32
- const response = await groupInvite ( "1" , invalidRoleId , environment [ 0 ] ) ;
33
+ const response = await groupInvite ( "1" , invalidGroup . id , environment [ 0 ] ) ;
33
34
34
35
expect ( await response . json ( ) ) . toEqual ( await expectedResponse . json ( ) ) ;
35
36
} ) ;
0 commit comments