Skip to content

Commit

Permalink
[#11878] Reference account requests by ID in tests (#13017)
Browse files Browse the repository at this point in the history
* Reference by ID in GetCourseJoinStatusActionIT

* Reference by ID in AccountRequestsDbIT

* Reference by ID in AccountRequestsLogicIT

* Reference by ID in CreateAccountActionIT

* Reference by ID in BaseTestCaseWithSqlDatabaseAccess

* Remove now irrelevant reference by email address and institute
  • Loading branch information
jayasting98 authored Apr 14, 2024
1 parent 4682dff commit c6b8642
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public void testResetAccountRequest()
AccountRequestsDb accountRequestsDb = AccountRequestsDb.inst();

toReset.setRegisteredAt(Instant.now());
toReset = accountRequestsDb.getAccountRequest(email, institute);
UUID id = toReset.getId();
toReset = accountRequestsDb.getAccountRequest(id);

assertNotNull(toReset);
assertNotNull(toReset.getRegisteredAt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ public void testCreateReadDeleteAccountRequest() throws Exception {
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments");
accountRequestDb.createAccountRequest(accountRequest);

______TS("Read account request using the given email and institute");
______TS("Read account request using the given ID");

AccountRequest actualAccReqEmalAndInstitute =
accountRequestDb.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute());
AccountRequest actualAccReqEmalAndInstitute = accountRequestDb.getAccountRequest(accountRequest.getId());
verifyEquals(accountRequest, actualAccReqEmalAndInstitute);

______TS("Read account request using the given registration key");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private BaseEntity getEntity(BaseEntity entity) {
return logic.getNotification(((Notification) entity).getId());
} else if (entity instanceof AccountRequest) {
AccountRequest accountRequest = (AccountRequest) entity;
return logic.getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute());
return logic.getAccountRequest(accountRequest.getId());
} else if (entity instanceof Instructor) {
return logic.getInstructor(((Instructor) entity).getId());
} else if (entity instanceof Student) {
Expand Down
5 changes: 2 additions & 3 deletions src/it/java/teammates/it/ui/webapi/CreateAccountActionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void testExecute() throws InvalidParametersException, EntityAlreadyExi

______TS("Normal case with valid timezone");
String timezone = "Asia/Singapore";
AccountRequest accountRequest = logic.getAccountRequest(email, institute);
AccountRequest accountRequest = logic.getAccountRequest(accReq.getId());

String[] params = new String[] {
Const.ParamsNames.REGKEY, accountRequest.getRegistrationKey(),
Expand Down Expand Up @@ -118,10 +118,9 @@ protected void testExecute() throws InvalidParametersException, EntityAlreadyExi

accReq = typicalBundle.accountRequests.get("unregisteredInstructor2");
email = accReq.getEmail();
institute = accReq.getInstitute();
timezone = "InvalidTimezone";

accountRequest = logic.getAccountRequest(email, institute);
accountRequest = logic.getAccountRequest(accReq.getId());

params = new String[] {
Const.ParamsNames.REGKEY, accountRequest.getRegistrationKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import teammates.common.util.Const;
import teammates.common.util.HibernateUtil;
import teammates.storage.sqlentity.AccountRequest;
import teammates.ui.output.JoinStatus;
import teammates.ui.webapi.GetCourseJoinStatusAction;
import teammates.ui.webapi.JsonResult;
Expand Down Expand Up @@ -131,8 +132,8 @@ protected void testExecute() {

______TS("Normal case: account request not used, instructor has not joined course");

String accountRequestNotUsedKey = logic.getAccountRequest("[email protected]",
"TEAMMATES Test Institute 1").getRegistrationKey();
AccountRequest unregisteredInstructor1AccountRequest = typicalBundle.accountRequests.get("unregisteredInstructor1");
String accountRequestNotUsedKey = unregisteredInstructor1AccountRequest.getRegistrationKey();

params = new String[] {
Const.ParamsNames.REGKEY, accountRequestNotUsedKey,
Expand All @@ -148,8 +149,8 @@ protected void testExecute() {

______TS("Normal case: account request already used, instructor has joined course");

String accountRequestUsedKey =
logic.getAccountRequest("[email protected]", "TEAMMATES Test Institute 1").getRegistrationKey();
AccountRequest instructor1AccountRequest = typicalBundle.accountRequests.get("instructor1");
String accountRequestUsedKey = instructor1AccountRequest.getRegistrationKey();

params = new String[] {
Const.ParamsNames.REGKEY, accountRequestUsedKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package teammates.storage.sqlapi;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -50,27 +49,14 @@ public void teardownMethod() {
}

@Test
public void testCreateAccountRequest_accountRequestDoesNotExist_success() throws InvalidParametersException {
public void testCreateAccountRequest_typicalCase_success() throws InvalidParametersException {
AccountRequest accountRequest =
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments");
doReturn(null).when(accountRequestDb).getAccountRequest(anyString(), anyString());

accountRequestDb.createAccountRequest(accountRequest);

mockHibernateUtil.verify(() -> HibernateUtil.persist(accountRequest));
}

@Test
public void testCreateAccountRequest_accountRequestAlreadyExists_createsSuccessfully()
throws InvalidParametersException {
AccountRequest accountRequest =
new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments");
doReturn(new AccountRequest("[email protected]", "name", "institute", AccountRequestStatus.PENDING, "comments"))
.when(accountRequestDb).getAccountRequest(anyString(), anyString());
accountRequestDb.createAccountRequest(accountRequest);
mockHibernateUtil.verify(() -> HibernateUtil.persist(accountRequest));
}

@Test
public void testGetAccountRequest_nonExistentAccountRequest_returnsNull() {
UUID id = UUID.randomUUID();
Expand Down

0 comments on commit c6b8642

Please sign in to comment.