@@ -5,6 +5,8 @@ import { COOKIE_MAESTRO_ACCESS_TOKEN } from 'maestro-shared/constants';
55import { Region } from 'maestro-shared/referential/Region' ;
66import { User } from 'maestro-shared/schema/User/User' ;
77import {
8+ AdminFixture ,
9+ genUser ,
810 NationalCoordinator ,
911 RegionalCoordinator ,
1012 Sampler1Fixture ,
@@ -130,4 +132,52 @@ describe('User router', () => {
130132 ) ;
131133 } ) ;
132134 } ) ;
135+
136+ describe ( 'POST /' , ( ) => {
137+ const testRoute = ( ) => `/api/users` ;
138+
139+ test ( 'should fail if the user is not administrator' , async ( ) => {
140+ await request ( app )
141+ . post ( testRoute ( ) )
142+ . use ( tokenProvider ( NationalCoordinator ) )
143+ . send ( genUser ( ) )
144+ . expect ( constants . HTTP_STATUS_FORBIDDEN ) ;
145+ } ) ;
146+
147+ test ( 'should create an user' , async ( ) => {
148+ await request ( app )
149+ . post ( testRoute ( ) )
150+ . send ( genUser ( ) )
151+ . use ( tokenProvider ( AdminFixture ) )
152+ . expect ( constants . HTTP_STATUS_CREATED ) ;
153+ } ) ;
154+ } ) ;
155+
156+ describe ( 'PUT /{userId}' , ( ) => {
157+ const testRoute = ( userId : string ) => `/api/users/${ userId } ` ;
158+
159+ test ( 'should fail if the user is not administrator' , async ( ) => {
160+ await request ( app )
161+ . put ( testRoute ( NationalCoordinator . id ) )
162+ . send ( { role : 'Sampler' } )
163+ . use ( tokenProvider ( NationalCoordinator ) )
164+ . expect ( constants . HTTP_STATUS_FORBIDDEN ) ;
165+ } ) ;
166+
167+ test ( 'should fail if the updated user is unknown' , async ( ) => {
168+ await request ( app )
169+ . put ( testRoute ( '55555555-5555-5555-5555-555555555550' ) )
170+ . send ( { role : 'Sampler' } )
171+ . use ( tokenProvider ( AdminFixture ) )
172+ . expect ( constants . HTTP_STATUS_NOT_FOUND ) ;
173+ } ) ;
174+
175+ test ( 'should update an user' , async ( ) => {
176+ await request ( app )
177+ . put ( testRoute ( NationalCoordinator . id ) )
178+ . send ( { role : 'Sampler' } )
179+ . use ( tokenProvider ( AdminFixture ) )
180+ . expect ( constants . HTTP_STATUS_OK ) ;
181+ } ) ;
182+ } ) ;
133183} ) ;
0 commit comments