Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDGPATRON-161 #141

Merged
merged 7 commits into from
Dec 27, 2024
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
17 changes: 14 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,12 @@ 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) {
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 +333,17 @@ 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
Loading