@@ -16,6 +16,8 @@ jest.mock('../../services/users', () => ({
16
16
usersWithPermissions : jest . fn ( ) ,
17
17
} ) ) ;
18
18
19
+ jest . mock ( '../../policies/activityReport' ) ;
20
+
19
21
const mockResponse = {
20
22
json : jest . fn ( ) ,
21
23
sendStatus : jest . fn ( ) ,
@@ -49,7 +51,9 @@ describe('Activity Report handlers', () => {
49
51
} ;
50
52
51
53
it ( 'returns the report' , async ( ) => {
52
- ActivityReport . prototype . canUpdate = jest . fn ( ) . mockReturnValue ( true ) ;
54
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
55
+ canUpdate : ( ) => true ,
56
+ } ) ) ;
53
57
createOrUpdate . mockResolvedValue ( report ) ;
54
58
userById . mockResolvedValue ( {
55
59
id : 1 ,
@@ -59,7 +63,9 @@ describe('Activity Report handlers', () => {
59
63
} ) ;
60
64
61
65
it ( 'handles unauthorizedRequests' , async ( ) => {
62
- ActivityReport . prototype . canUpdate = jest . fn ( ) . mockReturnValue ( false ) ;
66
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
67
+ canUpdate : ( ) => false ,
68
+ } ) ) ;
63
69
activityReportById . mockResolvedValue ( report ) ;
64
70
userById . mockResolvedValue ( {
65
71
id : 1 ,
@@ -77,7 +83,9 @@ describe('Activity Report handlers', () => {
77
83
} ;
78
84
79
85
it ( 'returns the created report' , async ( ) => {
80
- ActivityReport . prototype . canCreate = jest . fn ( ) . mockReturnValue ( true ) ;
86
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
87
+ canCreate : ( ) => true ,
88
+ } ) ) ;
81
89
createOrUpdate . mockResolvedValue ( report ) ;
82
90
userById . mockResolvedValue ( {
83
91
id : 1 ,
@@ -93,7 +101,9 @@ describe('Activity Report handlers', () => {
93
101
} ) ;
94
102
95
103
it ( 'handles unauthorized requests' , async ( ) => {
96
- ActivityReport . prototype . canCreate = jest . fn ( ) . mockReturnValue ( false ) ;
104
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
105
+ canCreate : ( ) => false ,
106
+ } ) ) ;
97
107
userById . mockResolvedValue ( {
98
108
id : 1 ,
99
109
} ) ;
@@ -110,7 +120,9 @@ describe('Activity Report handlers', () => {
110
120
} ;
111
121
112
122
it ( 'returns the updated report' , async ( ) => {
113
- ActivityReport . prototype . canUpdate = jest . fn ( ) . mockReturnValue ( true ) ;
123
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
124
+ canUpdate : ( ) => true ,
125
+ } ) ) ;
114
126
activityReportById . mockResolvedValue ( report ) ;
115
127
createOrUpdate . mockResolvedValue ( report ) ;
116
128
userById . mockResolvedValue ( {
@@ -122,7 +134,9 @@ describe('Activity Report handlers', () => {
122
134
123
135
it ( 'handles unauthorized requests' , async ( ) => {
124
136
activityReportById . mockResolvedValue ( report ) ;
125
- ActivityReport . prototype . canUpdate = jest . fn ( ) . mockReturnValue ( false ) ;
137
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
138
+ canUpdate : ( ) => false ,
139
+ } ) ) ;
126
140
userById . mockResolvedValue ( {
127
141
id : 1 ,
128
142
} ) ;
@@ -150,6 +164,9 @@ describe('Activity Report handlers', () => {
150
164
} ;
151
165
152
166
it ( 'returns the report' , async ( ) => {
167
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
168
+ canGet : ( ) => true ,
169
+ } ) ) ;
153
170
activityReportById . mockResolvedValue ( report ) ;
154
171
userById . mockResolvedValue ( {
155
172
id : 1 ,
@@ -167,7 +184,9 @@ describe('Activity Report handlers', () => {
167
184
168
185
it ( 'handles unauthorized requests' , async ( ) => {
169
186
activityReportById . mockResolvedValue ( report ) ;
170
- ActivityReport . prototype . canGet = jest . fn ( ) . mockReturnValue ( false ) ;
187
+ ActivityReport . mockImplementationOnce ( ( ) => ( {
188
+ canGet : ( ) => false ,
189
+ } ) ) ;
171
190
await getReport ( request , mockResponse ) ;
172
191
expect ( mockResponse . sendStatus ) . toHaveBeenCalledWith ( 403 ) ;
173
192
} ) ;
0 commit comments