-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the repository for confirmation code with a delete function
- Loading branch information
1 parent
e725f20
commit 0af8233
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
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> { | ||
|
||
void deleteByExpiryDateLessThan(Instant currentInstant); | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
...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,39 @@ | ||
package ca.gov.dtsstn.cdcp.api.data.repository; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import java.time.Instant; | ||
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; | ||
|
||
|
||
@DataJpaTest | ||
@ActiveProfiles("test") | ||
@Import({ DataSourceConfig.class }) | ||
@AutoConfigureTestDatabase(replace = Replace.NONE) | ||
public class ConfirmationCodeRepositoryIT { | ||
|
||
@Autowired ConfirmationCodeRepository confirmationCodeRepository; | ||
|
||
@Test | ||
@DisplayName("Test confirmationCodeRepository.findBy(..)") | ||
void testFindById() { | ||
assertThat(confirmationCodeRepository.findAll()).isNotEmpty(); | ||
assertThat(confirmationCodeRepository.findById("a6ea4925-f813-493e-80ec-a5b90ca28b6c")).isNotEmpty(); | ||
assertThat(confirmationCodeRepository.findById("bogusId")).isEmpty(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test confirmationCodeRepository.deleteByExpiredCode(..)") | ||
void testDeleteByExpiredCode() { | ||
|
||
assertThat(confirmationCodeRepository.findById("a6ea4925-f813-493e-80ec-a5b90ca28aaa")).isNotEmpty(); | ||
confirmationCodeRepository.deleteByExpiryDateLessThan(Instant.now()); | ||
assertThat(confirmationCodeRepository.findById("a6ea4925-f813-493e-80ec-a5b90ca28aaa")).isEmpty(); | ||
} | ||
} |