From e0e2d69b42e3f5fd77a5890942eeb2541a9032ce Mon Sep 17 00:00:00 2001 From: Jay Aljelo Ting <65202977+jayasting98@users.noreply.github.com> Date: Thu, 21 Mar 2024 23:06:35 +0800 Subject: [PATCH] Add account request search indexing --- .../webapi/CreateAccountRequestActionIT.java | 60 +++++++++++++++++++ .../ui/webapi/CreateAccountRequestAction.java | 3 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java diff --git a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java new file mode 100644 index 00000000000..70aa4ecc521 --- /dev/null +++ b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java @@ -0,0 +1,60 @@ +package teammates.it.ui.webapi; + +import org.testng.annotations.Test; + +import teammates.common.util.Const; +import teammates.common.util.EmailType; +import teammates.common.util.EmailWrapper; +import teammates.storage.sqlentity.AccountRequest; +import teammates.ui.output.JoinLinkData; +import teammates.ui.request.AccountCreateRequest; +import teammates.ui.webapi.CreateAccountRequestAction; +import teammates.ui.webapi.JsonResult; + +/** + * SUT: {@link CreateAccountRequestAction}. + */ +public class CreateAccountRequestActionIT extends BaseActionIT { + + @Override + String getActionUri() { + return Const.ResourceURIs.ACCOUNT_REQUEST; + } + + @Override + String getRequestMethod() { + return POST; + } + + @Override + @Test + protected void testExecute() throws Exception { + // This is a minimal test; other cases are not tested due to upcoming changes in behaviour. + AccountCreateRequest request = new AccountCreateRequest(); + request.setInstructorEmail("ring-bearer@fellowship.net"); + request.setInstructorName("Frodo Baggins"); + request.setInstructorInstitution("The Fellowship of the Ring"); + CreateAccountRequestAction action = getAction(request); + JsonResult result = getJsonResult(action); + JoinLinkData output = (JoinLinkData) result.getOutput(); + AccountRequest accountRequest = logic.getAccountRequest("ring-bearer@fellowship.net", "The Fellowship of the Ring"); + assertEquals("ring-bearer@fellowship.net", accountRequest.getEmail()); + assertEquals("Frodo Baggins", accountRequest.getName()); + assertEquals("The Fellowship of the Ring", accountRequest.getInstitute()); + assertNull(accountRequest.getRegisteredAt()); + assertEquals(accountRequest.getRegistrationUrl(), output.getJoinLink()); + verifyNumberOfEmailsSent(1); + verifySpecifiedTasksAdded(Const.TaskQueue.SEARCH_INDEXING_QUEUE_NAME, 1); + EmailWrapper emailSent = mockEmailSender.getEmailsSent().get(0); + assertEquals(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), "Frodo Baggins"), + emailSent.getSubject()); + assertEquals("ring-bearer@fellowship.net", emailSent.getRecipient()); + assertTrue(emailSent.getContent().contains(output.getJoinLink())); + } + + @Override + protected void testAccessControl() throws Exception { + // This is not tested due to upcoming changes in behaviour. + } + +} diff --git a/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java b/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java index 0022e2ff26a..27de0e8437b 100644 --- a/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java +++ b/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java @@ -11,7 +11,7 @@ /** * Creates a new account request. */ -class CreateAccountRequestAction extends AdminOnlyAction { +public class CreateAccountRequestAction extends AdminOnlyAction { @Override public JsonResult execute() @@ -26,6 +26,7 @@ public JsonResult execute() try { accountRequest = sqlLogic.createAccountRequest(instructorName, instructorEmail, instructorInstitution); + taskQueuer.scheduleAccountRequestForSearchIndexing(instructorEmail, instructorInstitution); } catch (InvalidParametersException ipe) { throw new InvalidHttpRequestBodyException(ipe); } catch (EntityAlreadyExistsException eaee) {