@@ -318,4 +318,258 @@ describe('generateFiledBy', () => {
318318
319319 expect ( filedByResult ) . toEqual ( mockDocketEntry . filedBy ) ;
320320 } ) ;
321+
322+ it ( 'should return existing filedBy when docket entry is a notice of contact change (not auto-generated) but is served' , ( ) => {
323+ const mockFiledBy = 'Existing Filed By' ;
324+ const filedByResult = generateFiledBy ( {
325+ docketEntry : {
326+ ...mockDocketEntry ,
327+ documentType : NOTICE_OF_CHANGE_CONTACT_INFORMATION_MAP [ 0 ] . documentType ,
328+ eventCode : NOTICE_OF_CHANGE_CONTACT_INFORMATION_MAP [ 0 ] . eventCode ,
329+ filedBy : mockFiledBy ,
330+ filers : [ mockPrimaryContactId ] ,
331+ isAutoGenerated : false ,
332+ servedAt : '2019-08-25T05:00:00.000Z' ,
333+ } ,
334+ petitioners : mockPetitioners ,
335+ } ) ;
336+
337+ expect ( filedByResult ) . toEqual ( mockFiledBy ) ;
338+ } ) ;
339+
340+ it ( 'should handle multiple private practitioners all party private practitioners' , ( ) => {
341+ const filedByResult = generateFiledBy ( {
342+ docketEntry : {
343+ ...mockDocketEntry ,
344+ filers : [ mockPrimaryContactId ] ,
345+ privatePractitioners : [
346+ {
347+ name : 'Alice Practitioner' ,
348+ partyPrivatePractitioner : true ,
349+ } ,
350+ {
351+ name : 'Bob Practitioner' ,
352+ partyPrivatePractitioner : true ,
353+ } ,
354+ ] ,
355+ } ,
356+ petitioners : mockPetitioners ,
357+ } ) ;
358+
359+ expect ( filedByResult ) . toEqual ( 'Alice Practitioner & Bob Practitioner' ) ;
360+ } ) ;
361+
362+ it ( 'should handle respondent only when there are no filers' , ( ) => {
363+ const filedByResult = generateFiledBy ( {
364+ docketEntry : {
365+ ...mockDocketEntry ,
366+ filers : [ ] ,
367+ partyIrsPractitioner : true ,
368+ } ,
369+ petitioners : mockPetitioners ,
370+ } ) ;
371+
372+ expect ( filedByResult ) . toEqual ( 'Resp.' ) ;
373+ } ) ;
374+
375+ it ( 'should handle respondent with otherFilingParty but no filers' , ( ) => {
376+ const filedByResult = generateFiledBy ( {
377+ docketEntry : {
378+ ...mockDocketEntry ,
379+ filers : [ ] ,
380+ otherFilingParty : mockOtherFilingParty ,
381+ partyIrsPractitioner : true ,
382+ } ,
383+ petitioners : mockPetitioners ,
384+ } ) ;
385+
386+ expect ( filedByResult ) . toEqual ( `Resp., ${ mockOtherFilingParty } ` ) ;
387+ } ) ;
388+
389+ it ( 'should handle multiple intervenors with respondent' , ( ) => {
390+ const mockIntervenors = mockPetitioners . map ( pet => ( {
391+ ...pet ,
392+ contactType : 'intervenor' ,
393+ } ) ) ;
394+ const filedByResult = generateFiledBy ( {
395+ docketEntry : {
396+ ...mockDocketEntry ,
397+ filers : [ mockPrimaryContactId , mockSecondaryContactId ] ,
398+ partyIrsPractitioner : true ,
399+ } ,
400+ petitioners : mockIntervenors ,
401+ } ) ;
402+
403+ expect ( filedByResult ) . toEqual ( 'Resp. & Intvs. Bob & Bill' ) ;
404+ } ) ;
405+
406+ it ( 'should handle complex scenario with respondent, petitioners, intervenors, and otherFilingParty' , ( ) => {
407+ const mockThirdContactId = 'third-contact-id' ;
408+ const mixedPetitioners = [
409+ {
410+ contactId : mockPrimaryContactId ,
411+ name : 'Bob' ,
412+ contactType : 'petitioner' ,
413+ } ,
414+ {
415+ contactId : mockSecondaryContactId ,
416+ name : 'Bill' ,
417+ contactType : 'intervenor' ,
418+ } ,
419+ {
420+ contactId : mockThirdContactId ,
421+ name : 'Alice' ,
422+ contactType : 'intervenor' ,
423+ } ,
424+ ] ;
425+ const filedByResult = generateFiledBy ( {
426+ docketEntry : {
427+ ...mockDocketEntry ,
428+ filers : [
429+ mockPrimaryContactId ,
430+ mockSecondaryContactId ,
431+ mockThirdContactId ,
432+ ] ,
433+ otherFilingParty : mockOtherFilingParty ,
434+ partyIrsPractitioner : true ,
435+ } ,
436+ petitioners : mixedPetitioners ,
437+ } ) ;
438+
439+ expect ( filedByResult ) . toEqual (
440+ `Resp. & Petr. Bob & Intvs. Bill & Alice, ${ mockOtherFilingParty } ` ,
441+ ) ;
442+ } ) ;
443+
444+ it ( 'should handle filers array with undefined entries' , ( ) => {
445+ const filedByResult = generateFiledBy ( {
446+ docketEntry : {
447+ ...mockDocketEntry ,
448+ filers : undefined ,
449+ } ,
450+ petitioners : mockPetitioners ,
451+ } ) ;
452+
453+ expect ( filedByResult ) . toEqual ( mockDocketEntry . filedBy ) ;
454+ } ) ;
455+
456+ it ( 'should treat contactType other than intervenor as petitioner' , ( ) => {
457+ const mockPetitionersWithOtherType = [
458+ {
459+ contactId : mockPrimaryContactId ,
460+ name : 'Bob' ,
461+ contactType : 'participant' ,
462+ } ,
463+ ] ;
464+ const filedByResult = generateFiledBy ( {
465+ docketEntry : {
466+ ...mockDocketEntry ,
467+ filers : [ mockPrimaryContactId ] ,
468+ } ,
469+ petitioners : mockPetitionersWithOtherType ,
470+ } ) ;
471+
472+ expect ( filedByResult ) . toEqual ( 'Petr. Bob' ) ;
473+ } ) ;
474+
475+ it ( 'should return existing filedBy when document has isLegacyServed set to true' , ( ) => {
476+ const mockFiledBy = 'Legacy Filed By' ;
477+ const filedByResult = generateFiledBy ( {
478+ docketEntry : {
479+ ...mockDocketEntry ,
480+ filedBy : mockFiledBy ,
481+ filers : [ mockPrimaryContactId ] ,
482+ isLegacyServed : true ,
483+ } ,
484+ petitioners : mockPetitioners ,
485+ } ) ;
486+
487+ expect ( filedByResult ) . toEqual ( mockFiledBy ) ;
488+ } ) ;
489+
490+ it ( 'should handle private practitioners with undefined privatePractitioners array' , ( ) => {
491+ const filedByResult = generateFiledBy ( {
492+ docketEntry : {
493+ ...mockDocketEntry ,
494+ filers : [ mockPrimaryContactId ] ,
495+ privatePractitioners : undefined ,
496+ } ,
497+ petitioners : mockPetitioners ,
498+ } ) ;
499+
500+ expect ( filedByResult ) . toEqual ( 'Petr. Bob' ) ;
501+ } ) ;
502+
503+ it ( 'should generate filedBy when notice of contact change is not auto-generated' , ( ) => {
504+ const filedByResult = generateFiledBy ( {
505+ docketEntry : {
506+ ...mockDocketEntry ,
507+ documentType : NOTICE_OF_CHANGE_CONTACT_INFORMATION_MAP [ 0 ] . documentType ,
508+ eventCode : NOTICE_OF_CHANGE_CONTACT_INFORMATION_MAP [ 0 ] . eventCode ,
509+ filers : [ mockPrimaryContactId ] ,
510+ isAutoGenerated : false ,
511+ } ,
512+ petitioners : mockPetitioners ,
513+ } ) ;
514+
515+ expect ( filedByResult ) . toEqual ( 'Petr. Bob' ) ;
516+ } ) ;
517+
518+ it ( 'should handle empty names arrays in formatPartyNames helper' , ( ) => {
519+ const filedByResult = generateFiledBy ( {
520+ docketEntry : {
521+ ...mockDocketEntry ,
522+ filers : [ ] ,
523+ partyIrsPractitioner : false ,
524+ } ,
525+ petitioners : mockPetitioners ,
526+ } ) ;
527+
528+ expect ( filedByResult ) . toEqual ( mockDocketEntry . filedBy ) ;
529+ } ) ;
530+
531+ it ( 'should handle single intervenor with otherFilingParty' , ( ) => {
532+ const mockIntervenors = [
533+ {
534+ contactId : mockPrimaryContactId ,
535+ name : 'Bob' ,
536+ contactType : 'intervenor' ,
537+ } ,
538+ ] ;
539+ const filedByResult = generateFiledBy ( {
540+ docketEntry : {
541+ ...mockDocketEntry ,
542+ filers : [ mockPrimaryContactId ] ,
543+ otherFilingParty : mockOtherFilingParty ,
544+ } ,
545+ petitioners : mockIntervenors ,
546+ } ) ;
547+
548+ expect ( filedByResult ) . toEqual ( `Intv. Bob, ${ mockOtherFilingParty } ` ) ;
549+ } ) ;
550+
551+ it ( 'should handle multiple intervenors with otherFilingParty' , ( ) => {
552+ const mockIntervenors = [
553+ {
554+ contactId : mockPrimaryContactId ,
555+ name : 'Bob' ,
556+ contactType : 'intervenor' ,
557+ } ,
558+ {
559+ contactId : mockSecondaryContactId ,
560+ name : 'Bill' ,
561+ contactType : 'intervenor' ,
562+ } ,
563+ ] ;
564+ const filedByResult = generateFiledBy ( {
565+ docketEntry : {
566+ ...mockDocketEntry ,
567+ filers : [ mockPrimaryContactId , mockSecondaryContactId ] ,
568+ otherFilingParty : mockOtherFilingParty ,
569+ } ,
570+ petitioners : mockIntervenors ,
571+ } ) ;
572+
573+ expect ( filedByResult ) . toEqual ( `Intvs. Bob & Bill, ${ mockOtherFilingParty } ` ) ;
574+ } ) ;
321575} ) ;
0 commit comments