@@ -48,9 +48,9 @@ describe("RatingController", () => {
4848 describe ( "authorization" , ( ) => {
4949 let server : http . Server ;
5050 let port : number ;
51- let httpRatingService : MockedService < IRatingService > ;
52- let httpSettingsService : MockedService < ISettingsService > ;
53- let httpUserService : MockedService < IUserService > ;
51+ let ratingService : MockedService < IRatingService > ;
52+ let settingsService : MockedService < ISettingsService > ;
53+ let userService : MockedService < IUserService > ;
5454
5555 const rootUser = Object . assign ( new User ( ) , { id : 1 , role : UserRole . Root } ) ;
5656 const regularUser = Object . assign ( new User ( ) , { id : 2 , role : UserRole . User } ) ;
@@ -61,20 +61,20 @@ describe("RatingController", () => {
6161 } ;
6262
6363 beforeAll ( async ( ) => {
64- httpRatingService = new MockRatingService ( ) ;
65- httpSettingsService = new MockSettingsService ( ) ;
66- httpUserService = new MockUserService ( ) ;
64+ ratingService = new MockRatingService ( ) ;
65+ settingsService = new MockSettingsService ( ) ;
66+ userService = new MockUserService ( ) ;
6767
68- httpUserService . mocks . findUserByLoginToken . mockImplementation (
68+ userService . mocks . findUserByLoginToken . mockImplementation (
6969 async ( token : string ) => tokenMap [ token ] ?? null ,
7070 ) ;
7171
72- const httpService = new HttpService ( null as any , null as any , httpUserService . instance ) ;
72+ const httpService = new HttpService ( null as any , null as any , userService . instance ) ;
7373
7474 useContainer ( {
7575 get ( target : Function ) {
7676 if ( target === RatingController ) {
77- return new RatingController ( httpSettingsService . instance , httpRatingService . instance ) ;
77+ return new RatingController ( settingsService . instance , ratingService . instance ) ;
7878 }
7979 return new ( target as any ) ( ) ;
8080 } ,
@@ -111,27 +111,34 @@ describe("RatingController", () => {
111111 } ) ;
112112
113113 it ( "allows requests from User-role users" , async ( ) => {
114- expect . assertions ( 1 ) ;
114+ expect . assertions ( 2 ) ;
115115
116- httpRatingService . mocks . createRating . mockResolvedValue ( { } as any ) ;
116+ ratingService . mocks . createRating . mockResolvedValue ( { } as any ) ;
117117
118118 const response = await fetch ( `http://localhost:${ port } /api/ratings/rate` , {
119119 method : "POST" ,
120120 headers : {
121121 "Content-Type" : "application/json" ,
122122 Authorization : "Bearer user-token" ,
123123 } ,
124- body : JSON . stringify ( { data : { } } ) ,
124+ body : JSON . stringify ( { data : { rating : 3 , project : { id : 1 } , criterion : { id : 2 } } } ) ,
125125 } ) ;
126126
127- // Authorization passed; any status other than 403 is acceptable here
128- expect ( response . status ) . not . toBe ( 403 ) ;
127+ expect ( response . status ) . toBe ( 200 ) ;
128+ expect ( ratingService . mocks . createRating ) . toHaveBeenCalledWith (
129+ expect . objectContaining ( {
130+ project : expect . objectContaining ( { id : 1 } ) ,
131+ user : expect . objectContaining ( { id : regularUser . id } ) ,
132+ criterion : expect . objectContaining ( { id : 2 } ) ,
133+ } ) ,
134+ regularUser ,
135+ ) ;
129136 } ) ;
130137
131138 it ( "passes authorization for admin (Root) users" , async ( ) => {
132139 expect . assertions ( 1 ) ;
133140
134- httpRatingService . mocks . createRating . mockResolvedValue ( { } as any ) ;
141+ ratingService . mocks . createRating . mockResolvedValue ( { } as any ) ;
135142
136143 const response = await fetch ( `http://localhost:${ port } /api/ratings/rate` , {
137144 method : "POST" ,
0 commit comments