-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDGPATRON-149 changing emailId from path param to query param and for…
…matting error response
- Loading branch information
1 parent
364129b
commit 72cb196
Showing
10 changed files
with
241 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,14 +273,110 @@ public void testGetAccountPatronNotFound(TestContext context) throws Exception { | |
} | ||
|
||
@Test | ||
public void testGetAccountByEmail(TestContext context) { | ||
logger.info("=== Test request for getting external_patron by email ==="); | ||
public void testGetPatronRegistrationStatusWithoutEmail(TestContext context) { | ||
|
||
RestAssured | ||
.get(String.format("/patron/account/%s/by-email/%s?apikey=%s", extPatronId, "fgh@mail", apiKey)) | ||
var response = RestAssured | ||
.get(String.format("/patron/registration-status?apikey=%s", apiKey)) | ||
.then() | ||
.statusCode(400) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
var jsonResponse = new JsonObject(response.body().asString()); | ||
assertEquals("EMAIL_NOT_PROVIDED", jsonResponse.getString("code")); | ||
assertEquals("emailId is missing in the request", jsonResponse.getString("errorMessage")); | ||
|
||
response = RestAssured | ||
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "", apiKey)) | ||
.then() | ||
.statusCode(400) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
jsonResponse = new JsonObject(response.body().asString()); | ||
assertEquals("EMAIL_NOT_PROVIDED", jsonResponse.getString("code")); | ||
assertEquals("emailId is missing in the request", jsonResponse.getString("errorMessage")); | ||
} | ||
|
||
@Test | ||
public void testGetPatronRegistrationStatusWithActiveEmail(TestContext context) { | ||
|
||
final var response = RestAssured | ||
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "[email protected]", apiKey)) | ||
.then() | ||
.statusCode(200) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
var expected = new JsonObject(readMockFile( | ||
"/user_active.json")); | ||
var actual = new JsonObject(response.body().asString()); | ||
assertEquals(expected, actual); | ||
} | ||
|
||
@Test | ||
public void testGetPatronRegistrationStatusWithInvalidEmail() { | ||
|
||
final var response = RestAssured | ||
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "[email protected]", apiKey)) | ||
.then() | ||
.statusCode(404) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
var jsonResponse = new JsonObject(response.body().asString()); | ||
assertEquals("USER_NOT_FOUND", jsonResponse.getString("code")); | ||
assertEquals("User does not exist", jsonResponse.getString("errorMessage")); | ||
} | ||
|
||
@Test | ||
public void testGetPatronRegistrationStatusWithMultipleUserEmail() { | ||
|
||
final var response = RestAssured | ||
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "[email protected]", apiKey)) | ||
.then() | ||
.statusCode(400) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
var jsonResponse = new JsonObject(response.body().asString()); | ||
assertEquals("MULTIPLE_USER_WITH_EMAIL", jsonResponse.getString("code")); | ||
assertEquals("Multiple users found with the same email", jsonResponse.getString("errorMessage")); | ||
} | ||
|
||
@Test | ||
public void testGetPatronRegistrationStatusWithInvalidScenarios() { | ||
|
||
// when we are getting 404, we converted it to Errors.class. But there are cases where we get text/plain errors. | ||
// In that case, code will return the error as it is. | ||
var response = RestAssured | ||
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "[email protected]", apiKey)) | ||
.then() | ||
.statusCode(404) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
var jsonResponse = new JsonObject(response.body().asString()); | ||
assertEquals("404", jsonResponse.getString("code")); | ||
assertEquals("Resource not found", jsonResponse.getString("errorMessage")); | ||
|
||
response = RestAssured | ||
.get(String.format("/patron/registration-status?emailId=%s&apikey=%s", "[email protected]", apiKey)) | ||
.then() | ||
.statusCode(500) | ||
.header(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.extract() | ||
.response(); | ||
|
||
jsonResponse = new JsonObject(response.body().asString()); | ||
assertEquals("500", jsonResponse.getString("code")); | ||
assertEquals("unable to retrieve user details", jsonResponse.getString("errorMessage")); | ||
} | ||
|
||
@Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import static org.folio.edge.core.Constants.DAY_IN_MILLIS; | ||
import static org.folio.edge.core.Constants.TEXT_PLAIN; | ||
import static org.folio.edge.core.Constants.X_OKAPI_TOKEN; | ||
import static org.folio.edge.patron.Constants.PARAM_EMAIL_ID; | ||
import static org.folio.edge.patron.Constants.PARAM_HOLD_ID; | ||
import static org.folio.edge.patron.Constants.PARAM_INCLUDE_CHARGES; | ||
import static org.folio.edge.patron.Constants.PARAM_INCLUDE_HOLDS; | ||
|
@@ -22,10 +23,13 @@ | |
import java.nio.charset.StandardCharsets; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Currency; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
|
@@ -166,6 +170,9 @@ public Router defineRoutes() { | |
router.route(HttpMethod.GET, "/circulation/requests/:requestId") | ||
.handler(this::getRequestHandler); | ||
|
||
router.route(HttpMethod.GET, "/patron/registration-status/:emailId") | ||
.handler(this::getRegistrationStatusHandler); | ||
|
||
return router; | ||
} | ||
|
||
|
@@ -255,6 +262,42 @@ public void getExtPatronAccountHandler(RoutingContext ctx) { | |
} | ||
} | ||
|
||
public void getRegistrationStatusHandler(RoutingContext ctx) { | ||
String token = ctx.request().getHeader(X_OKAPI_TOKEN); | ||
String emailId = ctx.request().getParam(PARAM_EMAIL_ID); | ||
if (token == null || !token.equals(MOCK_TOKEN)) { | ||
ctx.response() | ||
.setStatusCode(403) | ||
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN) | ||
.end("Access requires permission: patron.account.get"); | ||
} else if(emailId.equals("[email protected]")) { | ||
ctx.response() | ||
.setStatusCode(200) | ||
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.end(readMockFile("/user_active.json")); | ||
} else if(emailId.equals("[email protected]")) { | ||
ctx.response() | ||
.setStatusCode(400) | ||
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.end(readMockFile("/multiple_user_error.json")); | ||
} else if(emailId.equals("[email protected]")) { | ||
ctx.response() | ||
.setStatusCode(404) | ||
.putHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON) | ||
.end(readMockFile("/user_not_found_error.json")); | ||
} else if(emailId.equals("[email protected]")) { | ||
ctx.response() | ||
.setStatusCode(404) | ||
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN) | ||
.end("Resource not found"); | ||
} else { | ||
ctx.response() | ||
.setStatusCode(500) | ||
.putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN) | ||
.end("unable to retrieve user details"); | ||
} | ||
} | ||
|
||
public void putExtPatronAccountHandler(RoutingContext ctx) { | ||
String token = ctx.request().getHeader(X_OKAPI_TOKEN); | ||
if (token == null || !token.equals(MOCK_TOKEN)) { | ||
|
@@ -667,7 +710,6 @@ public static Patron getPatron() { | |
.preferredEmailCommunication(new ArrayList<>()) | ||
.build(); | ||
} | ||
|
||
public static Charge getCharge(String itemId) { | ||
return Charge.builder() | ||
.item(getItem(itemId_overdue)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Multiple users found with the same email", | ||
"code": "MULTIPLE_USER_WITH_EMAIL", | ||
"parameters": [] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"id": "cacc29d8-cade-4312-a5f2-4eeac55d8697", | ||
"externalSystemId": "[email protected]", | ||
"active": true, | ||
"type": "patron", | ||
"patronGroup": "63f8065f-df84-4e76-a36b-3ba32dbdc9e5", | ||
"departments": [], | ||
"proxyFor": [], | ||
"personal": { | ||
"lastName": "active", | ||
"firstName": "folio", | ||
"middleName": "", | ||
"preferredFirstName": "new", | ||
"email": "[email protected]", | ||
"phone": "555-123456", | ||
"mobilePhone": "555-5678", | ||
"addresses": [ | ||
{ | ||
"id": "ec8c23d5-c301-4bba-8ade-39cc409e5d7e", | ||
"countryId": "US", | ||
"addressLine1": "123 Main St", | ||
"addressLine2": "Apt 8", | ||
"city": "Metropolis", | ||
"region": "NY", | ||
"postalCode": "12345", | ||
"addressTypeId": "93d3d88d-499b-45d0-9bc7-ac73c3a19880", | ||
"primaryAddress": true | ||
} | ||
], | ||
"preferredContactTypeId": "002" | ||
}, | ||
"enrollmentDate": "2024-08-29T13:29:39.248+00:00", | ||
"expirationDate": "2026-08-29T00:00:00.000+00:00", | ||
"createdDate": "2024-08-29T13:29:39.256+00:00", | ||
"updatedDate": "2024-08-29T13:29:39.256+00:00", | ||
"metadata": { | ||
"createdDate": "2024-08-29T13:29:39.250+00:00", | ||
"createdByUserId": "21457ab5-4635-4e56-906a-908f05e9233b", | ||
"updatedDate": "2024-08-29T13:29:39.250+00:00", | ||
"updatedByUserId": "21457ab5-4635-4e56-906a-908f05e9233b" | ||
}, | ||
"preferredEmailCommunication": [ | ||
"Support", | ||
"Programs" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "User does not exist", | ||
"code": "USER_NOT_FOUND", | ||
"parameters": [] | ||
} | ||
] | ||
} |