@@ -1413,6 +1413,25 @@ type PrRepoLendingSide struct {
14131413 PrRepoError
14141414}
14151415
1416+ // PrRepoBranchOwner returns a borrowing-side PR for id "3" whose RequesterSymbol
1417+ // is "ISIL:S1" — the branch symbol that MockIllRepositorySuccess returns for any
1418+ // peer, allowing a test to reach the requesterSymbol mismatch check.
1419+ type PrRepoBranchOwner struct {
1420+ PrRepoError
1421+ }
1422+
1423+ func (r * PrRepoBranchOwner ) GetPatronRequestById (ctx common.ExtendedContext , id string ) (pr_db.PatronRequest , error ) {
1424+ if id == "3" {
1425+ return pr_db.PatronRequest {
1426+ ID : id ,
1427+ State : prservice .BorrowerStateNew ,
1428+ Side : prservice .SideBorrowing ,
1429+ RequesterSymbol : pgtype.Text {String : "ISIL:S1" , Valid : true },
1430+ }, nil
1431+ }
1432+ return r .PrRepoError .GetPatronRequestById (ctx , id )
1433+ }
1434+
14161435func (r * PrRepoWrongOwner ) GetPatronRequestById (ctx common.ExtendedContext , id string ) (pr_db.PatronRequest , error ) {
14171436 if id == "3" {
14181437 return pr_db.PatronRequest {
@@ -1466,6 +1485,17 @@ func TestPutPatronRequestsIdInvalidJson(t *testing.T) {
14661485 assert .Equal (t , http .StatusBadRequest , rr .Code )
14671486}
14681487
1488+ func TestPutPatronRequestsIdEmptySymbol (t * testing.T ) {
1489+ handler := NewPrApiHandler (new (PrRepoError ), mockEventBus , mockEventRepo , tenant .NewResolver (), nil , 10 )
1490+ body := proapi.CreatePatronRequest {IllRequest : validIllRequest ()}
1491+ jsonBytes , _ := json .Marshal (body )
1492+ req , _ := http .NewRequest ("PUT" , "/" , bytes .NewBuffer (jsonBytes ))
1493+ rr := httptest .NewRecorder ()
1494+ handler .PutPatronRequestsId (rr , req , "3" , proapi.PutPatronRequestsIdParams {})
1495+ assert .Equal (t , http .StatusBadRequest , rr .Code )
1496+ assert .Contains (t , rr .Body .String (), "symbol must be specified" )
1497+ }
1498+
14691499func TestPutPatronRequestsIdMissingId (t * testing.T ) {
14701500 repo := new (PrRepoUpdateCapture )
14711501 handler := NewPrApiHandler (repo , mockEventBus , mockEventRepo , tenant .NewResolver (), nil , 10 )
@@ -1568,6 +1598,23 @@ func TestPutPatronRequestsIdNotBorrowingSide(t *testing.T) {
15681598 assert .Contains (t , rr .Body .String (), "only borrower-side patron requests can be updated" )
15691599}
15701600
1601+ func TestPutPatronRequestsIdRequesterSymbolMismatch (t * testing.T ) {
1602+ // "ISIL:DIFFERENT" is the body/request symbol; MockIllRepositorySuccess returns
1603+ // "ISIL:S1" as a branch of that symbol, so ownership passes. The existing PR
1604+ // stores "ISIL:S1" directly, which differs from the body symbol → mismatch error.
1605+ tenantResolver := tenant .NewResolver ().WithIllRepo (new (mocks.MockIllRepositorySuccess ))
1606+ handler := NewPrApiHandler (new (PrRepoBranchOwner ), mockEventBus , mockEventRepo , tenantResolver , nil , 10 )
1607+ differentSymbol := "ISIL:DIFFERENT"
1608+ id := "3"
1609+ body := proapi.CreatePatronRequest {Id : & id , RequesterSymbol : & differentSymbol , IllRequest : validIllRequest ()}
1610+ jsonBytes , _ := json .Marshal (body )
1611+ req , _ := http .NewRequest ("PUT" , "/" , bytes .NewBuffer (jsonBytes ))
1612+ rr := httptest .NewRecorder ()
1613+ handler .PutPatronRequestsId (rr , req , "3" , proapi.PutPatronRequestsIdParams {})
1614+ assert .Equal (t , http .StatusBadRequest , rr .Code )
1615+ assert .Contains (t , rr .Body .String (), "requesterSymbol does not match existing patron request" )
1616+ }
1617+
15711618func TestPutPatronRequestsIdPreservesCreatedAt (t * testing.T ) {
15721619 originalCreatedAt := time .Date (2024 , 1 , 15 , 10 , 0 , 0 , 0 , time .UTC )
15731620 repo := & PrRepoUpdateCapturePreset {
0 commit comments