@@ -7,18 +7,32 @@ beforeAll(async () => {
77 server = await createServer ( ) ;
88} ) ;
99
10- test ( 'users' , async ( ) => {
11- const res = await server . inject ( ) . get ( '/users' ) ;
10+ describe ( 'APIs - /users' , ( ) => {
11+ it ( 'should redirect to index' , async ( ) => {
12+ const res = await server . inject ( ) . get ( '/users' ) ;
13+ expect ( res . statusCode ) . toBe ( 302 ) ;
14+ } ) ;
1215
13- expect ( res . statusCode ) . toBe ( 200 ) ;
14- expect ( res . body ) . toMatch ( 'pong' ) ;
16+ it ( 'should return true on user id validation' , async ( ) => {
17+ const res = await server . inject ( ) . get ( '/users' ) . query ( { id : 1 } ) ;
18+ expect ( res . statusCode ) . toBe ( 200 ) ;
19+ expect ( res . json ( ) ) . toEqual ( { user_id : 1 , validated : true } ) ;
20+ } ) ;
21+
22+ it ( 'should return false on user id validation' , async ( ) => {
23+ const res = await server . inject ( ) . get ( '/users' ) . query ( { id : 10 } ) ;
24+ expect ( res . statusCode ) . toBe ( 200 ) ;
25+ expect ( res . json ( ) ) . toEqual ( { user_id : 10 , validated : false } ) ;
26+ } ) ;
1527} ) ;
1628
17- test ( 'user by id' , async ( ) => {
18- const res = await server . inject ( ) . get ( '/users/1' ) ;
29+ describe ( 'API - /users/:id' , ( ) => {
30+ it ( 'should return user id passed in' , async ( ) => {
31+ const res = await server . inject ( ) . get ( '/users/1' ) ;
1932
20- expect ( res . statusCode ) . toBe ( 200 ) ;
21- expect ( res . json ( ) ) . toEqual ( { user : 1 } ) ;
33+ expect ( res . statusCode ) . toBe ( 200 ) ;
34+ expect ( res . json ( ) ) . toEqual ( { user : 1 } ) ;
35+ } ) ;
2236} ) ;
2337
2438afterAll ( async ( ) => {
0 commit comments