-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into MissingKeysToXXFiles
- Loading branch information
Showing
5 changed files
with
49 additions
and
200 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.util.Arrays; | ||
import java.util.Calendar; | ||
|
@@ -376,84 +375,5 @@ public void testDisable2FA() { | |
profileDao.disable2FA("2000-0000-0000-0002"); | ||
profile = profileDao.find("2000-0000-0000-0002"); | ||
assertFalse(profile.getUsing2FA()); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
@Rollback(true) | ||
public void findEmailsUnverfiedDaysTest() throws IllegalAccessException { | ||
String orcid = "9999-9999-9999-999X"; | ||
ProfileEntity profile = new ProfileEntity(); | ||
profile.setId(orcid); | ||
profile.setClaimed(true); | ||
profileDao.persist(profile); | ||
profileDao.flush(); | ||
emailDao.removeAll(); | ||
|
||
// Created today | ||
assertEquals(1, insertEmailWithDateCreated("[email protected]", "bd22086b65b6259fe79f7844a6b6a369441733b9ef04eff762f3d640957b78f5", orcid, false, new Date())); | ||
|
||
// Created a week ago | ||
assertEquals(1, insertEmailWithDateCreated("[email protected]", "95770578974f683fb05c179a84f57c3fc7d4b260f8079fbc590080e51873bb67", orcid, false, LocalDateTime.now().minusDays(7).toDate())); | ||
|
||
// Created 15 days ago | ||
assertEquals(1, insertEmailWithDateCreated("[email protected]", "3cbebfc1de2500494fc95553c956e757cb1998149d366afb71888cdeb1550719", orcid, false, LocalDateTime.now().minusDays(15).toDate())); | ||
|
||
// Created 7 days ago and verified | ||
assertEquals(1, insertEmailWithDateCreated("[email protected]", "2f4812b9c675e9803a4bb616dd1bc241c8c9302ba5690a1ea9d48049a32e7c5f", orcid, true, LocalDateTime.now().minusDays(7).toDate())); | ||
|
||
// Created 15 days ago and verified | ||
assertEquals(1, insertEmailWithDateCreated("[email protected]", "896dea808bbf69bde1b177f27800e84d17763860bffde1dfd8ef200e79ff9971", orcid, true, LocalDateTime.now().minusDays(15).toDate())); | ||
|
||
List<Triple<String, Boolean, Date>> results = profileDao.findEmailsUnverfiedDays(7, 100); | ||
assertNotNull(results); | ||
assertEquals(2, results.size()); | ||
|
||
boolean found1 = false, found2 = false; | ||
|
||
for(Triple<String, Boolean, Date> element : results) { | ||
assertNotNull(element.getRight()); | ||
if(element.getLeft().equals("[email protected]")) { | ||
found1 = true; | ||
} else if(element.getLeft().equals("[email protected]")) { | ||
found2 = true; | ||
} else { | ||
fail("Unexpected email id: " + element.getRight()); | ||
} | ||
} | ||
|
||
assertTrue(found1); | ||
assertTrue(found2); | ||
|
||
// Put an email event on '[email protected]' and verify there is only one result | ||
emailEventDao.persist(new EmailEventEntity("[email protected]", EmailEventType.VERIFY_EMAIL_7_DAYS_SENT)); | ||
|
||
results = profileDao.findEmailsUnverfiedDays(7, 100); | ||
assertNotNull(results); | ||
assertEquals(1, results.size()); | ||
assertEquals("[email protected]", results.get(0).getLeft()); | ||
|
||
// Put an email event on '[email protected]' and verify there is no result anymore | ||
emailEventDao.persist(new EmailEventEntity("[email protected]", EmailEventType.VERIFY_EMAIL_TOO_OLD)); | ||
results = profileDao.findEmailsUnverfiedDays(7, 100); | ||
assertNotNull(results); | ||
assertTrue(results.isEmpty()); | ||
} | ||
|
||
private int insertEmailWithDateCreated(String email, String emailHash, String orcid, boolean isVerified, Date dateCreated) { | ||
Query q = entityManager.createNativeQuery( | ||
"INSERT INTO email(email,email_hash,orcid,source_id,visibility,is_primary,is_current,is_verified,date_created,last_modified) " | ||
+ "values(:email, :emailHash, :orcid, :sourceId, :visibility, :isPrimary, :isCurrent, :isVerified, :dateCreated, :lastModified)"); | ||
q.setParameter("email", email); | ||
q.setParameter("emailHash", emailHash); | ||
q.setParameter("orcid", orcid); | ||
q.setParameter("sourceId", orcid); | ||
q.setParameter("visibility", "PUBLIC"); | ||
q.setParameter("isPrimary", false); | ||
q.setParameter("isCurrent", false); | ||
q.setParameter("isVerified", isVerified); | ||
q.setParameter("dateCreated", dateCreated); | ||
q.setParameter("lastModified", dateCreated); | ||
return q.executeUpdate(); | ||
} | ||
} | ||
} |
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