Skip to content

Commit

Permalink
[EDGPATRON-161] - Extend get API for /patron/registration-status with…
Browse files Browse the repository at this point in the history
… {externalSystemId}
  • Loading branch information
gurleenkaurbp committed Dec 27, 2024
1 parent 6805054 commit e86aaa3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
7 changes: 5 additions & 2 deletions ramls/schemas/user_error_400.schema
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
"description": "Error code",
"examples": [
"MULTIPLE_USER_WITH_EMAIL",
"EMAIL_NOT_PROVIDED"
"EMAIL_NOT_PROVIDED",
"INVALID_IDENTIFIERS"
]
},
"errorMessage": {
"type": "string",
"description": "Error code description",
"examples": [
"Multiple users found with the same email",
"emailId is missing in the request"
"emailId is missing in the request",
"Either emailId or externalSystemId must be provided in the request.",
Provide either emailId or externalSystemId, not both.
]
}
},
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/org/folio/edge/patron/PatronHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,13 @@ public void handleGetPatronRegistrationStatus(RoutingContext ctx) {
String emailId = ctx.request().getParam(PARAM_EMAIL_ID);
String externalSystemId = ctx.request().getParam(PARAM_EXTERNAL_SYSTEM_ID);

if (StringUtils.isNullOrEmpty(emailId) && StringUtils.isNullOrEmpty(externalSystemId)) {
logger.warn("handleGetPatronRegistrationStatus:: Missing or empty emailId and externalSystemId");
String validationError = validateIdentifiers(emailId, externalSystemId);
if (validationError != null) {
logger.warn("handleGetPatronRegistrationStatus:: " + validationError);
ctx.response()
.setStatusCode(400)
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.end(getErrorMsg("IDENTIFIERS_NOT_PROVIDED", "Either emailId or externalSystemId must be provided in the request"));
.end(getErrorMsg("INVALID_IDENTIFIERS", validationError));
return;
}

Expand All @@ -333,6 +334,19 @@ public void handleGetPatronRegistrationStatus(RoutingContext ctx) {
});
}

private String validateIdentifiers(String emailId, String externalSystemId) {
if (StringUtils.isNullOrEmpty(emailId) && StringUtils.isNullOrEmpty(externalSystemId)) {
return "Either emailId or externalSystemId must be provided in the request.";
}

if (!StringUtils.isNullOrEmpty(emailId) && !StringUtils.isNullOrEmpty(externalSystemId)) {
return "Provide either emailId or externalSystemId, not both.";
}

return null;
}



@Override
protected void invalidApiKey(RoutingContext ctx, String msg) {
Expand Down
26 changes: 22 additions & 4 deletions src/test/java/org/folio/edge/patron/MainVerticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ public void testGetPatronRegistrationStatusWithoutEmail(TestContext context) {
.response();

var jsonResponse = new JsonObject(response.body().asString());
assertEquals("IDENTIFIERS_NOT_PROVIDED", jsonResponse.getString("code"));
assertEquals("Either emailId or externalSystemId must be provided in the request", jsonResponse.getString("errorMessage"));
assertEquals("INVALID_IDENTIFIERS", jsonResponse.getString("code"));
assertEquals("Either emailId or externalSystemId must be provided in the request.", jsonResponse.getString("errorMessage"));

response = RestAssured
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "", apiKey))
Expand All @@ -405,10 +405,28 @@ public void testGetPatronRegistrationStatusWithoutEmail(TestContext context) {
.response();

jsonResponse = new JsonObject(response.body().asString());
assertEquals("IDENTIFIERS_NOT_PROVIDED", jsonResponse.getString("code"));
assertEquals("Either emailId or externalSystemId must be provided in the request", jsonResponse.getString("errorMessage"));
assertEquals("INVALID_IDENTIFIERS", jsonResponse.getString("code"));
assertEquals("Either emailId or externalSystemId must be provided in the request.", jsonResponse.getString("errorMessage"));
}

@Test
public void testGetPatronRegistrationStatusWithEmailAndESID(TestContext context) {

var response = RestAssured
.get(String.format("/patron/registration-status?emailId=%s&externalSystemId=%s&apikey=%s", "[email protected]", "9eb67301-6f6e-468f-9b1a-6134dc39a670", apiKey))
.then()
.statusCode(400)
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON)
.extract()
.response();

var jsonResponse = new JsonObject(response.body().asString());
assertEquals("INVALID_IDENTIFIERS", jsonResponse.getString("code"));
assertEquals("Provide either emailId or externalSystemId, not both.", jsonResponse.getString("errorMessage"));

}


@Test
public void testGetPatronRegistrationStatusWithActiveEmail(TestContext context) {

Expand Down

0 comments on commit e86aaa3

Please sign in to comment.