@@ -327,4 +327,98 @@ describe('FileBreadcrumbsStorage', () => {
327327 expect ( actualMain ) . toEqual ( expectedMain ) ;
328328 expect ( actualFallback ) . toEqual ( expectedFallback ) ;
329329 } ) ;
330+
331+ it ( 'should return attachments with a valid name from getAttachments' , async ( ) => {
332+ const fs = mockStreamFileSystem ( ) ;
333+ const session = new SessionFiles ( fs , '.' , 'sessionId' ) ;
334+
335+ const breadcrumbs : RawBreadcrumb [ ] = [
336+ {
337+ level : BreadcrumbLogLevel . Info ,
338+ message : 'a' ,
339+ type : BreadcrumbType . Manual ,
340+ attributes : {
341+ foo : 'bar' ,
342+ } ,
343+ } ,
344+ {
345+ level : BreadcrumbLogLevel . Debug ,
346+ message : 'b' ,
347+ type : BreadcrumbType . Http ,
348+ } ,
349+ {
350+ level : BreadcrumbLogLevel . Warning ,
351+ message : 'c' ,
352+ type : BreadcrumbType . Navigation ,
353+ attributes : { } ,
354+ } ,
355+ ] ;
356+
357+ const storage = new FileBreadcrumbsStorage ( session , fs , {
358+ maximumBreadcrumbs : 4 ,
359+ } ) ;
360+
361+ for ( const breadcrumb of breadcrumbs ) {
362+ storage . add ( breadcrumb ) ;
363+ await nextTick ( ) ;
364+ }
365+
366+ // FileBreadcrumbsStorage is asynchronous in nature
367+ await nextTick ( ) ;
368+
369+ const [ fallbackAttachment , mainAttachment ] = storage . getAttachments ( ) ;
370+
371+ expect ( fallbackAttachment . name ) . toEqual ( expect . stringMatching ( / ^ b t - b r e a d c r u m b s - 0 / ) ) ;
372+ expect ( mainAttachment . name ) . toEqual ( expect . stringMatching ( / ^ b t - b r e a d c r u m b s - 1 / ) ) ;
373+ } ) ;
374+
375+ it ( 'should return attachments with a valid name from getAttachmentProviders' , async ( ) => {
376+ const fs = mockStreamFileSystem ( ) ;
377+ const session = new SessionFiles ( fs , '.' , 'sessionId' ) ;
378+
379+ const breadcrumbs : RawBreadcrumb [ ] = [
380+ {
381+ level : BreadcrumbLogLevel . Info ,
382+ message : 'a' ,
383+ type : BreadcrumbType . Manual ,
384+ attributes : {
385+ foo : 'bar' ,
386+ } ,
387+ } ,
388+ {
389+ level : BreadcrumbLogLevel . Debug ,
390+ message : 'b' ,
391+ type : BreadcrumbType . Http ,
392+ } ,
393+ {
394+ level : BreadcrumbLogLevel . Warning ,
395+ message : 'c' ,
396+ type : BreadcrumbType . Navigation ,
397+ attributes : { } ,
398+ } ,
399+ ] ;
400+
401+ const storage = new FileBreadcrumbsStorage ( session , fs , {
402+ maximumBreadcrumbs : 4 ,
403+ } ) ;
404+
405+ for ( const breadcrumb of breadcrumbs ) {
406+ storage . add ( breadcrumb ) ;
407+ await nextTick ( ) ;
408+ }
409+
410+ // FileBreadcrumbsStorage is asynchronous in nature
411+ await nextTick ( ) ;
412+
413+ const providers = storage . getAttachmentProviders ( ) ;
414+
415+ const [ fallbackAttachment , mainAttachment ] = providers
416+ . map ( ( v ) => v . get ( ) )
417+ . map ( ( v ) => ( Array . isArray ( v ) ? v : [ v ] ) )
418+ . filter ( ( f ) => ! ! f )
419+ . reduce ( ( acc , arr ) => [ ...acc , ...arr ] , [ ] ) ;
420+
421+ expect ( fallbackAttachment ?. name ) . toEqual ( expect . stringMatching ( / ^ b t - b r e a d c r u m b s - 0 / ) ) ;
422+ expect ( mainAttachment ?. name ) . toEqual ( expect . stringMatching ( / ^ b t - b r e a d c r u m b s - 1 / ) ) ;
423+ } ) ;
330424} ) ;
0 commit comments