Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions broker/events/eventmodels.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ type CommonEventData struct {
EventError *EventError `json:"eventError,omitempty"`
Note string `json:"note,omitempty"`
Action *pr_db.PatronRequestAction `json:"action,omitempty"`
ActionResult *ActionResult `json:"actionResult,omitempty"`
}

type ActionResult struct {
Outcome string `json:"outcome"`
ToState *string `json:"toState,omitempty"`
}

type EventError struct {
Expand Down
15 changes: 13 additions & 2 deletions broker/oapi/open-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,25 @@ components:
ActionResult:
type: object
properties:
actionResult:
result:
type: string
description: Action result
message:
type: string
description: Action message
outcome:
type: string
description: Action outcome ("success", "failure")
fromState:
type: string
description: State before action execution
toState:
type: string
description: State after action execution
required:
- actionResult
- result
- outcome
- fromState

SseResult:
type: object
Expand Down
12 changes: 11 additions & 1 deletion broker/patron_request/api/api-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (a *PatronRequestApiHandler) PostPatronRequestsIdAction(w http.ResponseWrit
addInternalError(ctx, w, err)
return
}
fromState := string(pr.State)
if !actionMapping.IsActionAvailable(*pr, pr_db.PatronRequestAction(action.Action)) {
addBadRequestError(ctx, w, errors.New("Action "+action.Action+" is not allowed for patron request "+id+" in state "+string(pr.State)))
return
Expand Down Expand Up @@ -395,8 +396,17 @@ func (a *PatronRequestApiHandler) PostPatronRequestsIdAction(w http.ResponseWrit
addInternalError(ctx, w, err)
return
}
var message *string
if completedEvent.ResultData.EventError != nil {
message = &completedEvent.ResultData.EventError.Message
}
outcome := completedEvent.ResultData.ActionResult.Outcome
result := proapi.ActionResult{
ActionResult: string(completedEvent.EventStatus),
Result: string(completedEvent.EventStatus),
Message: message,
Outcome: outcome,
FromState: fromState,
ToState: completedEvent.ResultData.ActionResult.ToState,
}
if completedEvent.ResultData.Note != "" {
result.Message = &completedEvent.ResultData.Note
Expand Down
216 changes: 122 additions & 94 deletions broker/patron_request/service/action.go

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions broker/patron_request/service/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestHandleInvokeActionValidateOK(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{ID: fakeEventID, PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &actionValidate}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, BorrowerStateValidated, mockPrRepo.savedPr.State)
}

Expand Down Expand Up @@ -284,7 +284,7 @@ func TestHandleInvokeActionCheckOutOK(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, BorrowerStateCheckedOut, mockPrRepo.savedPr.State)
}

Expand Down Expand Up @@ -334,7 +334,7 @@ func TestHandleInvokeActionCheckInOK(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, BorrowerStateCheckedIn, mockPrRepo.savedPr.State)
}

Expand Down Expand Up @@ -719,7 +719,7 @@ func TestHandleInvokeLenderActionValidate(t *testing.T) {
})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateWillSupply, mockPrRepo.savedPr.State)
assert.Len(t, mockEventBus.createdTaskData, 1)
assert.NotNil(t, mockEventBus.createdTaskData[0].Action)
Expand Down Expand Up @@ -777,7 +777,7 @@ func TestHandleInvokeLenderActionWillSupplyUseIllTitleWhenRequestItemEmptyOK(t *
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateWillSupply, mockPrRepo.savedPr.State)
assert.Len(t, mockPrRepo.savedItems, 1)
assert.Equal(t, "1", mockPrRepo.savedItems[0].Barcode)
Expand All @@ -799,7 +799,7 @@ func TestHandleInvokeLenderActionWillSupplyUseRequestItemTitleWhenAvailableOK(t
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateWillSupply, mockPrRepo.savedPr.State)
assert.Len(t, mockPrRepo.savedItems, 1)
assert.Equal(t, "1", mockPrRepo.savedItems[0].Barcode)
Expand Down Expand Up @@ -831,7 +831,7 @@ func TestHandleInvokeLenderActionRejectCancel(t *testing.T) {
})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateWillSupply, mockPrRepo.savedPr.State)
assert.NotNil(t, mockIso18626Handler.lastSupplyingAgencyMessage)
assert.Equal(t, iso18626.TypeReasonForMessageCancelResponse, mockIso18626Handler.lastSupplyingAgencyMessage.MessageInfo.ReasonForMessage)
Expand Down Expand Up @@ -887,7 +887,7 @@ func TestHandleInvokeLenderActionCannotSupply(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateUnfilled, mockPrRepo.savedPr.State)
}

Expand All @@ -904,7 +904,7 @@ func TestHandleInvokeLenderActionAddCondition(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateConditionPending, mockPrRepo.savedPr.State)
}

Expand Down Expand Up @@ -937,7 +937,7 @@ func TestHandleInvokeLenderActionShipOK(t *testing.T) {

status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})
assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateShipped, mockPrRepo.savedPr.State)
assert.Len(t, mockPrRepo.savedItems, 0)
}
Expand Down Expand Up @@ -972,7 +972,7 @@ func TestHandleInvokeLenderActionShipNewTitleOK(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateShipped, mockPrRepo.savedPr.State)
assert.Len(t, mockPrRepo.savedItems, 2)
assert.Equal(t, "item1", mockPrRepo.savedItems[0].ID)
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func TestHandleInvokeLenderActionMarkReceivedOK(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateCompleted, mockPrRepo.savedPr.State)
}

Expand Down Expand Up @@ -1130,7 +1130,7 @@ func TestHandleInvokeLenderActionAcceptCancel(t *testing.T) {
status, resultData := prAction.handleInvokeAction(appCtx, events.Event{PatronRequestID: patronRequestId, EventData: events.EventData{CommonEventData: events.CommonEventData{Action: &action}}})

assert.Equal(t, events.EventStatusSuccess, status)
assert.Nil(t, resultData)
assert.NotNil(t, resultData)
assert.Equal(t, LenderStateCancelled, mockPrRepo.savedPr.State)
assert.NotNil(t, mockIso18626Handler.lastSupplyingAgencyMessage)
assert.Equal(t, iso18626.TypeReasonForMessageCancelResponse, mockIso18626Handler.lastSupplyingAgencyMessage.MessageInfo.ReasonForMessage)
Expand Down
51 changes: 42 additions & 9 deletions broker/test/patron_request/api/api-handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,14 @@ func TestCrud(t *testing.T) {
actionBytes, err := json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", thisPrPath+"/action"+queryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
var pResult proapi.ActionResult
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Equal(t, "success", pResult.Outcome)
assert.Equal(t, "VALIDATED", pResult.FromState)
assert.Equal(t, "SENT", *pResult.ToState)
assert.Nil(t, pResult.Message)

respBytes = httpRequest(t, "GET", thisPrPath+queryParams, []byte{}, 200)
err = json.Unmarshal(respBytes, &foundPr)
Expand All @@ -254,7 +261,11 @@ func TestCrud(t *testing.T) {
respBytes = httpRequest(t, "POST", thisPrPath+"/action"+queryParams, actionBytes, 200)
// used to succeed, but the illmock currently does not include items as part of the Loaned message, which causes the action to fail.
// We should either update the mock to include items or change the test to not use blocking action.
assert.Equal(t, "{\"actionResult\":\"ERROR\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "ERROR", pResult.Result)
assert.Equal(t, "receiveBorrowingRequest failed to get items by PR ID", *pResult.Message)
assert.Equal(t, "failure", pResult.Outcome)

respBytes = httpRequest(t, "GET", thisPrPath+queryParams, []byte{}, 200)
err = json.Unmarshal(respBytes, &foundPr)
Expand Down Expand Up @@ -340,7 +351,11 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err := json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", requesterPrPath+"/action"+queryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
var pResult proapi.ActionResult
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Find supplier patron request
test.WaitForPredicateToBeTrue(func() bool {
Expand All @@ -366,7 +381,10 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err = json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", supplierPrPath+"/action"+supQueryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Wait for action
test.WaitForPredicateToBeTrue(func() bool {
Expand All @@ -381,7 +399,10 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err = json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", requesterPrPath+"/action"+queryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Wait for action
test.WaitForPredicateToBeTrue(func() bool {
Expand All @@ -396,7 +417,10 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err = json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", requesterPrPath+"/action"+queryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Wait for action
test.WaitForPredicateToBeTrue(func() bool {
Expand All @@ -411,7 +435,10 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err = json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", requesterPrPath+"/action"+queryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Wait for action
test.WaitForPredicateToBeTrue(func() bool {
Expand All @@ -426,7 +453,10 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err = json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", requesterPrPath+"/action"+queryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Wait for action
test.WaitForPredicateToBeTrue(func() bool {
Expand All @@ -441,7 +471,10 @@ func TestActionsToCompleteState(t *testing.T) {
actionBytes, err = json.Marshal(action)
assert.NoError(t, err, "failed to marshal patron request action")
respBytes = httpRequest(t, "POST", supplierPrPath+"/action"+supQueryParams, actionBytes, 200)
assert.Equal(t, "{\"actionResult\":\"SUCCESS\"}\n", string(respBytes))
err = json.Unmarshal(respBytes, &pResult)
assert.NoError(t, err, "failed to unmarshal patron request action result")
assert.Equal(t, "SUCCESS", pResult.Result)
assert.Nil(t, pResult.Message)

// Check requester patron request done
respBytes = httpRequest(t, "GET", requesterPrPath+queryParams, []byte{}, 200)
Expand Down
7 changes: 7 additions & 0 deletions bruno/crosslink/PR Happy flow/Borrowing side check-in.bru
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ body:json {
}
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
7 changes: 7 additions & 0 deletions bruno/crosslink/PR Happy flow/Borrowing side check-out.bru
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ body:json {
}
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
7 changes: 7 additions & 0 deletions bruno/crosslink/PR Happy flow/Borrowing side receive.bru
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ body:json {
}
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ body:json {
}
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ body:json {
}
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ body:json {
}
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
7 changes: 7 additions & 0 deletions bruno/crosslink/PR Happy flow/Lending side ship.bru
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ script:pre-request {
bru.sleep(500)
}

script:post-response {
test("for success", function() {
const pr = res.getBody();
expect(pr.result).to.equal("SUCCESS")
});
}

settings {
encodeUrl: true
timeout: 0
Expand Down
Loading