@@ -209,6 +209,36 @@ func TestHandleInvokeActionValidateSendRequest(t *testing.T) {
209209 assert .Equal (t , ActionOutcomeSuccess , resultData .ActionResult .Outcome )
210210}
211211
212+ func TestHandleInvokeActionValidateSendRequestDuplicate (t * testing.T ) {
213+ mockPrRepo := new (MockPrRepo )
214+ lmsCreator := new (MockLmsCreator )
215+ mockEventBus := new (MockEventBus )
216+ mockIso18626Handler := new (MockIso18626Handler )
217+ patronRequestId := "duplicate"
218+
219+ lmsCreator .On ("GetAdapter" , "ISIL:x" ).Return (createLmsAdapterMockLog (), nil )
220+ prAction := CreatePatronRequestActionService (mockPrRepo , new (IllRepoMock ), mockEventBus , mockIso18626Handler , lmsCreator , new (EmailSenderMock ))
221+ illRequest := iso18626.Request {BibliographicInfo : iso18626.BibliographicInfo {SupplierUniqueRecordId : "12312" }}
222+ fakeEventID := "1234"
223+ initialPR := pr_db.PatronRequest {ID : patronRequestId , IllRequest : illRequest , RequesterSymbol : pgtype.Text {Valid : true , String : "ISIL:x" }, State : BorrowerStateNew , Side : SideBorrowing , Tenant : pgtype.Text {Valid : true , String : "testlib" }}
224+ validatedPR := initialPR
225+ validatedPR .State = BorrowerStateValidated
226+ sentPR := initialPR
227+ sentPR .State = BorrowerStateSent
228+ mockPrRepo .On ("GetPatronRequestById" , patronRequestId ).Return (initialPR , nil ).Once ()
229+ mockPrRepo .On ("GetPatronRequestById" , patronRequestId ).Return (validatedPR , nil ).Once ()
230+ mockPrRepo .On ("GetPatronRequestById" , patronRequestId ).Return (sentPR , nil ).Once ()
231+ mockEventBus .On ("CreateNoticeWithParent" , fakeEventID ).Return ("" , nil )
232+
233+ status , resultData := prAction .handleInvokeAction (appCtx , events.Event {ID : fakeEventID , PatronRequestID : patronRequestId , EventData : events.EventData {CommonEventData : events.CommonEventData {Action : & actionValidate }}})
234+
235+ assert .Equal (t , events .EventStatusSuccess , status )
236+ assert .NotNil (t , resultData )
237+ assert .Equal (t , BorrowerStateClosedDuplicate , mockPrRepo .savedPr .State )
238+ assert .Equal (t , string (BorrowerActionSendRequest ), mockPrRepo .savedPr .LastAction .String )
239+ assert .Equal (t , ActionOutcomeDuplicate , mockPrRepo .savedPr .LastActionOutcome .String )
240+ }
241+
212242func TestHandleInvokeActionValidateGetAdapterFailed (t * testing.T ) {
213243 mockPrRepo := new (MockPrRepo )
214244 lmsCreator := new (MockLmsCreator )
@@ -2685,6 +2715,13 @@ func (h *MockIso18626Handler) HandleRequest(ctx common.ExtendedContext, illMessa
26852715 MessageStatus : status ,
26862716 },
26872717 }
2718+ if illMessage .Request .Header .RequestingAgencyRequestId == "duplicate" {
2719+ resmsg .RequestConfirmation .ConfirmationHeader .MessageStatus = iso18626 .TypeMessageStatusERROR
2720+ resmsg .RequestConfirmation .ErrorData = & iso18626.ErrorData {
2721+ ErrorType : iso18626 .TypeErrorTypeUnrecognisedDataValue ,
2722+ ErrorValue : string (handler .ReqIsDuplicate ),
2723+ }
2724+ }
26882725 output , err := xml .MarshalIndent (resmsg , " " , " " )
26892726 if err != nil {
26902727 ctx .Logger ().Error ("failed to produce response" , "error" , err , "body" , string (output ))
0 commit comments