@@ -1326,6 +1326,337 @@ describe("Tasks", function () {
1326
1326
} ) ;
1327
1327
} ) ;
1328
1328
1329
+ describe ( "PATCH /tasks/:id/status" , function ( ) {
1330
+ const taskStatusData = {
1331
+ status : "AVAILABLE" ,
1332
+ percentCompleted : 50 ,
1333
+ } ;
1334
+
1335
+ const taskData = {
1336
+ title : "Test task" ,
1337
+ type : "feature" ,
1338
+ endsOn : 1234 ,
1339
+ startedOn : 4567 ,
1340
+ status : "VERIFIED" ,
1341
+ percentCompleted : 10 ,
1342
+ participants : [ ] ,
1343
+ completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
1344
+ lossRate : { [ DINERO ] : 1 } ,
1345
+ isNoteworthy : true ,
1346
+ } ;
1347
+
1348
+ it ( "Should throw 400 Bad Request if the user tries to update the status of a task to AVAILABLE" , function ( done ) {
1349
+ chai
1350
+ . request ( app )
1351
+ . patch ( `/tasks/${ taskId1 } /status?dev=true` )
1352
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1353
+ . send ( taskStatusData )
1354
+ . end ( ( err , res ) => {
1355
+ if ( err ) {
1356
+ return done ( err ) ;
1357
+ }
1358
+ expect ( res ) . to . have . status ( 400 ) ;
1359
+ expect ( res . body ) . to . be . a ( "object" ) ;
1360
+ expect ( res . body . error ) . to . equal ( "Bad Request" ) ;
1361
+ expect ( res . body . message ) . to . equal ( "The value for the 'status' field is invalid." ) ;
1362
+ return done ( ) ;
1363
+ } ) ;
1364
+ } ) ;
1365
+
1366
+ it ( "Should update the task status for given self taskid" , function ( done ) {
1367
+ taskStatusData . status = "IN_PROGRESS" ;
1368
+ chai
1369
+ . request ( app )
1370
+ . patch ( `/tasks/${ taskId1 } /status?dev=true` )
1371
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1372
+ . send ( taskStatusData )
1373
+ . end ( ( err , res ) => {
1374
+ if ( err ) {
1375
+ return done ( err ) ;
1376
+ }
1377
+ expect ( res ) . to . have . status ( 200 ) ;
1378
+ expect ( res . body . taskLog ) . to . have . property ( "type" ) ;
1379
+ expect ( res . body . taskLog ) . to . have . property ( "id" ) ;
1380
+ expect ( res . body . taskLog . body ) . to . be . a ( "object" ) ;
1381
+ expect ( res . body . taskLog . meta ) . to . be . a ( "object" ) ;
1382
+ expect ( res . body . message ) . to . equal ( "Task updated successfully!" ) ;
1383
+
1384
+ expect ( res . body . taskLog . body . new . status ) . to . equal ( taskStatusData . status ) ;
1385
+ expect ( res . body . taskLog . body . new . percentCompleted ) . to . equal ( taskStatusData . percentCompleted ) ;
1386
+ return done ( ) ;
1387
+ } ) ;
1388
+ } ) ;
1389
+
1390
+ it ( "Should update the task status for given self taskid under feature flag" , function ( done ) {
1391
+ chai
1392
+ . request ( app )
1393
+ . patch ( `/tasks/${ taskId1 } /status?dev=true&userStatusFlag=true` )
1394
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1395
+ . send ( { status : "DONE" , percentCompleted : 100 } )
1396
+ . end ( ( err , res ) => {
1397
+ if ( err ) {
1398
+ return done ( err ) ;
1399
+ }
1400
+ expect ( res ) . to . have . status ( 200 ) ;
1401
+ expect ( res . body . taskLog ) . to . have . property ( "type" ) ;
1402
+ expect ( res . body . taskLog ) . to . have . property ( "id" ) ;
1403
+ expect ( res . body . taskLog . body ) . to . be . a ( "object" ) ;
1404
+ expect ( res . body . taskLog . meta ) . to . be . a ( "object" ) ;
1405
+ expect ( res . body . message ) . to . equal ( "Task updated successfully!" ) ;
1406
+
1407
+ expect ( res . body . taskLog . body . new . status ) . to . equal ( "DONE" ) ;
1408
+ expect ( res . body . taskLog . body . new . percentCompleted ) . to . equal ( 100 ) ;
1409
+ return done ( ) ;
1410
+ } ) ;
1411
+ } ) ;
1412
+
1413
+ it ( "Should return fail response if task data has non-acceptable status value to update the task status for given self taskid" , function ( done ) {
1414
+ chai
1415
+ . request ( app )
1416
+ . patch ( `/tasks/${ taskId1 } /status?dev=true` )
1417
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1418
+ . send ( { ...taskStatusData , status : "invalidStatus" } )
1419
+ . end ( ( err , res ) => {
1420
+ if ( err ) {
1421
+ return done ( err ) ;
1422
+ }
1423
+ expect ( res ) . to . have . status ( 400 ) ;
1424
+ expect ( res . body ) . to . be . a ( "object" ) ;
1425
+ expect ( res . body . error ) . to . equal ( "Bad Request" ) ;
1426
+ return done ( ) ;
1427
+ } ) ;
1428
+ } ) ;
1429
+
1430
+ it ( "Should return fail response if percentage is < 0 or > 100" , function ( done ) {
1431
+ chai
1432
+ . request ( app )
1433
+ . patch ( `/tasks/${ taskId1 } /status?dev=true` )
1434
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1435
+ . send ( { ...taskStatusData , percentCompleted : - 10 } )
1436
+ . end ( ( err , res ) => {
1437
+ if ( err ) {
1438
+ return done ( err ) ;
1439
+ }
1440
+ expect ( res ) . to . have . status ( 400 ) ;
1441
+ expect ( res . body ) . to . be . a ( "object" ) ;
1442
+ expect ( res . body . error ) . to . equal ( "Bad Request" ) ;
1443
+ return done ( ) ;
1444
+ } ) ;
1445
+ } ) ;
1446
+
1447
+ it ( "Should return 404 if task doesnt exist" , function ( done ) {
1448
+ taskStatusData . status = "IN_PROGRESS" ;
1449
+ chai
1450
+ . request ( app )
1451
+ . patch ( `/tasks/wrongtaskId/status?dev=true` )
1452
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1453
+ . send ( taskStatusData )
1454
+ . end ( ( err , res ) => {
1455
+ if ( err ) {
1456
+ return done ( err ) ;
1457
+ }
1458
+ expect ( res ) . to . have . status ( 404 ) ;
1459
+ expect ( res . body . message ) . to . equal ( "Task doesn't exist" ) ;
1460
+ return done ( ) ;
1461
+ } ) ;
1462
+ } ) ;
1463
+
1464
+ it ( "Should return Forbidden error if task is not assigned to self" , async function ( ) {
1465
+ const userId = await addUser ( userData [ 0 ] ) ;
1466
+ const jwt = authService . generateAuthToken ( { userId } ) ;
1467
+
1468
+ const res = await chai
1469
+ . request ( app )
1470
+ . patch ( `/tasks/${ taskId1 } /status?dev=true` )
1471
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` ) ;
1472
+
1473
+ expect ( res ) . to . have . status ( 403 ) ;
1474
+ expect ( res . body . message ) . to . equal ( "This task is not assigned to you" ) ;
1475
+ } ) ;
1476
+
1477
+ it ( "Should give error for no cookie" , function ( done ) {
1478
+ chai
1479
+ . request ( app )
1480
+ . patch ( `/tasks/${ taskId1 } /status?dev=true` )
1481
+ . send ( taskStatusData )
1482
+ . end ( ( err , res ) => {
1483
+ if ( err ) {
1484
+ return done ( err ) ;
1485
+ }
1486
+ expect ( res ) . to . have . status ( 401 ) ;
1487
+ expect ( res . body . message ) . to . be . equal ( "Unauthenticated User" ) ;
1488
+ return done ( ) ;
1489
+ } ) ;
1490
+ } ) ;
1491
+
1492
+ it ( "Should give 403 if status is already 'VERIFIED' " , async function ( ) {
1493
+ taskStatusData . status = "IN_PROGRESS" ;
1494
+ taskId = ( await tasks . updateTask ( { ...taskData , assignee : appOwner . username } ) ) . taskId ;
1495
+ const res = await chai
1496
+ . request ( app )
1497
+ . patch ( `/tasks/${ taskId } /status?dev=true` )
1498
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1499
+ . send ( taskStatusData ) ;
1500
+
1501
+ expect ( res ) . to . have . status ( 403 ) ;
1502
+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Please contact admin." ) ;
1503
+ } ) ;
1504
+
1505
+ it ( "Should give 403 if new status is 'MERGED' " , async function ( ) {
1506
+ taskId = ( await tasks . updateTask ( { ...taskData , assignee : appOwner . username } ) ) . taskId ;
1507
+ const res = await chai
1508
+ . request ( app )
1509
+ . patch ( `/tasks/${ taskId } /status?dev=true` )
1510
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1511
+ . send ( { ...taskStatusData , status : "MERGED" } ) ;
1512
+
1513
+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Please contact admin." ) ;
1514
+ } ) ;
1515
+
1516
+ it ( "Should give 403 if new status is 'BACKLOG' " , async function ( ) {
1517
+ taskId = ( await tasks . updateTask ( { ...taskData , assignee : appOwner . username } ) ) . taskId ;
1518
+ const res = await chai
1519
+ . request ( app )
1520
+ . patch ( `/tasks/${ taskId } /status?dev=true` )
1521
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1522
+ . send ( { ...taskStatusData , status : "BACKLOG" } ) ;
1523
+
1524
+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Please contact admin." ) ;
1525
+ } ) ;
1526
+
1527
+ it ( "Should give 400 if percentCompleted is not 100 and new status is COMPLETED " , async function ( ) {
1528
+ taskId = ( await tasks . updateTask ( { ...taskData , status : "REVIEW" , assignee : appOwner . username } ) ) . taskId ;
1529
+ const res = await chai
1530
+ . request ( app )
1531
+ . patch ( `/tasks/${ taskId } /status?dev=true` )
1532
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1533
+ . send ( { ...taskStatusData , status : "COMPLETED" } ) ;
1534
+
1535
+ expect ( res ) . to . have . status ( 400 ) ;
1536
+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated as progress of task is not 100%." ) ;
1537
+ } ) ;
1538
+
1539
+ it ( "Should give 403 if current task status is DONE" , async function ( ) {
1540
+ taskId = ( await tasks . updateTask ( { ...taskData , status : "DONE" , assignee : appOwner . username } ) ) . taskId ;
1541
+ const res = await chai
1542
+ . request ( app )
1543
+ . patch ( `/tasks/${ taskId } /status?dev=true&userStatusFlag=true` )
1544
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1545
+ . send ( { ...taskStatusData , status : "IN_REVIEW" } ) ;
1546
+
1547
+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated. Please contact admin." ) ;
1548
+ expect ( res ) . to . have . status ( 403 ) ;
1549
+ } ) ;
1550
+
1551
+ it ( "Should give 400 if percentCompleted is not 100 and new status is VERIFIED " , async function ( ) {
1552
+ taskId = ( await tasks . updateTask ( { ...taskData , status : "REVIEW" , assignee : appOwner . username } ) ) . taskId ;
1553
+ const res = await chai
1554
+ . request ( app )
1555
+ . patch ( `/tasks/${ taskId } /status?dev=true` )
1556
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1557
+ . send ( { ...taskStatusData , status : "VERIFIED" } ) ;
1558
+
1559
+ expect ( res ) . to . have . status ( 400 ) ;
1560
+ expect ( res . body . message ) . to . be . equal ( "Status cannot be updated as progress of task is not 100%." ) ;
1561
+ } ) ;
1562
+
1563
+ it ( "Should give 400 if status is COMPLETED and newpercent is less than 100" , async function ( ) {
1564
+ const taskData = {
1565
+ title : "Test task" ,
1566
+ type : "feature" ,
1567
+ endsOn : 1234 ,
1568
+ startedOn : 4567 ,
1569
+ status : "completed" ,
1570
+ percentCompleted : 100 ,
1571
+ participants : [ ] ,
1572
+ assignee : appOwner . username ,
1573
+ completionAward : { [ DINERO ] : 3 , [ NEELAM ] : 300 } ,
1574
+ lossRate : { [ DINERO ] : 1 } ,
1575
+ isNoteworthy : true ,
1576
+ } ;
1577
+ taskId = ( await tasks . updateTask ( taskData ) ) . taskId ;
1578
+ const res = await chai
1579
+ . request ( app )
1580
+ . patch ( `/tasks/${ taskId } /status?dev=true` )
1581
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1582
+ . send ( { percentCompleted : 80 } ) ;
1583
+
1584
+ expect ( res ) . to . have . status ( 400 ) ;
1585
+ expect ( res . body . message ) . to . be . equal ( "Task percentCompleted can't updated as status is COMPLETED" ) ;
1586
+ } ) ;
1587
+
1588
+ it ( "Should give 400 if current status of task is In Progress and new status is not Blocked and both current and new percentCompleted are not 100 " , async function ( ) {
1589
+ const newDate = { ...updateTaskStatus [ 0 ] , status : "IN_PROGRESS" , percentCompleted : 80 } ;
1590
+ taskId = ( await tasks . updateTask ( newDate ) ) . taskId ;
1591
+ const res = await chai
1592
+ . request ( app )
1593
+ . patch ( `/tasks/${ taskId } /status?dev=true&userStatusFlag=true` )
1594
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1595
+ . send ( { status : "NEEDS_REVIEW" } ) ;
1596
+
1597
+ expect ( res ) . to . have . status ( 400 ) ;
1598
+ expect ( res . body . message ) . to . be . equal (
1599
+ "The status of task can not be changed from In progress until progress of task is not 100%."
1600
+ ) ;
1601
+ } ) ;
1602
+
1603
+ it ( "Should give 400 if new status of task is In Progress and current status of task is not Blocked and both current and new percentCompleted are not 0 " , async function ( ) {
1604
+ const newDate = { ...updateTaskStatus [ 0 ] , status : "NEEDS_REVIEW" , percentCompleted : 100 } ;
1605
+ taskId = ( await tasks . updateTask ( newDate ) ) . taskId ;
1606
+ const res = await chai
1607
+ . request ( app )
1608
+ . patch ( `/tasks/${ taskId } /status?dev=true&userStatusFlag=true` )
1609
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1610
+ . send ( { status : "IN_PROGRESS" } ) ;
1611
+
1612
+ expect ( res ) . to . have . status ( 400 ) ;
1613
+ expect ( res . body . message ) . to . be . equal (
1614
+ "The status of task can not be changed to In progress until progress of task is not 0%."
1615
+ ) ;
1616
+ } ) ;
1617
+
1618
+ it ( "Should give 400 if current status of task is Blocked and new status is not In Progress and both current and new percentCompleted are not 100 " , async function ( ) {
1619
+ const newDate = { ...updateTaskStatus [ 0 ] , status : "BLOCKED" , percentCompleted : 52 } ;
1620
+ taskId = ( await tasks . updateTask ( newDate ) ) . taskId ;
1621
+ const res = await chai
1622
+ . request ( app )
1623
+ . patch ( `/tasks/${ taskId } /status?dev=true&userStatusFlag=true` )
1624
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1625
+ . send ( { status : "NEEDS_REVIEW" } ) ;
1626
+
1627
+ expect ( res ) . to . have . status ( 400 ) ;
1628
+ expect ( res . body . message ) . to . be . equal (
1629
+ "The status of task can not be changed from Blocked until progress of task is not 100%."
1630
+ ) ;
1631
+ } ) ;
1632
+
1633
+ it ( "Should give 200 if new status of task is In Progress and current status of task is Blocked" , async function ( ) {
1634
+ const newDate = { ...updateTaskStatus [ 0 ] , status : "BLOCKED" , percentCompleted : 56 } ;
1635
+ taskId = ( await tasks . updateTask ( newDate ) ) . taskId ;
1636
+ const res = await chai
1637
+ . request ( app )
1638
+ . patch ( `/tasks/${ taskId } /status?dev=true&userStatusFlag=true` )
1639
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1640
+ . send ( { status : "IN_PROGRESS" } ) ;
1641
+
1642
+ expect ( res ) . to . have . status ( 200 ) ;
1643
+ expect ( res . body . message ) . to . be . equal ( "Task updated successfully!" ) ;
1644
+ } ) ;
1645
+
1646
+ it ( "Should give 200 if new status of task is Blocked and current status of task is In Progress" , async function ( ) {
1647
+ const newDate = { ...updateTaskStatus [ 0 ] , status : "IN_PROGRESS" , percentCompleted : 59 } ;
1648
+ taskId = ( await tasks . updateTask ( newDate ) ) . taskId ;
1649
+ const res = await chai
1650
+ . request ( app )
1651
+ . patch ( `/tasks/${ taskId } /status?dev=true&userStatusFlag=true` )
1652
+ . set ( "cookie" , `${ cookieName } =${ jwt } ` )
1653
+ . send ( { status : "BLOCKED" } ) ;
1654
+
1655
+ expect ( res ) . to . have . status ( 200 ) ;
1656
+ expect ( res . body . message ) . to . be . equal ( "Task updated successfully!" ) ;
1657
+ } ) ;
1658
+ } ) ;
1659
+
1329
1660
describe ( "GET /tasks/overdue" , function ( ) {
1330
1661
it ( "Should return all the overdue Tasks" , async function ( ) {
1331
1662
await tasks . updateTask ( tasksData [ 0 ] ) ;
0 commit comments