Skip to content

Commit 693f2c0

Browse files
committed
CP
1 parent 6b7d2e6 commit 693f2c0

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

broker/oapi/open-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ paths:
18491849
content:
18501850
application/json:
18511851
schema:
1852-
$ref: '#/components/schemas/PatronRequest'
1852+
$ref: '#/components/schemas/CreatePatronRequest'
18531853
responses:
18541854
'200':
18551855
description: Patron request updated successfully

broker/patron_request/api/api-handler.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,20 @@ func (a *PatronRequestApiHandler) PutPatronRequestsId(w http.ResponseWriter, r *
550550
if !a.checkOwnership(w, ctx, existingPr.Side, existingPr.RequesterSymbol, existingPr.SupplierSymbol, nil, tenant) {
551551
return
552552
}
553-
existingPr.IllRequest = newPr.IllRequest
553+
newPr.RequesterSymbol = &symbol
554+
creationTime := pgtype.Timestamp{Valid: true, Time: time.Now()}
555+
illRequest, requesterReqId, err := a.parseAndValidateIllRequest(ctx, &newPr, creationTime.Time)
556+
if err != nil {
557+
if errors.Is(err, errInvalidPatronRequest) {
558+
api.AddBadRequestError(ctx, w, err)
559+
return
560+
}
561+
api.AddInternalError(ctx, w, err)
562+
return
563+
}
564+
565+
existingPr.RequesterReqID = getDbText(&requesterReqId)
566+
existingPr.IllRequest = illRequest
554567
existingPr.Patron = getDbText(newPr.Patron)
555568
existingPr.InternalNote = getDbText(newPr.InternalNote)
556569
updatedPr, err := a.prRepo.UpdatePatronRequest(ctx, pr_db.UpdatePatronRequestParams(existingPr))

broker/patron_request/api/api-handler_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,3 +1551,32 @@ func TestPutPatronRequestsIdOK(t *testing.T) {
15511551
assert.NoError(t, err)
15521552
assert.Equal(t, id, response.Id)
15531553
}
1554+
1555+
func TestPutPatronRequestsIdEmptyIllRequest(t *testing.T) {
1556+
handler := NewPrApiHandler(new(PrRepoError), mockEventBus, mockEventRepo, tenant.NewResolver(), nil, 10)
1557+
handler.SetIllRepo(new(illRepoNoTx))
1558+
id := "3"
1559+
body := proapi.CreatePatronRequest{Id: &id, RequesterSymbol: &symbol}
1560+
// IllRequest is zero-valued, which parseAndValidateIllRequest rejects as errInvalidPatronRequest
1561+
jsonBytes, _ := json.Marshal(body)
1562+
req, _ := http.NewRequest("PUT", "/", bytes.NewBuffer(jsonBytes))
1563+
rr := httptest.NewRecorder()
1564+
handler.PutPatronRequestsId(rr, req, "3", proapi.PutPatronRequestsIdParams{})
1565+
assert.Equal(t, http.StatusBadRequest, rr.Code)
1566+
assert.Contains(t, rr.Body.String(), "illRequest must not be empty")
1567+
}
1568+
1569+
func TestPutPatronRequestsIdInvalidBrokerSymbol(t *testing.T) {
1570+
handler := NewPrApiHandler(new(PrRepoError), mockEventBus, mockEventRepo, tenant.NewResolver(), nil, 10)
1571+
handler.SetIllRepo(new(illRepoNoTx))
1572+
previousBrokerSymbol := brokerSymbol
1573+
brokerSymbol = "BROKER"
1574+
defer func() {
1575+
brokerSymbol = previousBrokerSymbol
1576+
}()
1577+
req, _ := http.NewRequest("PUT", "/", putBody(t, "3", validIllRequest()))
1578+
rr := httptest.NewRecorder()
1579+
handler.PutPatronRequestsId(rr, req, "3", proapi.PutPatronRequestsIdParams{})
1580+
assert.Equal(t, http.StatusInternalServerError, rr.Code)
1581+
assert.Contains(t, rr.Body.String(), "invalid BROKER_SYMBOL")
1582+
}

0 commit comments

Comments
 (0)