@@ -6,6 +6,7 @@ import { Database } from './database';
66import { Streams } from './streams' ;
77import { InterruptFlag , MongoshInterruptedError } from './interruptor' ;
88import type { MongoshInvalidInputError } from '@mongosh/errors' ;
9+ import { asPrintable } from './enums' ;
910
1011describe ( 'Streams' , function ( ) {
1112 let mongo : Mongo ;
@@ -60,7 +61,7 @@ describe('Streams', function () {
6061
6162 const pipeline = [ { $match : { foo : 'bar' } } ] ;
6263 const result = await streams . createStreamProcessor ( 'spm' , pipeline ) ;
63- expect ( result ) . to . eql ( streams . getProcessor ( 'spm' ) ) ;
64+ expect ( result ) . to . eql ( streams . getProcessor ( { name : 'spm' , pipeline } ) ) ;
6465
6566 const cmd = { createStreamProcessor : 'spm' , pipeline } ;
6667 expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
@@ -172,7 +173,7 @@ describe('Streams', function () {
172173 . resolves ( { ok : 1 } ) ;
173174 const pipeline = [ { $match : { foo : 'bar' } } ] ;
174175 const processor = await streams . createStreamProcessor ( name , pipeline ) ;
175- expect ( processor ) . to . eql ( streams . getProcessor ( name ) ) ;
176+ expect ( processor ) . to . eql ( streams . getProcessor ( { name, pipeline } ) ) ;
176177 const cmd = { createStreamProcessor : name , pipeline } ;
177178 expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
178179 return { runCmdStub, processor } ;
@@ -313,6 +314,104 @@ describe('Streams', function () {
313314 } ) ;
314315 } ) ;
315316
317+ describe ( 'listStreamProcessors' , function ( ) {
318+ it ( 'passes filter parameter correctly' , async function ( ) {
319+ const runCmdStub = sinon
320+ . stub ( mongo . _serviceProvider , 'runCommand' )
321+ . resolves ( { ok : 1 , streamProcessors : [ ] } ) ;
322+
323+ const complexFilter = {
324+ name : { $regex : '^test' } ,
325+ state : { $in : [ 'STARTED' , 'STOPPED' ] } ,
326+ 'options.dlq.connectionName' : 'atlas-sql' ,
327+ } ;
328+
329+ await streams . listStreamProcessors ( complexFilter ) ;
330+
331+ const cmd = { listStreamProcessors : 1 , filter : complexFilter } ;
332+ expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
333+ } ) ;
334+
335+ it ( 'returns error when command fails' , async function ( ) {
336+ const error = { ok : 0 , errmsg : 'Command failed' } ;
337+ sinon . stub ( mongo . _serviceProvider , 'runCommand' ) . resolves ( error ) ;
338+
339+ const filter = { name : 'test' } ;
340+ const result = await streams . listStreamProcessors ( filter ) ;
341+ expect ( result ) . to . eql ( error ) ;
342+ } ) ;
343+
344+ it ( 'returns empty array when no processors exist' , async function ( ) {
345+ const runCmdStub = sinon
346+ . stub ( mongo . _serviceProvider , 'runCommand' )
347+ . resolves ( { ok : 1 , streamProcessors : [ ] } ) ;
348+
349+ const filter = { } ;
350+ const result = await streams . listStreamProcessors ( filter ) ;
351+
352+ expect ( Array . isArray ( result ) ) . to . be . true ;
353+ expect ( result . length ) . to . equal ( 0 ) ;
354+
355+ const cmd = { listStreamProcessors : 1 , filter } ;
356+ expect ( runCmdStub . calledOnceWithExactly ( 'admin' , cmd , { } ) ) . to . be . true ;
357+ } ) ;
358+
359+ it ( 'ensures complete stream processor objects are defined in response' , async function ( ) {
360+ const completeProcessor = {
361+ id : '6916541aa9733d72cff41f27' ,
362+ name : 'complete-processor' ,
363+ pipeline : [
364+ { $match : { status : 'active' } } ,
365+ { $project : { _id : 1 , name : 1 , timestamp : 1 } } ,
366+ ] ,
367+ state : 'STARTED' ,
368+ tier : 'SP2' ,
369+ errorMsg : '' ,
370+ lastModified : new Date ( '2023-01-01T00:00:00Z' ) ,
371+ lastStateChange : new Date ( '2023-01-01T00:00:00Z' ) ,
372+ } ;
373+
374+ sinon
375+ . stub ( mongo . _serviceProvider , 'runCommand' )
376+ . resolves ( { ok : 1 , streamProcessors : [ completeProcessor ] } ) ;
377+
378+ const result = await streams . listStreamProcessors ( { } ) ;
379+
380+ // Verify the raw processor data is preserved in asPrintable
381+ const rawProcessors = result [ asPrintable ] ( ) ;
382+ expect ( rawProcessors ) . to . have . length ( 1 ) ;
383+
384+ // deep comparison to ensure all fields are present an equal
385+ expect ( rawProcessors [ 0 ] ) . to . eql ( completeProcessor ) ;
386+ } ) ;
387+
388+ it ( 'ensures you can drill down into individual processor attributes' , async function ( ) {
389+ const completeProcessor = {
390+ id : '6916541aa9733d72cff41f27' ,
391+ name : 'complete-processor' ,
392+ pipeline : [
393+ { $match : { status : 'active' } } ,
394+ { $project : { _id : 1 , name : 1 , timestamp : 1 } } ,
395+ ] ,
396+ state : 'STARTED' ,
397+ tier : 'SP2' ,
398+ errorMsg : '' ,
399+ lastModified : new Date ( '2023-01-01T00:00:00Z' ) ,
400+ lastStateChange : new Date ( '2023-01-01T00:00:00Z' ) ,
401+ } ;
402+
403+ sinon
404+ . stub ( mongo . _serviceProvider , 'runCommand' )
405+ . resolves ( { ok : 1 , streamProcessors : [ completeProcessor ] } ) ;
406+
407+ const result = await streams . listStreamProcessors ( { } ) ;
408+
409+ // verify users can access properties on individual processors
410+ expect ( result [ 0 ] . name ) . to . equal ( completeProcessor . name ) ;
411+ expect ( result [ 0 ] . pipeline ) . to . eql ( completeProcessor . pipeline ) ;
412+ } ) ;
413+ } ) ;
414+
316415 describe ( 'listWorkspaceDefaults' , function ( ) {
317416 it ( 'returns tier and maxTierSize' , async function ( ) {
318417 const runCmdStub = sinon
0 commit comments