Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vijay-eis committed Oct 14, 2024
1 parent dba3633 commit 3c83844
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 28 additions & 2 deletions src/test/java/org/folio/edge/patron/utils/PatronMockOkapi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down

0 comments on commit 3c83844

Please sign in to comment.