@@ -736,22 +736,125 @@ func TestHandleSupplyingAgencyMessageCancelled(t *testing.T) {
736736 assert .NoError (t , err )
737737}
738738
739- func TestHandleSupplyingAgencyMessageCancelledStatusChangeRejected (t * testing.T ) {
739+ func TestHandleSupplyingAgencyMessageCancelledStatusChangeAcceptedWithoutTransition (t * testing.T ) {
740+ mockPrRepo := new (MockPrRepo )
741+ handler := CreatePatronRequestMessageHandler (mockPrRepo , * new (events.EventRepo ), * new (ill_db.IllRepo ), * new (events.EventBus ))
742+
743+ status , resp , err := handler .handleSupplyingAgencyMessage (appCtx , iso18626.SupplyingAgencyMessage {
744+ Header : iso18626.Header {
745+ SupplyingAgencyId : iso18626.TypeAgencyId {
746+ AgencyIdType : iso18626.TypeSchemeValuePair {Text : "ISIL" },
747+ AgencyIdValue : "REQ" ,
748+ },
749+ RequestingAgencyRequestId : patronRequestId ,
750+ },
751+ MessageInfo : iso18626.MessageInfo {
752+ ReasonForMessage : iso18626 .TypeReasonForMessageStatusChange ,
753+ },
754+ StatusInfo : iso18626.StatusInfo {Status : iso18626 .TypeStatusCancelled },
755+ }, pr_db.PatronRequest {
756+ ID : patronRequestId ,
757+ RequesterSymbol : pgtype.Text {Valid : true , String : "ISIL:REQ" },
758+ State : BorrowerStateLocalSupply ,
759+ Side : SideBorrowing ,
760+ })
761+ assert .Equal (t , events .EventStatusSuccess , status )
762+ assert .Equal (t , iso18626 .TypeMessageStatusOK , resp .SupplyingAgencyMessageConfirmation .ConfirmationHeader .MessageStatus )
763+ assert .NoError (t , err )
764+ assert .Equal (t , patronRequestId , mockPrRepo .savedPr .ID )
765+ assert .Equal (t , BorrowerStateLocalSupply , mockPrRepo .savedPr .State )
766+ }
767+
768+ func TestHandleSupplyingAgencyMessageCancelledStatusChangeRejectedWhenNotLocalSupply (t * testing.T ) {
740769 handler := CreatePatronRequestMessageHandler (new (MockPrRepo ), * new (events.EventRepo ), * new (ill_db.IllRepo ), * new (events.EventBus ))
741770
742771 status , resp , err := handler .handleSupplyingAgencyMessage (appCtx , iso18626.SupplyingAgencyMessage {
743772 Header : iso18626.Header {
773+ SupplyingAgencyId : iso18626.TypeAgencyId {
774+ AgencyIdType : iso18626.TypeSchemeValuePair {Text : "ISIL" },
775+ AgencyIdValue : "REQ" ,
776+ },
744777 RequestingAgencyRequestId : patronRequestId ,
745778 },
746779 MessageInfo : iso18626.MessageInfo {
747780 ReasonForMessage : iso18626 .TypeReasonForMessageStatusChange ,
748781 },
749782 StatusInfo : iso18626.StatusInfo {Status : iso18626 .TypeStatusCancelled },
750- }, pr_db.PatronRequest {})
783+ }, pr_db.PatronRequest {
784+ RequesterSymbol : pgtype.Text {Valid : true , String : "ISIL:REQ" },
785+ State : BorrowerStateSent ,
786+ Side : SideBorrowing ,
787+ })
751788 assert .Equal (t , events .EventStatusProblem , status )
752789 assert .Equal (t , iso18626 .TypeMessageStatusERROR , resp .SupplyingAgencyMessageConfirmation .ConfirmationHeader .MessageStatus )
753- assert .Contains (t , resp .SupplyingAgencyMessageConfirmation .ErrorData .ErrorValue , "status change not allowed:" )
754- assert .Contains (t , err .Error (), "status change not allowed:" )
790+ if assert .Error (t , err ) {
791+ assert .Contains (t , err .Error (), "status change not allowed:" )
792+ }
793+ }
794+
795+ func TestHandleSupplyingAgencyMessageLocalSupplyCompletedAcceptedWithoutTransition (t * testing.T ) {
796+ for _ , completedStatus := range []iso18626.TypeStatus {
797+ iso18626 .TypeStatusLoanCompleted ,
798+ iso18626 .TypeStatusCopyCompleted ,
799+ } {
800+ t .Run (string (completedStatus ), func (t * testing.T ) {
801+ mockPrRepo := new (MockPrRepo )
802+ handler := CreatePatronRequestMessageHandler (mockPrRepo , * new (events.EventRepo ), * new (ill_db.IllRepo ), * new (events.EventBus ))
803+
804+ status , resp , err := handler .handleSupplyingAgencyMessage (appCtx , iso18626.SupplyingAgencyMessage {
805+ Header : iso18626.Header {
806+ SupplyingAgencyId : iso18626.TypeAgencyId {
807+ AgencyIdType : iso18626.TypeSchemeValuePair {Text : "ISIL" },
808+ AgencyIdValue : "REQ" ,
809+ },
810+ RequestingAgencyRequestId : patronRequestId ,
811+ },
812+ MessageInfo : iso18626.MessageInfo {
813+ ReasonForMessage : iso18626 .TypeReasonForMessageStatusChange ,
814+ },
815+ StatusInfo : iso18626.StatusInfo {Status : completedStatus },
816+ }, pr_db.PatronRequest {
817+ ID : patronRequestId ,
818+ RequesterSymbol : pgtype.Text {Valid : true , String : "ISIL:REQ" },
819+ State : BorrowerStateLocalSupply ,
820+ Side : SideBorrowing ,
821+ })
822+ assert .Equal (t , events .EventStatusSuccess , status )
823+ assert .Equal (t , iso18626 .TypeMessageStatusOK , resp .SupplyingAgencyMessageConfirmation .ConfirmationHeader .MessageStatus )
824+ assert .NoError (t , err )
825+ assert .Equal (t , patronRequestId , mockPrRepo .savedPr .ID )
826+ assert .Equal (t , BorrowerStateLocalSupply , mockPrRepo .savedPr .State )
827+ })
828+ }
829+ }
830+
831+ func TestHandleSupplyingAgencyMessageLocalSupplyUnfilledAcceptedWithoutTransition (t * testing.T ) {
832+ mockPrRepo := new (MockPrRepo )
833+ handler := CreatePatronRequestMessageHandler (mockPrRepo , * new (events.EventRepo ), * new (ill_db.IllRepo ), * new (events.EventBus ))
834+
835+ status , resp , err := handler .handleSupplyingAgencyMessage (appCtx , iso18626.SupplyingAgencyMessage {
836+ Header : iso18626.Header {
837+ SupplyingAgencyId : iso18626.TypeAgencyId {
838+ AgencyIdType : iso18626.TypeSchemeValuePair {Text : "ISIL" },
839+ AgencyIdValue : "REQ" ,
840+ },
841+ RequestingAgencyRequestId : patronRequestId ,
842+ },
843+ MessageInfo : iso18626.MessageInfo {
844+ ReasonForMessage : iso18626 .TypeReasonForMessageStatusChange ,
845+ },
846+ StatusInfo : iso18626.StatusInfo {Status : iso18626 .TypeStatusUnfilled },
847+ }, pr_db.PatronRequest {
848+ ID : patronRequestId ,
849+ RequesterSymbol : pgtype.Text {Valid : true , String : "ISIL:REQ" },
850+ State : BorrowerStateLocalSupply ,
851+ Side : SideBorrowing ,
852+ })
853+ assert .Equal (t , events .EventStatusSuccess , status )
854+ assert .Equal (t , iso18626 .TypeMessageStatusOK , resp .SupplyingAgencyMessageConfirmation .ConfirmationHeader .MessageStatus )
855+ assert .NoError (t , err )
856+ assert .Equal (t , patronRequestId , mockPrRepo .savedPr .ID )
857+ assert .Equal (t , BorrowerStateLocalSupply , mockPrRepo .savedPr .State )
755858}
756859
757860func TestHandleSupplyingAgencyMessageCancelResponseCancelled (t * testing.T ) {
0 commit comments