From 9f0ca34ccd0f39118ac950adf6d91f18a42ad124 Mon Sep 17 00:00:00 2001 From: Jay Aljelo Ting <65202977+jayasting98@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:16:21 +0800 Subject: [PATCH] Get account requests by ID in storage update method (#12955) --- .../java/teammates/it/storage/sqlapi/AccountRequestsDbIT.java | 3 +-- src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java | 2 +- .../java/teammates/storage/sqlapi/AccountRequestsDbTest.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/it/java/teammates/it/storage/sqlapi/AccountRequestsDbIT.java b/src/it/java/teammates/it/storage/sqlapi/AccountRequestsDbIT.java index e989d6fb3cb..070d577144b 100644 --- a/src/it/java/teammates/it/storage/sqlapi/AccountRequestsDbIT.java +++ b/src/it/java/teammates/it/storage/sqlapi/AccountRequestsDbIT.java @@ -107,8 +107,7 @@ public void testUpdateAccountRequest() throws Exception { accountRequest.setName("new account request name"); accountRequestDb.updateAccountRequest(accountRequest); - AccountRequest actual = accountRequestDb.getAccountRequest( - accountRequest.getEmail(), accountRequest.getInstitute()); + AccountRequest actual = accountRequestDb.getAccountRequest(accountRequest.getId()); verifyEquals(accountRequest, actual); } diff --git a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java index 6d9f7312fe4..f95f93bc7d9 100644 --- a/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java +++ b/src/main/java/teammates/storage/sqlapi/AccountRequestsDb.java @@ -128,7 +128,7 @@ public AccountRequest updateAccountRequest(AccountRequest accountRequest) throw new InvalidParametersException(accountRequest.getInvalidityInfo()); } - if (getAccountRequest(accountRequest.getEmail(), accountRequest.getInstitute()) == null) { + if (getAccountRequest(accountRequest.getId()) == null) { throw new EntityDoesNotExistException( String.format(ERROR_UPDATE_NON_EXISTENT, accountRequest.toString())); } diff --git a/src/test/java/teammates/storage/sqlapi/AccountRequestsDbTest.java b/src/test/java/teammates/storage/sqlapi/AccountRequestsDbTest.java index 31f6cf77873..f9e71d2f1c8 100644 --- a/src/test/java/teammates/storage/sqlapi/AccountRequestsDbTest.java +++ b/src/test/java/teammates/storage/sqlapi/AccountRequestsDbTest.java @@ -106,7 +106,7 @@ public void testUpdateAccountRequest_invalidEmail_throwsInvalidParametersExcepti public void testUpdateAccountRequest_accountRequestDoesNotExist_throwsEntityDoesNotExistException() { AccountRequest accountRequest = new AccountRequest("test@gmail.com", "name", "institute", AccountRequestStatus.PENDING, "comments"); - doReturn(null).when(accountRequestDb).getAccountRequest(anyString(), anyString()); + doReturn(null).when(accountRequestDb).getAccountRequest(accountRequest.getId()); assertThrows(EntityDoesNotExistException.class, () -> accountRequestDb.updateAccountRequest(accountRequest)); @@ -118,7 +118,7 @@ public void testUpdateAccountRequest_accountRequestDoesNotExist_throwsEntityDoes public void testUpdateAccountRequest_success() throws InvalidParametersException, EntityDoesNotExistException { AccountRequest accountRequest = new AccountRequest("test@gmail.com", "name", "institute", AccountRequestStatus.PENDING, "comments"); - doReturn(accountRequest).when(accountRequestDb).getAccountRequest(anyString(), anyString()); + doReturn(accountRequest).when(accountRequestDb).getAccountRequest(accountRequest.getId()); accountRequestDb.updateAccountRequest(accountRequest);