@@ -1642,6 +1642,104 @@ describe('resource-publisher', () => {
16421642 } ) ;
16431643 } ) ;
16441644
1645+ describe ( 'WebSocket API operations (#317)' , ( ) => {
1646+ const apiJson = {
1647+ name : 'notification-socket' ,
1648+ properties : { displayName : 'Notification socket' , type : 'websocket' , protocols : [ 'wss' ] } ,
1649+ } ;
1650+ const onHandshakeJson = {
1651+ name : 'onHandshake' ,
1652+ properties : {
1653+ displayName : 'onHandshake' ,
1654+ method : 'GET' ,
1655+ urlTemplate : '' ,
1656+ templateParameters : [ ] ,
1657+ description : 'WebSocket opening handshake' ,
1658+ responses : [ ] ,
1659+ } ,
1660+ } ;
1661+
1662+ it ( 'skips the system-managed onHandshake operation instead of PUTting an empty urlTemplate' , async ( ) => {
1663+ const client = createMockClient ( ) ;
1664+ const store = createMockStore ( ) ;
1665+ store . readResource . mockImplementation ( async ( _dir : string , d : ResourceDescriptor ) =>
1666+ d . type === ResourceType . Api ? apiJson : onHandshakeJson
1667+ ) ;
1668+
1669+ const descriptor : ResourceDescriptor = {
1670+ type : ResourceType . ApiOperation ,
1671+ nameParts : [ 'notification-socket' , 'onHandshake' ] ,
1672+ } ;
1673+
1674+ const result = await publishResource ( client , store , testContext , descriptor , testConfig ) ;
1675+
1676+ expect ( result ) . toMatchObject ( { descriptor, status : 'skipped' , action : 'noop' } ) ;
1677+ expect ( client . putResource ) . not . toHaveBeenCalled ( ) ;
1678+ expect ( store . readResource ) . toHaveBeenCalledWith (
1679+ testConfig . sourceDir ,
1680+ expect . objectContaining ( { type : ResourceType . Api , nameParts : [ 'notification-socket' ] } )
1681+ ) ;
1682+ } ) ;
1683+
1684+ it ( 'still publishes operations whose parent API is not a WebSocket API' , async ( ) => {
1685+ const client = createMockClient ( ) ;
1686+ const store = createMockStore ( ) ;
1687+ store . readResource . mockImplementation ( async ( _dir : string , d : ResourceDescriptor ) =>
1688+ d . type === ResourceType . Api
1689+ ? { name : 'orders-api' , properties : { type : 'http' } }
1690+ : { name : 'get-orders' , properties : { method : 'GET' , urlTemplate : '/orders' } }
1691+ ) ;
1692+
1693+ const descriptor : ResourceDescriptor = {
1694+ type : ResourceType . ApiOperation ,
1695+ nameParts : [ 'orders-api' , 'get-orders' ] ,
1696+ } ;
1697+
1698+ const result = await publishResource ( client , store , testContext , descriptor , testConfig ) ;
1699+
1700+ expect ( result . status ) . toBe ( 'success' ) ;
1701+ expect ( client . putResource ) . toHaveBeenCalledTimes ( 1 ) ;
1702+ } ) ;
1703+
1704+ it ( 'still publishes the operation when the parent API artifact is missing' , async ( ) => {
1705+ const client = createMockClient ( ) ;
1706+ const store = createMockStore ( ) ;
1707+ store . readResource . mockImplementation ( async ( _dir : string , d : ResourceDescriptor ) =>
1708+ d . type === ResourceType . Api ? undefined : onHandshakeJson
1709+ ) ;
1710+
1711+ const descriptor : ResourceDescriptor = {
1712+ type : ResourceType . ApiOperation ,
1713+ nameParts : [ 'notification-socket' , 'onHandshake' ] ,
1714+ } ;
1715+
1716+ const result = await publishResource ( client , store , testContext , descriptor , testConfig ) ;
1717+
1718+ expect ( result . status ) . toBe ( 'success' ) ;
1719+ expect ( client . putResource ) . toHaveBeenCalledTimes ( 1 ) ;
1720+ } ) ;
1721+
1722+ it ( 'reports a parent API artifact read error as a failure instead of PUTting the operation' , async ( ) => {
1723+ const client = createMockClient ( ) ;
1724+ const store = createMockStore ( ) ;
1725+ const readError = new Error ( 'Unexpected token in apiInformation.json' ) ;
1726+ store . readResource . mockImplementation ( async ( _dir : string , d : ResourceDescriptor ) => {
1727+ if ( d . type === ResourceType . Api ) throw readError ;
1728+ return onHandshakeJson ;
1729+ } ) ;
1730+
1731+ const descriptor : ResourceDescriptor = {
1732+ type : ResourceType . ApiOperation ,
1733+ nameParts : [ 'notification-socket' , 'onHandshake' ] ,
1734+ } ;
1735+
1736+ const result = await publishResource ( client , store , testContext , descriptor , testConfig ) ;
1737+
1738+ expect ( result ) . toMatchObject ( { status : 'failed' , action : 'noop' , error : readError } ) ;
1739+ expect ( client . putResource ) . not . toHaveBeenCalled ( ) ;
1740+ } ) ;
1741+ } ) ;
1742+
16451743 describe ( 'API revision handling' , ( ) => {
16461744 it ( 'injects sourceApiId for revision APIs' , async ( ) => {
16471745 const client = createMockClient ( ) ;
0 commit comments