@@ -76,6 +76,22 @@ import {
7676 UploadMetadata ,
7777} from '../gen/app/datasync/v1/data_sync_pb' ;
7878import { DataClient , type FilterOptions } from './data-client' ;
79+ import {
80+ DataPipeline ,
81+ ListDataPipelinesRequest ,
82+ ListDataPipelinesResponse ,
83+ GetDataPipelineRequest ,
84+ GetDataPipelineResponse ,
85+ CreateDataPipelineRequest ,
86+ CreateDataPipelineResponse ,
87+ DeleteDataPipelineRequest ,
88+ DeleteDataPipelineResponse ,
89+ DataPipelineRun ,
90+ DataPipelineRunStatus ,
91+ ListDataPipelineRunsRequest ,
92+ ListDataPipelineRunsResponse ,
93+ } from '../gen/app/datapipelines/v1/data_pipelines_pb' ;
94+ import { DataPipelinesService } from '../gen/app/datapipelines/v1/data_pipelines_connect' ;
7995vi . mock ( '../gen/app/data/v1/data_pb_service' ) ;
8096
8197let mockTransport : Transport ;
@@ -1404,3 +1420,231 @@ describe('DataSyncClient tests', () => {
14041420 } ) ;
14051421 } ) ;
14061422} ) ;
1423+
1424+ describe ( 'DataPipelineClient tests' , ( ) => {
1425+ const organizationId = 'testOrgId' ;
1426+ const pipelineId = 'testPipelineId' ;
1427+ const pipelineName = 'testPipeline' ;
1428+ const mqlQuery = [ { $match : { component_name : 'sensor-1' } } ] ;
1429+ const schedule = '0 0 * * *' ;
1430+
1431+ describe ( 'listDataPipelines tests' , ( ) => {
1432+ const pipeline1 = new DataPipeline ( {
1433+ id : 'pipeline1' ,
1434+ name : 'pipeline1' ,
1435+ organizationId : 'org1' ,
1436+ } ) ;
1437+ const pipeline2 = new DataPipeline ( {
1438+ id : 'pipeline2' ,
1439+ name : 'pipeline2' ,
1440+ organizationId : 'org2' ,
1441+ } ) ;
1442+ const pipelines = [ pipeline1 , pipeline2 ] ;
1443+
1444+ let capReq : ListDataPipelinesRequest ;
1445+ beforeEach ( ( ) => {
1446+ mockTransport = createRouterTransport ( ( { service } ) => {
1447+ service ( DataPipelinesService , {
1448+ listDataPipelines : ( req : ListDataPipelinesRequest ) => {
1449+ capReq = req ;
1450+ return new ListDataPipelinesResponse ( {
1451+ dataPipelines : pipelines ,
1452+ } ) ;
1453+ } ,
1454+ } ) ;
1455+ } ) ;
1456+ } ) ;
1457+
1458+ it ( 'list data pipelines' , async ( ) => {
1459+ const expectedRequest = new ListDataPipelinesRequest ( {
1460+ organizationId,
1461+ } ) ;
1462+
1463+ const response = await subject ( ) . listDataPipelines ( organizationId ) ;
1464+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1465+ expect ( response ) . toEqual ( pipelines ) ;
1466+ } ) ;
1467+ } ) ;
1468+
1469+ describe ( 'getPipeline tests' , ( ) => {
1470+ const pipeline = new DataPipeline ( {
1471+ id : pipelineId ,
1472+ name : pipelineName ,
1473+ organizationId,
1474+ } ) ;
1475+
1476+ let capReq : GetDataPipelineRequest ;
1477+ beforeEach ( ( ) => {
1478+ mockTransport = createRouterTransport ( ( { service } ) => {
1479+ service ( DataPipelinesService , {
1480+ getDataPipeline : ( req : GetDataPipelineRequest ) => {
1481+ capReq = req ;
1482+ return new GetDataPipelineResponse ( {
1483+ dataPipeline : pipeline ,
1484+ } ) ;
1485+ } ,
1486+ } ) ;
1487+ } ) ;
1488+ } ) ;
1489+
1490+ it ( 'get pipeline' , async ( ) => {
1491+ const expectedRequest = new GetDataPipelineRequest ( {
1492+ id : pipelineId ,
1493+ } ) ;
1494+
1495+ const response = await subject ( ) . getDataPipeline ( pipelineId ) ;
1496+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1497+ expect ( response ) . toEqual ( pipeline ) ;
1498+ } ) ;
1499+
1500+ it ( 'returns null when pipeline does not exist' , async ( ) => {
1501+ mockTransport = createRouterTransport ( ( { service } ) => {
1502+ service ( DataPipelinesService , {
1503+ getDataPipeline : ( ) => {
1504+ return new GetDataPipelineResponse ( { } ) ;
1505+ } ,
1506+ } ) ;
1507+ } ) ;
1508+
1509+ const response = await subject ( ) . getDataPipeline ( pipelineId ) ;
1510+ expect ( response ) . toBeNull ( ) ;
1511+ } ) ;
1512+ } ) ;
1513+
1514+ describe ( 'createDataPipeline tests' , ( ) => {
1515+ let capReq : CreateDataPipelineRequest ;
1516+ beforeEach ( ( ) => {
1517+ mockTransport = createRouterTransport ( ( { service } ) => {
1518+ service ( DataPipelinesService , {
1519+ createDataPipeline : ( req : CreateDataPipelineRequest ) => {
1520+ capReq = req ;
1521+ return new CreateDataPipelineResponse ( {
1522+ id : pipelineId ,
1523+ } ) ;
1524+ } ,
1525+ } ) ;
1526+ } ) ;
1527+ } ) ;
1528+
1529+ it ( 'create data pipeline' , async ( ) => {
1530+ const expectedRequest = new CreateDataPipelineRequest ( {
1531+ organizationId,
1532+ name : pipelineName ,
1533+ mqlBinary : mqlQuery . map ( ( value ) => BSON . serialize ( value ) ) ,
1534+ schedule,
1535+ } ) ;
1536+
1537+ const response = await subject ( ) . createDataPipeline (
1538+ organizationId ,
1539+ pipelineName ,
1540+ mqlQuery ,
1541+ schedule
1542+ ) ;
1543+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1544+ expect ( response ) . toEqual ( pipelineId ) ;
1545+ } ) ;
1546+ } ) ;
1547+
1548+ describe ( 'deleteDataPipeline tests' , ( ) => {
1549+ let capReq : DeleteDataPipelineRequest ;
1550+ beforeEach ( ( ) => {
1551+ mockTransport = createRouterTransport ( ( { service } ) => {
1552+ service ( DataPipelinesService , {
1553+ deleteDataPipeline : ( req : DeleteDataPipelineRequest ) => {
1554+ capReq = req ;
1555+ return new DeleteDataPipelineResponse ( ) ;
1556+ } ,
1557+ } ) ;
1558+ } ) ;
1559+ } ) ;
1560+
1561+ it ( 'delete data pipeline' , async ( ) => {
1562+ const expectedRequest = new DeleteDataPipelineRequest ( {
1563+ id : pipelineId ,
1564+ } ) ;
1565+
1566+ await subject ( ) . deleteDataPipeline ( pipelineId ) ;
1567+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1568+ } ) ;
1569+ } ) ;
1570+
1571+ describe ( 'listDataPipelineRuns tests' , ( ) => {
1572+ const run1 = new DataPipelineRun ( {
1573+ id : 'run1' ,
1574+ status : DataPipelineRunStatus . STARTED ,
1575+ } ) ;
1576+ const run2 = new DataPipelineRun ( {
1577+ id : 'run2' ,
1578+ status : DataPipelineRunStatus . COMPLETED ,
1579+ } ) ;
1580+ const runs = [ run1 , run2 ] ;
1581+ const pageSize = 10 ;
1582+ const nextPageToken = 'nextPageToken' ;
1583+
1584+ let capReq : ListDataPipelineRunsRequest ;
1585+ beforeEach ( ( ) => {
1586+ mockTransport = createRouterTransport ( ( { service } ) => {
1587+ service ( DataPipelinesService , {
1588+ listDataPipelineRuns : ( req : ListDataPipelineRunsRequest ) => {
1589+ capReq = req ;
1590+ return new ListDataPipelineRunsResponse ( {
1591+ runs,
1592+ nextPageToken,
1593+ } ) ;
1594+ } ,
1595+ } ) ;
1596+ } ) ;
1597+ } ) ;
1598+
1599+ it ( 'list data pipeline runs' , async ( ) => {
1600+ const expectedRequest = new ListDataPipelineRunsRequest ( {
1601+ id : pipelineId ,
1602+ pageSize,
1603+ } ) ;
1604+
1605+ const page = await subject ( ) . listDataPipelineRuns ( pipelineId , pageSize ) ;
1606+ expect ( capReq ) . toStrictEqual ( expectedRequest ) ;
1607+ expect ( page . runs ) . toEqual ( runs ) ;
1608+ const nextPage = await page . nextPage ( ) ;
1609+ expect ( nextPage . runs ) . toEqual ( runs ) ;
1610+ } ) ;
1611+
1612+ it ( 'get next page of runs' , async ( ) => {
1613+ const nextPageRuns = [ run2 ] ;
1614+ mockTransport = createRouterTransport ( ( { service } ) => {
1615+ service ( DataPipelinesService , {
1616+ listDataPipelineRuns : ( req : ListDataPipelineRunsRequest ) => {
1617+ capReq = req ;
1618+ return new ListDataPipelineRunsResponse ( {
1619+ runs : nextPageRuns ,
1620+ nextPageToken : 'some-token' ,
1621+ } ) ;
1622+ } ,
1623+ } ) ;
1624+ } ) ;
1625+
1626+ const page = await subject ( ) . listDataPipelineRuns ( pipelineId , pageSize ) ;
1627+ const nextPage = await page . nextPage ( ) ;
1628+ expect ( nextPage . runs ) . toEqual ( nextPageRuns ) ;
1629+ } ) ;
1630+
1631+ it ( 'returns empty page when no more runs' , async ( ) => {
1632+ const someRuns = [ run1 ] ;
1633+ mockTransport = createRouterTransport ( ( { service } ) => {
1634+ service ( DataPipelinesService , {
1635+ listDataPipelineRuns : ( req : ListDataPipelineRunsRequest ) => {
1636+ capReq = req ;
1637+ return new ListDataPipelineRunsResponse ( {
1638+ runs : someRuns ,
1639+ nextPageToken : '' ,
1640+ } ) ;
1641+ } ,
1642+ } ) ;
1643+ } ) ;
1644+
1645+ const page = await subject ( ) . listDataPipelineRuns ( pipelineId , pageSize ) ;
1646+ const nextPage = await page . nextPage ( ) ;
1647+ expect ( nextPage . runs ) . toEqual ( [ ] ) ;
1648+ } ) ;
1649+ } ) ;
1650+ } ) ;
0 commit comments