@@ -83,7 +83,7 @@ describe("Task Based Status Updates", function () {
83
83
expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . IDLE ) ;
84
84
} ) ;
85
85
86
- it ( "Should not change the ACTIVE state to IDLE if no other task is assigned to the user." , async function ( ) {
86
+ it ( "Should change the ACTIVE state to IDLE if no other task is assigned to the user." , async function ( ) {
87
87
const statusData = generateStatusDataForState ( userId , userState . ACTIVE ) ;
88
88
await firestore . collection ( "usersStatus" ) . doc ( "userStatus" ) . set ( statusData ) ;
89
89
const res = await chai
@@ -96,6 +96,35 @@ describe("Task Based Status Updates", function () {
96
96
expect ( res . body . userStatus . data . previousStatus ) . to . equal ( userState . ACTIVE ) ;
97
97
expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . IDLE ) ;
98
98
} ) ;
99
+
100
+ it ( "Should not change the IDLE state if no other task is assigned to the user. & current task status is updated (excluding completed, e.g., in progress)." , async function ( ) {
101
+ const statusData = generateStatusDataForState ( userId , userState . IDLE ) ;
102
+ await firestore . collection ( "usersStatus" ) . doc ( "userStatus" ) . set ( statusData ) ;
103
+ reqBody . status = "NEEDS_REVIEW" ;
104
+ const res = await chai
105
+ . request ( app )
106
+ . patch ( `/tasks/self/taskid123?userStatusFlag=true` )
107
+ . set ( "cookie" , `${ cookieName } =${ userJwt } ` )
108
+ . send ( reqBody ) ;
109
+ expect ( res . body . userStatus . status ) . to . equal ( "success" ) ;
110
+ expect ( res . body . userStatus . message ) . to . equal ( "The status is already IDLE" ) ;
111
+ expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . IDLE ) ;
112
+ } ) ;
113
+
114
+ it ( "Should change the ACTIVE state to IDLE if no other task is assigned to the user. & current task status is updated (excluding completed, e.g., in progress)." , async function ( ) {
115
+ const statusData = generateStatusDataForState ( userId , userState . ACTIVE ) ;
116
+ await firestore . collection ( "usersStatus" ) . doc ( "userStatus" ) . set ( statusData ) ;
117
+ reqBody . status = "NEEDS_REVIEW" ;
118
+ const res = await chai
119
+ . request ( app )
120
+ . patch ( `/tasks/self/taskid123?userStatusFlag=true` )
121
+ . set ( "cookie" , `${ cookieName } =${ userJwt } ` )
122
+ . send ( reqBody ) ;
123
+ expect ( res . body . userStatus . status ) . to . equal ( "success" ) ;
124
+ expect ( res . body . userStatus . message ) . to . equal ( "The status has been updated to IDLE" ) ;
125
+ expect ( res . body . userStatus . data . previousStatus ) . to . equal ( userState . ACTIVE ) ;
126
+ expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . IDLE ) ;
127
+ } ) ;
99
128
} ) ;
100
129
101
130
describe ( "User has an Active Task" , function ( ) {
@@ -148,9 +177,38 @@ describe("Task Based Status Updates", function () {
148
177
expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . ACTIVE ) ;
149
178
} ) ;
150
179
151
- it ( "Should change to ACTIVE state if the user is not ACTIVE." , async function ( ) {
180
+ it ( "Should change to ACTIVE state if the user is not ACTIVE. " , async function ( ) {
181
+ const statusData = generateStatusDataForState ( userId , userState . IDLE ) ;
182
+ await firestore . collection ( "usersStatus" ) . doc ( "userStatus" ) . set ( statusData ) ;
183
+ const res = await chai
184
+ . request ( app )
185
+ . patch ( `/tasks/self/taskid123?userStatusFlag=true` )
186
+ . set ( "cookie" , `${ cookieName } =${ userJwt } ` )
187
+ . send ( reqBody ) ;
188
+ expect ( res . body . userStatus . status ) . to . equal ( "success" ) ;
189
+ expect ( res . body . userStatus . message ) . to . equal ( "The status has been updated to ACTIVE" ) ;
190
+ expect ( res . body . userStatus . data . previousStatus ) . to . equal ( userState . IDLE ) ;
191
+ expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . ACTIVE ) ;
192
+ } ) ;
193
+
194
+ it ( "Should not change the ACTIVE state if the user is already ACTIVE. & current task status is updated (excluding completed, e.g., in progress)." , async function ( ) {
195
+ const statusData = generateStatusDataForState ( userId , userState . ACTIVE ) ;
196
+ await firestore . collection ( "usersStatus" ) . doc ( "userStatus" ) . set ( statusData ) ;
197
+ reqBody . status = "NEEDS_REVIEW" ;
198
+ const res = await chai
199
+ . request ( app )
200
+ . patch ( `/tasks/self/taskid123?userStatusFlag=true` )
201
+ . set ( "cookie" , `${ cookieName } =${ userJwt } ` )
202
+ . send ( reqBody ) ;
203
+ expect ( res . body . userStatus . status ) . to . equal ( "success" ) ;
204
+ expect ( res . body . userStatus . message ) . to . equal ( "The status is already ACTIVE" ) ;
205
+ expect ( res . body . userStatus . data . currentStatus ) . to . equal ( userState . ACTIVE ) ;
206
+ } ) ;
207
+
208
+ it ( "Should change to ACTIVE state if the user is not ACTIVE. & current task status is updated (excluding completed, e.g., in progress)." , async function ( ) {
152
209
const statusData = generateStatusDataForState ( userId , userState . IDLE ) ;
153
210
await firestore . collection ( "usersStatus" ) . doc ( "userStatus" ) . set ( statusData ) ;
211
+ reqBody . status = "NEEDS_REVIEW" ;
154
212
const res = await chai
155
213
. request ( app )
156
214
. patch ( `/tasks/self/taskid123?userStatusFlag=true` )
0 commit comments