@@ -2620,6 +2620,144 @@ func TestHandleInvokeActionLenderActionSendNotification_emailServiceNotReady(t *
26202620 assert .Equal (t , LenderStateValidated , mockPrRepo .savedPr .State )
26212621}
26222622
2623+ func TestHandleInvokeBorrowerActionCancelLocalSupply (t * testing.T ) {
2624+ mockPrRepo := new (MockPrRepo )
2625+ lmsCreator := new (MockLmsCreator )
2626+ lmsCreator .On ("GetAdapter" , "ISIL:REQ1" ).Return (lms .CreateLmsAdapterMockOK (), nil )
2627+ mockIso18626Handler := new (MockIso18626Handler )
2628+ prAction := CreatePatronRequestActionService (mockPrRepo , new (IllRepoMock ), * new (events.EventBus ), mockIso18626Handler , lmsCreator , new (EmailSenderMock ))
2629+ illRequest := iso18626.Request {}
2630+ mockPrRepo .On ("GetPatronRequestById" , patronRequestId ).Return (pr_db.PatronRequest {
2631+ ID : patronRequestId ,
2632+ IllRequest : illRequest ,
2633+ State : BorrowerStateLocalSupply ,
2634+ Side : SideBorrowing ,
2635+ SupplierSymbol : getDbText ("ISIL:SUP1" ),
2636+ RequesterSymbol : getDbText ("ISIL:REQ1" ),
2637+ RequesterReqID : getDbText ("req-1" ),
2638+ }, nil )
2639+ action := BorrowerActionCancelLocalSupply
2640+
2641+ status , resultData := prAction .handleInvokeAction (appCtx , events.Event {
2642+ PatronRequestID : patronRequestId ,
2643+ EventData : events.EventData {CommonEventData : events.CommonEventData {Action : & action }},
2644+ })
2645+
2646+ assert .Equal (t , events .EventStatusSuccess , status )
2647+ assert .NotNil (t , resultData )
2648+ assert .Equal (t , BorrowerStateCancelled , mockPrRepo .savedPr .State )
2649+ assert .NotNil (t , mockIso18626Handler .lastSupplyingAgencyMessage )
2650+ assert .Equal (t , iso18626 .TypeReasonForMessageStatusChange , mockIso18626Handler .lastSupplyingAgencyMessage .MessageInfo .ReasonForMessage )
2651+ assert .Equal (t , iso18626 .TypeStatusCancelled , mockIso18626Handler .lastSupplyingAgencyMessage .StatusInfo .Status )
2652+ assert .False (t , mockIso18626Handler .lastSupplyingAgencyMessage .Header .Timestamp .IsZero ())
2653+ assert .Nil (t , mockIso18626Handler .lastSupplyingAgencyMessage .MessageInfo .AnswerYesNo )
2654+ }
2655+
2656+ func TestHandleInvokeBorrowerActionCannotSupplyLocally (t * testing.T ) {
2657+ mockPrRepo := new (MockPrRepo )
2658+ lmsCreator := new (MockLmsCreator )
2659+ lmsCreator .On ("GetAdapter" , "ISIL:REQ1" ).Return (lms .CreateLmsAdapterMockOK (), nil )
2660+ mockIso18626Handler := new (MockIso18626Handler )
2661+ prAction := CreatePatronRequestActionService (mockPrRepo , new (IllRepoMock ), * new (events.EventBus ), mockIso18626Handler , lmsCreator , new (EmailSenderMock ))
2662+ illRequest := iso18626.Request {}
2663+ mockPrRepo .On ("GetPatronRequestById" , patronRequestId ).Return (pr_db.PatronRequest {
2664+ ID : patronRequestId ,
2665+ IllRequest : illRequest ,
2666+ State : BorrowerStateLocalSupply ,
2667+ Side : SideBorrowing ,
2668+ SupplierSymbol : getDbText ("ISIL:SUP1" ),
2669+ RequesterSymbol : getDbText ("ISIL:REQ1" ),
2670+ RequesterReqID : getDbText ("req-1" ),
2671+ }, nil )
2672+ action := BorrowerActionCannotSupplyLocally
2673+
2674+ status , resultData := prAction .handleInvokeAction (appCtx , events.Event {
2675+ PatronRequestID : patronRequestId ,
2676+ EventData : events.EventData {CommonEventData : events.CommonEventData {Action : & action }},
2677+ })
2678+
2679+ assert .Equal (t , events .EventStatusSuccess , status )
2680+ assert .NotNil (t , resultData )
2681+ assert .Equal (t , BorrowerStateSent , mockPrRepo .savedPr .State )
2682+ assert .NotNil (t , mockIso18626Handler .lastSupplyingAgencyMessage )
2683+ assert .Equal (t , iso18626 .TypeReasonForMessageStatusChange , mockIso18626Handler .lastSupplyingAgencyMessage .MessageInfo .ReasonForMessage )
2684+ assert .Equal (t , iso18626 .TypeStatusUnfilled , mockIso18626Handler .lastSupplyingAgencyMessage .StatusInfo .Status )
2685+ assert .False (t , mockIso18626Handler .lastSupplyingAgencyMessage .Header .Timestamp .IsZero ())
2686+ }
2687+
2688+ func TestHandleInvokeBorrowerActionFillLocally (t * testing.T ) {
2689+ tests := []struct {
2690+ name string
2691+ serviceType iso18626.TypeServiceType
2692+ manualAdapter bool
2693+ expectedStatus iso18626.TypeStatus
2694+ }{
2695+ {name : "loan" , serviceType : iso18626 .TypeServiceTypeLoan , expectedStatus : iso18626 .TypeStatusLoanCompleted },
2696+ {name : "copy" , serviceType : iso18626 .TypeServiceTypeCopy , expectedStatus : iso18626 .TypeStatusCopyCompleted },
2697+ {name : "NCIP disabled" , serviceType : iso18626 .TypeServiceTypeLoan , manualAdapter : true , expectedStatus : iso18626 .TypeStatusLoanCompleted },
2698+ }
2699+
2700+ for _ , tt := range tests {
2701+ t .Run (tt .name , func (t * testing.T ) {
2702+ mockPrRepo := new (MockPrRepo )
2703+ lmsCreator := new (MockLmsCreator )
2704+ mockIso18626Handler := new (MockIso18626Handler )
2705+ illRequest := iso18626.Request {
2706+ BibliographicInfo : iso18626.BibliographicInfo {SupplierUniqueRecordId : "local-record-1" },
2707+ ServiceInfo : & iso18626.ServiceInfo {ServiceType : tt .serviceType },
2708+ }
2709+ pr := pr_db.PatronRequest {
2710+ ID : patronRequestId ,
2711+ IllRequest : illRequest ,
2712+ State : BorrowerStateLocalSupply ,
2713+ Side : SideBorrowing ,
2714+ Patron : getDbText ("patron-1" ),
2715+ RequesterSymbol : getDbText ("ISIL:REQ1" ),
2716+ SupplierSymbol : getDbText ("ISIL:REQ1" ),
2717+ RequesterReqID : getDbText ("req-1" ),
2718+ NeedsAttention : true ,
2719+ }
2720+
2721+ var lmsAdapter lms.LmsAdapter
2722+ if tt .manualAdapter {
2723+ lmsAdapter = & lms.LmsAdapterManual {}
2724+ } else {
2725+ adapterMock := & mockLmsAdapter {
2726+ requesterPickupLocation : "pickup-1" ,
2727+ itemLocation : "item-location-1" ,
2728+ }
2729+ adapterMock .On ("RequestItem" , patronRequestId , "local-record-1" , "patron-1" , "pickup-1" , "item-location-1" ).
2730+ Return ("" , "" , "" , nil )
2731+ lmsAdapter = adapterMock
2732+ }
2733+ lmsCreator .On ("GetAdapter" , "ISIL:REQ1" ).Return (lmsAdapter , nil )
2734+ mockPrRepo .On ("GetPatronRequestById" , patronRequestId ).Return (pr , nil )
2735+ prAction := CreatePatronRequestActionService (mockPrRepo , new (IllRepoMock ), * new (events.EventBus ), mockIso18626Handler , lmsCreator , new (EmailSenderMock ))
2736+ action := BorrowerActionFillLocally
2737+
2738+ status , resultData := prAction .handleInvokeAction (appCtx , events.Event {
2739+ PatronRequestID : patronRequestId ,
2740+ EventData : events.EventData {CommonEventData : events.CommonEventData {Action : & action }},
2741+ })
2742+
2743+ assert .Equal (t , events .EventStatusSuccess , status )
2744+ if assert .NotNil (t , resultData .ActionResult ) && assert .NotNil (t , resultData .ActionResult .ToState ) {
2745+ assert .Equal (t , string (BorrowerStateCompleted ), * resultData .ActionResult .ToState )
2746+ }
2747+ assert .Equal (t , BorrowerStateCompleted , mockPrRepo .savedPr .State )
2748+ assert .True (t , mockPrRepo .savedPr .TerminalState )
2749+ assert .False (t , mockPrRepo .savedPr .NeedsAttention )
2750+ if assert .NotNil (t , mockIso18626Handler .lastSupplyingAgencyMessage ) {
2751+ assert .Equal (t , tt .expectedStatus , mockIso18626Handler .lastSupplyingAgencyMessage .StatusInfo .Status )
2752+ assert .Equal (t , iso18626 .TypeReasonForMessageStatusChange , mockIso18626Handler .lastSupplyingAgencyMessage .MessageInfo .ReasonForMessage )
2753+ }
2754+ if adapterMock , ok := lmsAdapter .(* mockLmsAdapter ); ok {
2755+ adapterMock .AssertExpectations (t )
2756+ }
2757+ })
2758+ }
2759+ }
2760+
26232761type MockEventBus struct {
26242762 mock.Mock
26252763 events.EventBus
@@ -3088,6 +3226,16 @@ func TestLoadReturnableStateModel(t *testing.T) {
30883226type mockLmsAdapter struct {
30893227 mock.Mock
30903228 lms.LmsAdapterManual
3229+ requesterPickupLocation string
3230+ itemLocation string
3231+ }
3232+
3233+ func (m * mockLmsAdapter ) RequesterPickupLocation () string {
3234+ return m .requesterPickupLocation
3235+ }
3236+
3237+ func (m * mockLmsAdapter ) ItemLocation () string {
3238+ return m .itemLocation
30913239}
30923240
30933241func (m * mockLmsAdapter ) CancelRequestItem (requestId string , userId string ) error {
0 commit comments