@@ -1517,3 +1517,136 @@ currentTest = 'GET /connection/user/permissions';
15171517// throw e;
15181518// }
15191519// });
1520+
1521+ currentTest = 'PUT /connection/title' ;
1522+ test . serial ( `${ currentTest } should return success when updating connection title` , async ( t ) => {
1523+ const { newConnection } = getTestData ( ) ;
1524+ const { token } = await registerUserAndReturnUserInfo ( app ) ;
1525+
1526+ const createConnectionResponse = await request ( app . getHttpServer ( ) )
1527+ . post ( '/connection' )
1528+ . send ( newConnection )
1529+ . set ( 'Content-Type' , 'application/json' )
1530+ . set ( 'Cookie' , token )
1531+ . set ( 'Accept' , 'application/json' ) ;
1532+
1533+ const createConnectionRO = JSON . parse ( createConnectionResponse . text ) ;
1534+
1535+ const newTitle = 'New Connection Title' ;
1536+ const updateTitleResponse = await request ( app . getHttpServer ( ) )
1537+ . put ( `/connection/title/${ createConnectionRO . id } ` )
1538+ . send ( { title : newTitle } )
1539+ . set ( 'Content-Type' , 'application/json' )
1540+ . set ( 'Cookie' , token )
1541+ . set ( 'Accept' , 'application/json' ) ;
1542+
1543+ t . is ( updateTitleResponse . status , 200 ) ;
1544+ const result = updateTitleResponse . body ;
1545+ t . is ( result . success , true ) ;
1546+
1547+ const getConnectionResponse = await request ( app . getHttpServer ( ) )
1548+ . get ( `/connection/one/${ createConnectionRO . id } ` )
1549+ . set ( 'Cookie' , token )
1550+ . set ( 'Content-Type' , 'application/json' )
1551+ . set ( 'Accept' , 'application/json' ) ;
1552+
1553+ t . is ( getConnectionResponse . status , 200 ) ;
1554+ const connectionResult = JSON . parse ( getConnectionResponse . text ) ;
1555+ t . is ( connectionResult . connection . title , newTitle ) ;
1556+
1557+ t . pass ( ) ;
1558+ } ) ;
1559+
1560+ test . serial ( `${ currentTest } should throw error when title is empty` , async ( t ) => {
1561+ const { newConnection } = getTestData ( ) ;
1562+ const { token } = await registerUserAndReturnUserInfo ( app ) ;
1563+
1564+ const createConnectionResponse = await request ( app . getHttpServer ( ) )
1565+ . post ( '/connection' )
1566+ . send ( newConnection )
1567+ . set ( 'Content-Type' , 'application/json' )
1568+ . set ( 'Cookie' , token )
1569+ . set ( 'Accept' , 'application/json' ) ;
1570+
1571+ const createConnectionRO = JSON . parse ( createConnectionResponse . text ) ;
1572+
1573+ const updateTitleResponse = await request ( app . getHttpServer ( ) )
1574+ . put ( `/connection/title/${ createConnectionRO . id } ` )
1575+ . send ( { title : '' } )
1576+ . set ( 'Content-Type' , 'application/json' )
1577+ . set ( 'Cookie' , token )
1578+ . set ( 'Accept' , 'application/json' ) ;
1579+
1580+ t . is ( updateTitleResponse . status , 400 ) ;
1581+
1582+ t . pass ( ) ;
1583+ } ) ;
1584+
1585+ test . serial ( `${ currentTest } should throw error when title is not provided` , async ( t ) => {
1586+ const { newConnection } = getTestData ( ) ;
1587+ const { token } = await registerUserAndReturnUserInfo ( app ) ;
1588+
1589+ const createConnectionResponse = await request ( app . getHttpServer ( ) )
1590+ . post ( '/connection' )
1591+ . send ( newConnection )
1592+ . set ( 'Content-Type' , 'application/json' )
1593+ . set ( 'Cookie' , token )
1594+ . set ( 'Accept' , 'application/json' ) ;
1595+
1596+ const createConnectionRO = JSON . parse ( createConnectionResponse . text ) ;
1597+
1598+ const updateTitleResponse = await request ( app . getHttpServer ( ) )
1599+ . put ( `/connection/title/${ createConnectionRO . id } ` )
1600+ . send ( { } )
1601+ . set ( 'Content-Type' , 'application/json' )
1602+ . set ( 'Cookie' , token )
1603+ . set ( 'Accept' , 'application/json' ) ;
1604+
1605+ t . is ( updateTitleResponse . status , 400 ) ;
1606+
1607+ t . pass ( ) ;
1608+ } ) ;
1609+
1610+ test . serial (
1611+ `${ currentTest } should update title of encrypted connection and connection should still work` ,
1612+ async ( t ) => {
1613+ const { newConnection } = getTestData ( ) ;
1614+ const { token } = await registerUserAndReturnUserInfo ( app ) ;
1615+ newConnection . masterEncryption = true ;
1616+
1617+ const createConnectionResponse = await request ( app . getHttpServer ( ) )
1618+ . post ( '/connection' )
1619+ . send ( newConnection )
1620+ . set ( 'masterpwd' , 'ahalaimahalai' )
1621+ . set ( 'Content-Type' , 'application/json' )
1622+ . set ( 'Cookie' , token )
1623+ . set ( 'Accept' , 'application/json' ) ;
1624+
1625+ t . is ( createConnectionResponse . status , 201 ) ;
1626+ const createConnectionRO = JSON . parse ( createConnectionResponse . text ) ;
1627+
1628+ const newTitle = 'Renamed Encrypted Connection' ;
1629+ const updateTitleResponse = await request ( app . getHttpServer ( ) )
1630+ . put ( `/connection/title/${ createConnectionRO . id } ` )
1631+ . send ( { title : newTitle } )
1632+ . set ( 'Content-Type' , 'application/json' )
1633+ . set ( 'Cookie' , token )
1634+ . set ( 'Accept' , 'application/json' ) ;
1635+
1636+ t . is ( updateTitleResponse . status , 200 ) ;
1637+ t . is ( updateTitleResponse . body . success , true ) ;
1638+
1639+ const findOneResponse = await request ( app . getHttpServer ( ) )
1640+ . get ( `/connection/one/${ createConnectionRO . id } ` )
1641+ . set ( 'Content-Type' , 'application/json' )
1642+ . set ( 'masterpwd' , 'ahalaimahalai' )
1643+ . set ( 'Cookie' , token )
1644+ . set ( 'Accept' , 'application/json' ) ;
1645+
1646+ t . is ( findOneResponse . status , 200 ) ;
1647+ const connectionResult = findOneResponse . body . connection ;
1648+ t . is ( connectionResult . title , newTitle ) ;
1649+
1650+ t . pass ( ) ;
1651+ } ,
1652+ ) ;
0 commit comments