@@ -31,6 +31,13 @@ describe("deleteGuildRole", () => {
31
31
} ,
32
32
} ;
33
33
34
+ beforeEach ( ( ) => {
35
+ jest . clearAllMocks ( ) ;
36
+ } ) ;
37
+ afterEach ( ( ) => {
38
+ jest . restoreAllMocks ( ) ;
39
+ } ) ;
40
+
34
41
it ( "should pass the reason to discord as a X-Audit-Log-Reason header if provided" , async ( ) => {
35
42
jest
36
43
. spyOn ( global , "fetch" )
@@ -44,33 +51,22 @@ describe("deleteGuildRole", () => {
44
51
) ;
45
52
} ) ;
46
53
47
- it ( "should return an empty response with 204 status " , async ( ) => {
54
+ it ( "should return ROLE_REMOVED when response is ok " , async ( ) => {
48
55
const mockResponse = new Response ( null , {
49
56
status : 204 ,
50
57
} ) ;
51
- jest
52
- . spyOn ( global , "fetch" )
53
- . mockImplementation ( ( ) => Promise . resolve ( mockResponse ) ) ;
54
- const response = ( await deleteGuildRole ( guildEnv , roleId ) ) as Response ;
55
- expect ( response ) . toEqual ( mockResponse ) ;
56
- expect ( response . status ) . toEqual ( mockResponse . status ) ;
57
- expect ( global . fetch ) . toHaveBeenCalledWith (
58
- deleteGuildRoleUrl ,
59
- mockRequestInit
60
- ) ;
58
+ jest . spyOn ( global , "fetch" ) . mockResolvedValue ( mockResponse ) ;
59
+ const result = await deleteGuildRole ( guildEnv , roleId ) ;
60
+ expect ( result ) . toEqual ( response . ROLE_REMOVED ) ;
61
+ expect ( global . fetch ) . toHaveBeenCalledTimes ( 1 ) ;
61
62
} ) ;
62
63
63
64
it ( "should return INTERNAL_SERVER_ERROR when response is not ok" , async ( ) => {
64
- const mockErrorResponse = new JSONResponse ( response . INTERNAL_SERVER_ERROR ) ;
65
- jest
66
- . spyOn ( global , "fetch" )
67
- . mockImplementation ( ( ) => Promise . resolve ( mockErrorResponse ) ) ;
65
+ const mockErrorResponse = new Response ( response . INTERNAL_SERVER_ERROR ) ;
66
+ jest . spyOn ( global , "fetch" ) . mockRejectedValue ( mockErrorResponse ) ;
68
67
const result = await deleteGuildRole ( guildEnv , roleId ) ;
69
- expect ( result ) . toEqual ( mockErrorResponse ) ;
70
- expect ( global . fetch ) . toHaveBeenCalledWith (
71
- deleteGuildRoleUrl ,
72
- mockRequestInit
73
- ) ;
68
+ expect ( result ) . toEqual ( response . INTERNAL_SERVER_ERROR ) ;
69
+ expect ( global . fetch ) . toHaveBeenCalledTimes ( 1 ) ;
74
70
} ) ;
75
71
} ) ;
76
72
0 commit comments