@@ -88,6 +88,15 @@ describe('Admin controller', () => {
8888 expect ( result ) . toEqual ( expectedResult ) ;
8989 expect ( mockAdminService . findReports ) . toHaveBeenCalledWith ( validatedData ) ;
9090 } ) ;
91+
92+ it ( 'should throw error when validation fails' , async ( ) => {
93+ const ctx = { query : { } } as RequestContext ;
94+ const error = new Error ( 'Validation failed' ) ;
95+
96+ caster < jest . Mock > ( adminValidator . getReportFindReportsValidator ) . mockReturnValue ( { left : error } ) ;
97+
98+ await expect ( getController ( getStrapi ( ) ) . findReports ( ctx ) ) . rejects . toThrow ( ) ;
99+ } ) ;
91100 } ) ;
92101
93102 describe ( 'findOne' , ( ) => {
@@ -141,6 +150,15 @@ describe('Admin controller', () => {
141150 expect ( result ) . toEqual ( expectedResult ) ;
142151 expect ( mockAdminService . changeBlockedComment ) . toHaveBeenCalledWith ( '1' , true ) ;
143152 } ) ;
153+
154+ it ( 'should throw error when validation fails' , async ( ) => {
155+ const ctx = { params : { id : 'invalid' } } as RequestContext < object , { id : string } > ;
156+ const error = new Error ( 'Validation failed' ) ;
157+
158+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
159+
160+ await expect ( getController ( getStrapi ( ) ) . blockComment ( ctx ) ) . rejects . toThrow ( ) ;
161+ } ) ;
144162 } ) ;
145163
146164 describe ( 'resolveAbuseReport' , ( ) => {
@@ -157,6 +175,15 @@ describe('Admin controller', () => {
157175 expect ( result ) . toEqual ( expectedResult ) ;
158176 expect ( mockAdminService . resolveAbuseReport ) . toHaveBeenCalledWith ( validatedData ) ;
159177 } ) ;
178+
179+ it ( 'should throw error when validation fails' , async ( ) => {
180+ const ctx = { params : { id : 'invalid' , reportId : '2' } } as RequestContext < object , { id : string ; reportId : string } > ;
181+ const error = new Error ( 'Validation failed' ) ;
182+
183+ caster < jest . Mock > ( adminValidator . getCommentResolveAbuseReportValidator ) . mockReturnValue ( { left : error } ) ;
184+
185+ await expect ( getController ( getStrapi ( ) ) . resolveAbuseReport ( ctx ) ) . rejects . toThrow ( ) ;
186+ } ) ;
160187 } ) ;
161188
162189 describe ( 'resolveCommentMultipleAbuseReports' , ( ) => {
@@ -209,6 +236,18 @@ describe('Admin controller', () => {
209236 expect ( result ) . toEqual ( expectedResult ) ;
210237 expect ( mockAdminService . postComment ) . toHaveBeenCalledWith ( validatedData ) ;
211238 } ) ;
239+
240+ it ( 'should throw error when validation fails' , async ( ) => {
241+ const ctx = {
242+ params : { id : '1' } ,
243+ request : { body : { content : 'Test content' , author : 'Test author' } }
244+ } as RequestContext < any , any > ;
245+ const error = new Error ( 'Validation failed' ) ;
246+
247+ caster < jest . Mock > ( adminValidator . getCommentPostValidator ) . mockReturnValue ( { left : error } ) ;
248+
249+ await expect ( getController ( getStrapi ( ) ) . postComment ( ctx ) ) . rejects . toThrow ( ) ;
250+ } ) ;
212251 } ) ;
213252
214253 describe ( 'unblockComment' , ( ) => {
@@ -225,6 +264,15 @@ describe('Admin controller', () => {
225264 expect ( result ) . toEqual ( expectedResult ) ;
226265 expect ( mockAdminService . changeBlockedComment ) . toHaveBeenCalledWith ( '1' , false ) ;
227266 } ) ;
267+
268+ it ( 'should throw error when validation fails' , async ( ) => {
269+ const ctx = { params : { id : 'invalid' } } as RequestContext < object , { id : string } > ;
270+ const error = new Error ( 'Validation failed' ) ;
271+
272+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
273+
274+ await expect ( getController ( getStrapi ( ) ) . unblockComment ( ctx ) ) . rejects . toThrow ( ) ;
275+ } ) ;
228276 } ) ;
229277
230278 describe ( 'deleteComment' , ( ) => {
@@ -241,6 +289,15 @@ describe('Admin controller', () => {
241289 expect ( result ) . toEqual ( expectedResult ) ;
242290 expect ( mockAdminService . deleteComment ) . toHaveBeenCalledWith ( '1' ) ;
243291 } ) ;
292+
293+ it ( 'should throw error when validation fails' , async ( ) => {
294+ const ctx = { params : { id : 'invalid' } } as RequestContext < object , { id : string } > ;
295+ const error = new Error ( 'Validation failed' ) ;
296+
297+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
298+
299+ await expect ( getController ( getStrapi ( ) ) . deleteComment ( ctx ) ) . rejects . toThrow ( ) ;
300+ } ) ;
244301 } ) ;
245302
246303 describe ( 'blockCommentThread' , ( ) => {
@@ -257,6 +314,15 @@ describe('Admin controller', () => {
257314 expect ( result ) . toEqual ( expectedResult ) ;
258315 expect ( mockAdminService . blockCommentThread ) . toHaveBeenCalledWith ( '1' , true ) ;
259316 } ) ;
317+
318+ it ( 'should throw error when validation fails' , async ( ) => {
319+ const ctx = { params : { id : 'invalid' } } as RequestContext < object , { id : string } > ;
320+ const error = new Error ( 'Validation failed' ) ;
321+
322+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
323+
324+ await expect ( getController ( getStrapi ( ) ) . blockCommentThread ( ctx ) ) . rejects . toThrow ( ) ;
325+ } ) ;
260326 } ) ;
261327
262328 describe ( 'unblockCommentThread' , ( ) => {
@@ -298,6 +364,15 @@ describe('Admin controller', () => {
298364 expect ( result ) . toEqual ( expectedResult ) ;
299365 expect ( mockAdminService . resolveAllAbuseReportsForComment ) . toHaveBeenCalledWith ( '1' ) ;
300366 } ) ;
367+
368+ it ( 'should throw error when validation fails' , async ( ) => {
369+ const ctx = { params : { id : 'invalid' } } as RequestContext < object , { id : string } > ;
370+ const error = new Error ( 'Validation failed' ) ;
371+
372+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
373+
374+ await expect ( getController ( getStrapi ( ) ) . resolveAllAbuseReportsForComment ( ctx ) ) . rejects . toThrow ( ) ;
375+ } ) ;
301376 } ) ;
302377
303378 describe ( 'resolveAllAbuseReportsForThread' , ( ) => {
@@ -340,6 +415,16 @@ describe('Admin controller', () => {
340415 expect ( result ) . toEqual ( expectedResult ) ;
341416 expect ( mockAdminService . resolveMultipleAbuseReports ) . toHaveBeenCalledWith ( reportIds ) ;
342417 } ) ;
418+
419+ it ( 'should throw error when validation fails' , async ( ) => {
420+ const reportIds = [ 'invalid' ] ;
421+ const ctx = { request : { body : reportIds } } as RequestContext < Array < string > > ;
422+ const error = new Error ( 'Validation failed' ) ;
423+
424+ caster < jest . Mock > ( adminValidator . getReportsMultipleAbuseValidator ) . mockReturnValue ( { left : error } ) ;
425+
426+ await expect ( getController ( getStrapi ( ) ) . resolveMultipleAbuseReports ( ctx ) ) . rejects . toThrow ( ) ;
427+ } ) ;
343428 } ) ;
344429
345430 describe ( 'updateComment' , ( ) => {
@@ -359,6 +444,18 @@ describe('Admin controller', () => {
359444 expect ( result ) . toEqual ( expectedResult ) ;
360445 expect ( mockAdminService . updateComment ) . toHaveBeenCalledWith ( validatedData ) ;
361446 } ) ;
447+
448+ it ( 'should throw error when validation fails' , async ( ) => {
449+ const ctx = {
450+ params : { id : '1' } ,
451+ request : { body : { content : '' } }
452+ } as RequestContext < any , any > ;
453+ const error = new Error ( 'Validation failed' ) ;
454+
455+ caster < jest . Mock > ( adminValidator . getUpdateCommentValidator ) . mockReturnValue ( { left : error } ) ;
456+
457+ await expect ( getController ( getStrapi ( ) ) . updateComment ( ctx ) ) . rejects . toThrow ( ) ;
458+ } ) ;
362459 } ) ;
363460
364461 describe ( 'approveComment' , ( ) => {
@@ -375,6 +472,15 @@ describe('Admin controller', () => {
375472 expect ( result ) . toEqual ( expectedResult ) ;
376473 expect ( mockAdminService . approveComment ) . toHaveBeenCalledWith ( '1' ) ;
377474 } ) ;
475+
476+ it ( 'should throw error when validation fails' , async ( ) => {
477+ const ctx = { params : { id : 'invalid' } } as RequestContext < any , any > ;
478+ const error = new Error ( 'Validation failed' ) ;
479+
480+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
481+
482+ await expect ( getController ( getStrapi ( ) ) . approveComment ( ctx ) ) . rejects . toThrow ( ) ;
483+ } ) ;
378484 } ) ;
379485
380486 describe ( 'rejectComment' , ( ) => {
@@ -391,5 +497,14 @@ describe('Admin controller', () => {
391497 expect ( result ) . toEqual ( expectedResult ) ;
392498 expect ( mockAdminService . rejectComment ) . toHaveBeenCalledWith ( '1' ) ;
393499 } ) ;
500+
501+ it ( 'should throw error when validation fails' , async ( ) => {
502+ const ctx = { params : { id : 'invalid' } } as RequestContext < any , any > ;
503+ const error = new Error ( 'Validation failed' ) ;
504+
505+ caster < jest . Mock > ( adminValidator . getIdValidator ) . mockReturnValue ( { left : error } ) ;
506+
507+ await expect ( getController ( getStrapi ( ) ) . rejectComment ( ctx ) ) . rejects . toThrow ( ) ;
508+ } ) ;
394509 } ) ;
395510} ) ;
0 commit comments