@@ -2,6 +2,7 @@ import type { TFunction } from "i18next";
22import { describe , expect , it , vi } from "vitest" ;
33
44import * as event from "./event" ;
5+ import { updateHostInEventName } from "./event" ;
56
67describe ( "event tests" , ( ) => {
78 describe ( "fn: getEventName" , ( ) => {
@@ -423,4 +424,128 @@ describe("event tests", () => {
423424 expect ( event . validateCustomEventName ( "foo{nonsenseField}bar" ) ) . toBe ( "{nonsenseField}" ) ;
424425 } ) ;
425426 } ) ;
427+
428+ describe ( "fn: updateHostInEventName" , ( ) => {
429+ const oldHost = "John Doe" ;
430+ const newHost = "Jane Smith" ;
431+
432+ it ( "should replace full host name with spaces" , ( ) => {
433+ const eventName = "Meeting with John Doe" ;
434+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
435+ expect ( result ) . toBe ( "Meeting with Jane Smith" ) ;
436+ } ) ;
437+
438+ it ( "should replace full host name with dots" , ( ) => {
439+ const eventName = "Meeting with John.Doe" ;
440+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
441+ expect ( result ) . toBe ( "Meeting with Jane.Smith" ) ;
442+ } ) ;
443+
444+ it ( "should replace full host name with hyphens" , ( ) => {
445+ const eventName = "Meeting with John-Doe" ;
446+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
447+ expect ( result ) . toBe ( "Meeting with Jane-Smith" ) ;
448+ } ) ;
449+
450+ it ( "should replace full host name with underscores" , ( ) => {
451+ const eventName = "Meeting with John_Doe" ;
452+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
453+ expect ( result ) . toBe ( "Meeting with Jane_Smith" ) ;
454+ } ) ;
455+
456+ it ( "should replace first name only" , ( ) => {
457+ const eventName = "John's presentation" ;
458+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
459+ expect ( result ) . toBe ( "Jane's presentation" ) ;
460+ } ) ;
461+
462+ it ( "should replace first name at the beginning" , ( ) => {
463+ const eventName = "John will present tomorrow" ;
464+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
465+ expect ( result ) . toBe ( "Jane will present tomorrow" ) ;
466+ } ) ;
467+
468+ it ( "should replace first name at the end" , ( ) => {
469+ const eventName = "Presentation by John" ;
470+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
471+ expect ( result ) . toBe ( "Presentation by Jane" ) ;
472+ } ) ;
473+
474+ it ( "should handle different cases" , ( ) => {
475+ const eventName = "meeting with john.doe" ;
476+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
477+ expect ( result ) . toBe ( "meeting with Jane.Smith" ) ;
478+ } ) ;
479+
480+ it ( "should handle mixed cases" , ( ) => {
481+ const eventName = "Meeting with JOHN DOE" ;
482+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
483+ expect ( result ) . toBe ( "Meeting with Jane Smith" ) ;
484+ } ) ;
485+
486+ it ( "should not replace partial matches" , ( ) => {
487+ const eventName = "Meeting with Johnson" ;
488+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
489+ expect ( result ) . toBe ( "Meeting with Johnson" ) ;
490+ } ) ;
491+
492+ it ( "should handle empty event name" , ( ) => {
493+ const result = updateHostInEventName ( "" , oldHost , newHost ) ;
494+ expect ( result ) . toBe ( "" ) ;
495+ } ) ;
496+
497+ it ( "should handle event name without host" , ( ) => {
498+ const eventName = "Team meeting" ;
499+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
500+ expect ( result ) . toBe ( "Team meeting" ) ;
501+ } ) ;
502+
503+ it ( "should handle single word names" , ( ) => {
504+ const eventName = "Meeting with John" ;
505+ const result = updateHostInEventName ( eventName , "John" , "Jane" ) ;
506+ expect ( result ) . toBe ( "Meeting with Jane" ) ;
507+ } ) ;
508+
509+ it ( "should handle names with multiple parts" , ( ) => {
510+ const eventName = "Meeting with John van der Berg" ;
511+ const result = updateHostInEventName ( eventName , "John van der Berg" , "Jane Smith" ) ;
512+ expect ( result ) . toBe ( "Meeting with Jane Smith" ) ;
513+ } ) ;
514+
515+ it ( "should handle names with apostrophes" , ( ) => {
516+ const eventName = "Meeting with John O'Connor" ;
517+ const result = updateHostInEventName ( eventName , "John O'Connor" , "Jane Smith" ) ;
518+ expect ( result ) . toBe ( "Meeting with Jane Smith" ) ;
519+ } ) ;
520+
521+ it ( "should handle names with special characters" , ( ) => {
522+ const eventName = "Meeting with Jean-Pierre Dupont" ;
523+ const result = updateHostInEventName ( eventName , "Jean-Pierre Dupont" , "Jane Smith" ) ;
524+ expect ( result ) . toBe ( "Meeting with Jane Smith" ) ;
525+ } ) ;
526+
527+ it ( "should prioritize full name over first name" , ( ) => {
528+ const eventName = "John.Doe and John are coming" ;
529+ const result = updateHostInEventName ( eventName , "John Doe" , "Jane Smith" ) ;
530+ expect ( result ) . toBe ( "Jane.Smith and John are coming" ) ;
531+ } ) ;
532+
533+ it ( "should only replace first match" , ( ) => {
534+ const eventName = "John.Doe and John Doe meeting" ;
535+ const result = updateHostInEventName ( eventName , "John Doe" , "Jane Smith" ) ;
536+ expect ( result ) . toBe ( "Jane.Smith and John Doe meeting" ) ;
537+ } ) ;
538+
539+ it ( "should handle different new name structure" , ( ) => {
540+ const eventName = "Meeting with John.Doe" ;
541+ const result = updateHostInEventName ( eventName , "John Doe" , "Jane" ) ;
542+ expect ( result ) . toBe ( "Meeting with Jane" ) ;
543+ } ) ;
544+
545+ it ( "should handle multiple occurrences with priority" , ( ) => {
546+ const eventName = "John and John.Doe and John_Doe" ;
547+ const result = updateHostInEventName ( eventName , oldHost , newHost ) ;
548+ expect ( result ) . toBe ( "John and Jane.Smith and John_Doe" ) ;
549+ } ) ;
550+ } ) ;
426551} ) ;
0 commit comments