@@ -280,6 +280,40 @@ describe('AgControler', () => {
280280 gig : { } ,
281281 } ) ) . rejects . toThrow ( 'Invalid gig data' ) ;
282282 } ) ;
283+ it ( 'updates a gig when venueId is set and venue/city/usState are empty strings (#256)' , async ( ) => {
284+ const agController = new AgController ( aStub ) ;
285+ agController . gigController . findByIdAndUpdate = vi . fn ( ( ) => Promise . resolve ( true ) ) ;
286+ r = await agController . updateGig ( {
287+ gigId : testId ,
288+ gig : {
289+ venueId : testId , datetime : new Date ( ) , venue : '' , city : '' , usState : '' ,
290+ } ,
291+ } ) ;
292+ expect ( r ) . toBe ( 'Gig updated' ) ;
293+ } ) ;
294+ it ( 'updates a one-off gig with only free-text venue set and no venueId (#256)' , async ( ) => {
295+ const agController = new AgController ( aStub ) ;
296+ agController . gigController . findByIdAndUpdate = vi . fn ( ( ) => Promise . resolve ( true ) ) ;
297+ r = await agController . updateGig ( {
298+ gigId : testId ,
299+ gig : { venue : 'The Local Bar' , datetime : new Date ( ) } ,
300+ } ) ;
301+ expect ( r ) . toBe ( 'Gig updated' ) ;
302+ } ) ;
303+ it ( 'rejects updateGig when neither venueId nor venue is set (#256)' , async ( ) => {
304+ const agController = new AgController ( aStub ) ;
305+ await expect ( agController . updateGig ( {
306+ gigId : testId ,
307+ gig : { datetime : new Date ( ) } ,
308+ } ) ) . rejects . toThrow ( 'Invalid gig data' ) ;
309+ } ) ;
310+ it ( 'rejects updateGig when datetime is missing even though venueId is set (#256)' , async ( ) => {
311+ const agController = new AgController ( aStub ) ;
312+ await expect ( agController . updateGig ( {
313+ gigId : testId ,
314+ gig : { venueId : testId } ,
315+ } ) ) . rejects . toThrow ( 'Invalid gig data' ) ;
316+ } ) ;
283317 it ( 'does not process the newTour message from client when token is not valid' , async ( ) => {
284318 const agController = new AgController ( aStub ) ;
285319 agController . clients = [ '123' ] ;
@@ -494,6 +528,124 @@ describe('AgControler', () => {
494528 { newGig : 'Invalid create gig data' } ,
495529 ) ;
496530 } ) ;
531+ it ( 'creates a gig when venueId is set and venue/city/usState are empty strings (#256)' , async ( ) => {
532+ const agController = new AgController ( aStub ) ;
533+ agController . clients = [ '123' ] ;
534+ agController . gigController . createDocs = vi . fn ( ( ) => Promise . resolve ( [ ] ) ) ;
535+ agController . verifyAdminWrite = vi . fn ( ( ) => Promise . resolve ( ) ) ;
536+ const cStub :any = {
537+ socket : {
538+ id : '123' ,
539+ listener : ( ) => ( { createConsumer : ( ) => ( { next : ( ) => Promise . resolve ( { done : true , value : '1000' } ) } ) } ) ,
540+ transmit : ( ) => { } ,
541+ receiver : ( ) => ( {
542+ createConsumer : ( ) => ( {
543+ next : ( ) => Promise . resolve ( {
544+ value : {
545+ token : 'token' ,
546+ gig : {
547+ venueId : testId , datetime : new Date ( ) , venue : '' , city : '' , usState : '' ,
548+ } ,
549+ } ,
550+ done : true ,
551+ } ) ,
552+ } ) ,
553+ } ) ,
554+ } ,
555+ } ;
556+ const setIntervalMock :any = vi . fn ( ( cb :any ) => cb ( ) ) ;
557+ global . setInterval = setIntervalMock ;
558+ agController . newGig ( cStub , 'newGig' ) ;
559+ await delay ( 1000 ) ;
560+ expect ( agController . gigController . createDocs ) . toHaveBeenCalled ( ) ;
561+ } ) ;
562+ it ( 'creates a one-off gig with only free-text venue set and no venueId (#256)' , async ( ) => {
563+ const agController = new AgController ( aStub ) ;
564+ agController . clients = [ '123' ] ;
565+ agController . gigController . createDocs = vi . fn ( ( ) => Promise . resolve ( [ ] ) ) ;
566+ agController . verifyAdminWrite = vi . fn ( ( ) => Promise . resolve ( ) ) ;
567+ const cStub :any = {
568+ socket : {
569+ id : '123' ,
570+ listener : ( ) => ( { createConsumer : ( ) => ( { next : ( ) => Promise . resolve ( { done : true , value : '1000' } ) } ) } ) ,
571+ transmit : ( ) => { } ,
572+ receiver : ( ) => ( {
573+ createConsumer : ( ) => ( {
574+ next : ( ) => Promise . resolve ( {
575+ value : {
576+ token : 'token' ,
577+ gig : { venue : 'The Local Bar' , datetime : new Date ( ) } ,
578+ } ,
579+ done : true ,
580+ } ) ,
581+ } ) ,
582+ } ) ,
583+ } ,
584+ } ;
585+ const setIntervalMock :any = vi . fn ( ( cb :any ) => cb ( ) ) ;
586+ global . setInterval = setIntervalMock ;
587+ agController . newGig ( cStub , 'newGig' ) ;
588+ await delay ( 1000 ) ;
589+ expect ( agController . gigController . createDocs ) . toHaveBeenCalled ( ) ;
590+ } ) ;
591+ it ( 'rejects newGig with neither venueId nor venue (#256)' , async ( ) => {
592+ const agController = new AgController ( aStub ) ;
593+ agController . clients = [ '123' ] ;
594+ agController . gigController . createDocs = vi . fn ( ( ) => Promise . resolve ( [ ] ) ) ;
595+ agController . verifyAdminWrite = vi . fn ( ( ) => Promise . resolve ( ) ) ;
596+ const eStub :any = {
597+ socket : {
598+ id : '123' ,
599+ listener : ( ) => ( { createConsumer : ( ) => ( { next : ( ) => Promise . resolve ( { done : true , value : '1000' } ) } ) } ) ,
600+ transmit : vi . fn ( ) ,
601+ receiver : ( ) => ( {
602+ createConsumer : ( ) => ( {
603+ next : ( ) => Promise . resolve ( {
604+ value : {
605+ token : 'token' ,
606+ gig : { datetime : new Date ( ) } ,
607+ } ,
608+ done : true ,
609+ } ) ,
610+ } ) ,
611+ } ) ,
612+ } ,
613+ } ;
614+ const setIntervalMock :any = vi . fn ( ( cb :any ) => cb ( ) ) ;
615+ global . setInterval = setIntervalMock ;
616+ agController . newGig ( eStub , 'newGig' ) ;
617+ await delay ( 1000 ) ;
618+ expect ( eStub . socket . transmit ) . toHaveBeenCalledWith ( 'socketError' , { newGig : 'Invalid create gig data' } ) ;
619+ } ) ;
620+ it ( 'rejects newGig when datetime is missing even though venueId is set (#256)' , async ( ) => {
621+ const agController = new AgController ( aStub ) ;
622+ agController . clients = [ '123' ] ;
623+ agController . gigController . createDocs = vi . fn ( ( ) => Promise . resolve ( [ ] ) ) ;
624+ agController . verifyAdminWrite = vi . fn ( ( ) => Promise . resolve ( ) ) ;
625+ const eStub :any = {
626+ socket : {
627+ id : '123' ,
628+ listener : ( ) => ( { createConsumer : ( ) => ( { next : ( ) => Promise . resolve ( { done : true , value : '1000' } ) } ) } ) ,
629+ transmit : vi . fn ( ) ,
630+ receiver : ( ) => ( {
631+ createConsumer : ( ) => ( {
632+ next : ( ) => Promise . resolve ( {
633+ value : {
634+ token : 'token' ,
635+ gig : { venueId : testId } ,
636+ } ,
637+ done : true ,
638+ } ) ,
639+ } ) ,
640+ } ) ,
641+ } ,
642+ } ;
643+ const setIntervalMock :any = vi . fn ( ( cb :any ) => cb ( ) ) ;
644+ global . setInterval = setIntervalMock ;
645+ agController . newGig ( eStub , 'newGig' ) ;
646+ await delay ( 1000 ) ;
647+ expect ( eStub . socket . transmit ) . toHaveBeenCalledWith ( 'socketError' , { newGig : 'Invalid create gig data' } ) ;
648+ } ) ;
497649 it ( 'handles missing receiver value when process the newTour message from client' , ( ) => {
498650 const agController = new AgController ( aStub ) ;
499651 agController . clients = [ '123' ] ;
0 commit comments