Skip to content

Commit

Permalink
date_trunc function is not available in the in memory db, so, we cann…
Browse files Browse the repository at this point in the history
…ot run that query there
  • Loading branch information
amontenegro committed Nov 16, 2023
1 parent 28879e7 commit 5ba8f2a
Showing 1 changed file with 1 addition and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,74 +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 2 days ago
assertEquals(1, insertEmailWithDateCreated("[email protected]", "95770578974f683fb05c179a84f57c3fc7d4b260f8079fbc590080e51873bb67", orcid, false, LocalDateTime.now().minusDays(2).toDate()));

// Created 7 days ago
assertEquals(1, insertEmailWithDateCreated("[email protected]", "3cbebfc1de2500494fc95553c956e757cb1998149d366afb71888cdeb1550719", orcid, false, LocalDateTime.now().minusDays(7).toDate()));

// Created 15 days ago
assertEquals(1, insertEmailWithDateCreated("[email protected]", "8fccc2e14b546b968033dee2efb1644623a31a7878b55ae8ad52951961ca3719", orcid, false, LocalDateTime.now().minusDays(15).toDate()));

// Created 2 days ago and verified
assertEquals(1, insertEmailWithDateCreated("[email protected]", "2f4812b9c675e9803a4bb616dd1bc241c8c9302ba5690a1ea9d48049a32e7c5f", orcid, true, LocalDateTime.now().minusDays(2).toDate()));

// Created 7 days ago and verified
assertEquals(1, insertEmailWithDateCreated("[email protected]", "896dea808bbf69bde1b177f27800e84d17763860bffde1dfd8ef200e79ff9971", orcid, true, LocalDateTime.now().minusDays(7).toDate()));

// Created 15 days ago and verified
assertEquals(1, insertEmailWithDateCreated("[email protected]", "f98cce12446df199b852583ce677ecf9870ebe1b58df21bc4e7b01dea67daf01", orcid, true, LocalDateTime.now().minusDays(28).toDate()));

List<Triple<String, String, Boolean>> results = profileDao.findEmailsUnverfiedDays(2, EmailEventType.VERIFY_EMAIL_2_DAYS_SENT);
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(orcid, results.get(0).getLeft());
assertEquals("[email protected]", results.get(0).getMiddle());

results = profileDao.findEmailsUnverfiedDays(7, EmailEventType.VERIFY_EMAIL_7_DAYS_SENT);
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(orcid, results.get(0).getLeft());
assertEquals("[email protected]", results.get(0).getMiddle());

results = profileDao.findEmailsUnverfiedDays(28, EmailEventType.VERIFY_EMAIL_28_DAYS_SENT);
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(orcid, results.get(0).getLeft());
assertEquals("[email protected]", results.get(0).getMiddle());
}

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();
}
}
}

0 comments on commit 5ba8f2a

Please sign in to comment.