@@ -15,6 +15,7 @@ const tasksData = require("../fixtures/tasks/tasks")();
1515const { DINERO , NEELAM } = require ( "../../constants/wallets" ) ;
1616const cleanDb = require ( "../utils/cleanDb" ) ;
1717const { TASK_STATUS } = require ( "../../constants/tasks" ) ;
18+ const updateTaskStatus = require ( "../fixtures/tasks/tasks1" ) ( ) ;
1819chai . use ( chaiHttp ) ;
1920
2021const appOwner = userData [ 3 ] ;
@@ -836,6 +837,30 @@ describe("Tasks", function () {
836837 return done ( ) ;
837838 } ) ;
838839 } ) ;
840+
841+ it ( "Should update the task status for given self taskid under feature flag" , function ( done ) {
842+ chai
843+ . request ( app )
844+ . patch ( `/tasks/self/${ taskId1 } ?userStatusFlag=true` )
845+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
846+ . send ( { status : "DONE" , percentCompleted : 100 } )
847+ . end ( ( err , res ) => {
848+ if ( err ) {
849+ return done ( err ) ;
850+ }
851+ expect ( res ) . to . have . status ( 200 ) ;
852+ expect ( res . body . taskLog ) . to . have . property ( "type" ) ;
853+ expect ( res . body . taskLog ) . to . have . property ( "id" ) ;
854+ expect ( res . body . taskLog . body ) . to . be . a ( "object" ) ;
855+ expect ( res . body . taskLog . meta ) . to . be . a ( "object" ) ;
856+ expect ( res . body . message ) . to . equal ( "Task updated successfully!" ) ;
857+
858+ expect ( res . body . taskLog . body . new . status ) . to . equal ( "DONE" ) ;
859+ expect ( res . body . taskLog . body . new . percentCompleted ) . to . equal ( 100 ) ;
860+ return done ( ) ;
861+ } ) ;
862+ } ) ;
863+
839864 it ( "Should return fail response if task data has non-acceptable status value to update the task status for given self taskid" , function ( done ) {
840865 chai
841866 . request ( app )
@@ -945,6 +970,18 @@ describe("Tasks", function () {
945970 expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Task is not completed yet" ) ;
946971 } ) ;
947972
973+ it ( "Should give 400 if percentCompleted is not 100 and new status is DONE under feature flag " , async function ( ) {
974+ taskId = ( await tasks . updateTask ( { ...taskData , status : "REVIEW" , assignee : appOwner . username } ) ) . taskId ;
975+ const res = await chai
976+ . request ( app )
977+ . patch ( `/tasks/self/${ taskId } ?userStatusFlag=true` )
978+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
979+ . send ( { ...taskStatusData , status : "DONE" } ) ;
980+
981+ expect ( res ) . to . have . status ( 400 ) ;
982+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Task is not done yet" ) ;
983+ } ) ;
984+
948985 it ( "Should give 400 if percentCompleted is not 100 and new status is VERIFIED " , async function ( ) {
949986 taskId = ( await tasks . updateTask ( { ...taskData , status : "REVIEW" , assignee : appOwner . username } ) ) . taskId ;
950987 const res = await chai
@@ -957,6 +994,18 @@ describe("Tasks", function () {
957994 expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Task is not completed yet" ) ;
958995 } ) ;
959996
997+ it ( "Should give 400 if percentCompleted is not 100 and new status is VERIFIED under feature flag" , async function ( ) {
998+ taskId = ( await tasks . updateTask ( { ...taskData , status : "REVIEW" , assignee : appOwner . username } ) ) . taskId ;
999+ const res = await chai
1000+ . request ( app )
1001+ . patch ( `/tasks/self/${ taskId } ?userStatusFlag=true` )
1002+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1003+ . send ( { ...taskStatusData , status : "VERIFIED" } ) ;
1004+
1005+ expect ( res ) . to . have . status ( 400 ) ;
1006+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Task is not done yet" ) ;
1007+ } ) ;
1008+
9601009 it ( "Should give 400 if status is COMPLETED and newpercent is less than 100" , async function ( ) {
9611010 const taskData = {
9621011 title : "Test task" ,
@@ -981,6 +1030,18 @@ describe("Tasks", function () {
9811030 expect ( res ) . to . have . status ( 400 ) ;
9821031 expect ( res . body . message ) . to . be . equal ( "Task percentCompleted can't updated as status is COMPLETED" ) ;
9831032 } ) ;
1033+
1034+ it ( "Should give 400 if status is DONE and newpercent is less than 100 under feature flag" , async function ( ) {
1035+ taskId = ( await tasks . updateTask ( updateTaskStatus [ 0 ] ) ) . taskId ;
1036+ const res = await chai
1037+ . request ( app )
1038+ . patch ( `/tasks/self/${ taskId } ?userStatusFlag=true` )
1039+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1040+ . send ( { percentCompleted : 80 } ) ;
1041+
1042+ expect ( res ) . to . have . status ( 400 ) ;
1043+ expect ( res . body . message ) . to . be . equal ( "Task percentCompleted can't updated as status is DONE" ) ;
1044+ } ) ;
9841045 } ) ;
9851046
9861047 describe ( "GET /tasks/overdue" , function ( ) {
0 commit comments