-
Notifications
You must be signed in to change notification settings - Fork 3
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
AB#4215 Add the repository for confirmation code with a delete function #1849
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/ca/gov/dtsstn/cdcp/api/data/repository/ConfirmationCodeRepository.java
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,12 @@ | ||
package ca.gov.dtsstn.cdcp.api.data.repository; | ||
import java.time.Instant; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import ca.gov.dtsstn.cdcp.api.data.entity.ConfirmationCodeEntity; | ||
|
||
|
||
@Repository | ||
public interface ConfirmationCodeRepository extends JpaRepository<ConfirmationCodeEntity, String> { | ||
|
||
int deleteByExpiryDateLessThan(Instant instant); | ||
} |
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
60 changes: 60 additions & 0 deletions
60
...nd/src/test/java/ca/gov/dtsstn/cdcp/api/data/repository/ConfirmationCodeRepositoryIT.java
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,60 @@ | ||
package ca.gov.dtsstn.cdcp.api.data.repository; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import ca.gov.dtsstn.cdcp.api.config.DataSourceConfig; | ||
import ca.gov.dtsstn.cdcp.api.data.entity.ConfirmationCodeEntity; | ||
import ca.gov.dtsstn.cdcp.api.data.entity.ConfirmationCodeEntityBuilder; | ||
import ca.gov.dtsstn.cdcp.api.data.entity.UserAttributeEntityBuilder; | ||
import ca.gov.dtsstn.cdcp.api.data.entity.UserEntity; | ||
import ca.gov.dtsstn.cdcp.api.data.entity.UserEntityBuilder; | ||
|
||
@DataJpaTest | ||
@ActiveProfiles("test") | ||
@Import({ DataSourceConfig.class }) | ||
@AutoConfigureTestDatabase(replace = Replace.NONE) | ||
public class ConfirmationCodeRepositoryIT { | ||
|
||
@Autowired ConfirmationCodeRepository confirmationCodeRepository; | ||
@Autowired UserRepository userRepository; | ||
|
||
@Test | ||
@DisplayName("Test confirmationCodeRepository.deleteByExpiryDateLessThan(..)") | ||
void testDeleteByExpiryDateLessThan() { | ||
|
||
ConfirmationCodeEntity confirmationCode = new ConfirmationCodeEntityBuilder() | ||
.expiryDate(LocalDate.of(2024, 5, 15).atStartOfDay(ZoneId.systemDefault()).toInstant()) | ||
.code("98765") | ||
.build(); | ||
|
||
Collection<ConfirmationCodeEntity> confirmationCodes = new ArrayList<ConfirmationCodeEntity>(); | ||
confirmationCodes.add(confirmationCode); | ||
|
||
UserEntity newUser = userRepository.save(new UserEntityBuilder() | ||
.userAttributes(List.of(new UserAttributeEntityBuilder() | ||
.name("RAOIDC_USER_ID") | ||
.value("1234-5678-90") | ||
.build())) | ||
.confirmationCodes(confirmationCodes) | ||
.build()); | ||
|
||
assertThat(userRepository.findById(newUser.getId())).isNotEmpty(); | ||
assertThat(userRepository.findById(newUser.getId()).get().getConfirmationCodes()).isNotEmpty(); | ||
int deletedRows = confirmationCodeRepository.deleteByExpiryDateLessThan(Instant.now()); | ||
confirmationCodeRepository.flush(); | ||
assertThat(deletedRows).isEqualTo(1); | ||
assertThat(userRepository.findById(newUser.getId()).get().getConfirmationCodes()).isEmpty(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something that I don't like about this test is that it relies on data that is in the
data-init.sql
file.I know that other tests do the same thing.. I feel that they're also not good tests.
What you should do, instead.. is do a
findById(..)
and verify that the data doesn't exist, then insert usingsave(..)
and do anotherfindById(..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...same idea with the
delete
method