diff --git a/src/test/java/org/folio/edge/patron/MainVerticleTest.java b/src/test/java/org/folio/edge/patron/MainVerticleTest.java index 6a7c388..8b8ef84 100644 --- a/src/test/java/org/folio/edge/patron/MainVerticleTest.java +++ b/src/test/java/org/folio/edge/patron/MainVerticleTest.java @@ -17,6 +17,7 @@ import static org.folio.edge.patron.utils.PatronMockOkapi.holdReqTs; import static org.folio.edge.patron.utils.PatronMockOkapi.instanceId_notFound; import static org.folio.edge.patron.utils.PatronMockOkapi.invalidHoldCancellationdHoldId; +import static org.folio.edge.patron.utils.PatronMockOkapi.itemId_notFound; import static org.folio.edge.patron.utils.PatronMockOkapi.limit_param; import static org.folio.edge.patron.utils.PatronMockOkapi.malformedHoldCancellationHoldId; import static org.folio.edge.patron.utils.PatronMockOkapi.nonUUIDHoldCanceledByPatronId; @@ -1158,7 +1159,7 @@ public void testAllowedServicePointsForItemError(TestContext context) throws Exc final Response resp = RestAssured .with() .get(String.format("/patron/account/%s/item/%s/allowed-service-points?apikey=%s", - patronId, instanceId_notFound, apiKey)) + patronId, itemId_notFound, apiKey)) .then() .statusCode(422) .header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) diff --git a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java index f6a660d..fdb19d5 100644 --- a/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java +++ b/src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java @@ -158,7 +158,11 @@ public Router defineRoutes() { router.route(HttpMethod.GET, "/patron/account/:patronId/instance/:instanceId/allowed-service-points") - .handler(this::getAllowedServicePoints); + .handler(this::getAllowedServicePointsForInstance); + + router.route(HttpMethod.GET, + "/patron/account/:patronId/item/:itemId/allowed-service-points") + .handler(this::getAllowedServicePointsForItem); router.route(HttpMethod.POST, "/patron/account/:patronId/hold/:holdId/cancel") .handler(this::cancelHoldHandler); @@ -497,7 +501,7 @@ public void placeInstanceHoldHandler(RoutingContext ctx) { } } - public void getAllowedServicePoints(RoutingContext ctx) { + public void getAllowedServicePointsForInstance(RoutingContext ctx) { String instanceId = ctx.request().getParam(PARAM_INSTANCE_ID); String token = ctx.request().getHeader(X_OKAPI_TOKEN); @@ -519,6 +523,28 @@ public void getAllowedServicePoints(RoutingContext ctx) { } } + public void getAllowedServicePointsForItem(RoutingContext ctx) { + String itemId = ctx.request().getParam(PARAM_ITEM_ID); + String token = ctx.request().getHeader(X_OKAPI_TOKEN); + + if (token == null || !token.equals(MOCK_TOKEN)) { + ctx.response() + .setStatusCode(403) + .putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN) + .end("Access requires permission: patron.instance.hold.post"); + } else if (itemId.equals(itemId_notFound)) { + ctx.response() + .setStatusCode(422) + .putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .end(readMockFile("/allowed_sp_error_mod_patron.json")); + } else { + ctx.response() + .setStatusCode(200) + .putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) + .end(readMockFile("/allowed_sp_mod_patron_expected_response.json")); + } + } + public static String getPatronJson(String extPatronId) { JsonArray users = new JsonArray(); logger.info(extPatronId_notFound);