@@ -10,7 +10,7 @@ let app = require("../index");
10
10
describe ( `TESTS ON "/users"` , function ( ) {
11
11
let userToken ;
12
12
let adminToken ;
13
- this . timeout ( 60000 ) ;
13
+ this . timeout ( 30000 ) ;
14
14
before ( async ( ) => {
15
15
console . log ( "Tests starting:" ) ;
16
16
await connectDB ( MONGO_STRING ) ;
@@ -51,7 +51,7 @@ describe(`TESTS ON "/users"`, function () {
51
51
await disconnectDB ( ) ;
52
52
console . log ( "Testing ends" ) ;
53
53
} ) ;
54
- it ( `POST ON "/users/register"` , ( done ) => {
54
+ it ( `[Not Authenticated User] POST "/users/register"` , ( done ) => {
55
55
chai . request ( app )
56
56
. post ( "/users/register" )
57
57
. type ( "json" )
@@ -67,7 +67,24 @@ describe(`TESTS ON "/users"`, function () {
67
67
done ( ) ;
68
68
} ) ;
69
69
} ) ;
70
- it ( `POST ON "/users/login"` , ( done ) => {
70
+ it ( `[Authenticated User] POST "/users/register"` , ( done ) => {
71
+ chai . request ( app )
72
+ . post ( "/users/register" )
73
+ . type ( "json" )
74
+ . send ( {
75
+ username : "NewUser" ,
76
+
77
+ password : "pAs$w0rd" ,
78
+ } )
79
+ . set ( "Authorization" , `Bearer ${ adminToken } ` )
80
+ . end ( ( err , res ) => {
81
+ chai . expect ( res . status ) . to . equal ( 403 ) ;
82
+ chai . expect ( res . body ) . to . have . property ( "success" ) . that . equals ( false ) ;
83
+ chai . expect ( res . body ) . to . have . property ( "message" ) . that . equals ( "You do not have permission to access this resource." ) ;
84
+ done ( ) ;
85
+ } ) ;
86
+ } ) ;
87
+ it ( `[Not Authenticated User] POST "/users/login"` , ( done ) => {
71
88
chai . request ( app )
72
89
. post ( "/users/login" )
73
90
. type ( "json" )
@@ -83,7 +100,33 @@ describe(`TESTS ON "/users"`, function () {
83
100
done ( ) ;
84
101
} ) ;
85
102
} ) ;
86
- it ( `GET ON "/users"` , ( done ) => {
103
+ it ( `[Authenticated User] POST "/users/login"` , ( done ) => {
104
+ chai . request ( app )
105
+ . post ( "/users/login" )
106
+ . type ( "json" )
107
+ . send ( {
108
+
109
+ password : "pAs$w0rd" ,
110
+ } )
111
+ . set ( "Authorization" , `Bearer ${ adminToken } ` )
112
+ . end ( ( err , res ) => {
113
+ chai . expect ( res . status ) . to . equal ( 403 ) ;
114
+ chai . expect ( res . body ) . to . have . property ( "success" ) . that . equals ( false ) ;
115
+ chai . expect ( res . body ) . to . have . property ( "message" ) . that . equals ( "You do not have permission to access this resource." ) ;
116
+ done ( ) ;
117
+ } ) ;
118
+ } ) ;
119
+ it ( `[Not Authenticated User] GET "/users"` , ( done ) => {
120
+ chai . request ( app )
121
+ . get ( "/users" )
122
+ . end ( ( err , res ) => {
123
+ chai . expect ( res . status ) . to . equal ( 403 ) ;
124
+ chai . expect ( res . body ) . to . have . property ( "success" ) . that . equals ( false ) ;
125
+ chai . expect ( res . body ) . to . have . property ( "message" ) . that . equals ( "You do not have permission to access this resource." ) ;
126
+ done ( ) ;
127
+ } ) ;
128
+ } ) ;
129
+ it ( `[Authenticated User] GET "/users"` , ( done ) => {
87
130
chai . request ( app )
88
131
. get ( "/users" )
89
132
. set ( "Authorization" , `Bearer ${ adminToken } ` )
@@ -95,7 +138,24 @@ describe(`TESTS ON "/users"`, function () {
95
138
done ( ) ;
96
139
} ) ;
97
140
} ) ;
98
- it ( `PATCH on "/users"` , ( done ) => {
141
+ it ( `[Not Authenticated User] PATCH "/users"` , ( done ) => {
142
+ let updated = {
143
+ username : "UpdatedMainUser" ,
144
+
145
+ password : "pAs$w0rd" ,
146
+ } ;
147
+ chai . request ( app )
148
+ . patch ( "/users" )
149
+ . type ( "json" )
150
+ . send ( updated )
151
+ . end ( ( err , res ) => {
152
+ chai . expect ( res . status ) . to . equal ( 403 ) ;
153
+ chai . expect ( res . body ) . to . have . property ( "success" ) . that . equals ( false ) ;
154
+ chai . expect ( res . body ) . to . have . property ( "message" ) . that . equals ( "You do not have permission to access this resource." ) ;
155
+ done ( ) ;
156
+ } ) ;
157
+ } ) ;
158
+ it ( `[Authenticated User] PATCH "/users"` , ( done ) => {
99
159
let updated = {
100
160
username : "UpdatedMainUser" ,
101
161
0 commit comments