X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Fclub%2Fwpia%2Fgigi%2FdbObjects%2FTestUser.java;h=7d7b6dba93692942e61596b6651aa7fb9cefbbd5;hp=b25970b6c8b4815a61ef22ae2706b5043398f8d2;hb=a7dd0d91bd94ec5eb3ff4e066c8e3492659c7174;hpb=e19697179fb3d680062918e011f41e1d89e31778 diff --git a/tests/club/wpia/gigi/dbObjects/TestUser.java b/tests/club/wpia/gigi/dbObjects/TestUser.java index b25970b6..7d7b6dba 100644 --- a/tests/club/wpia/gigi/dbObjects/TestUser.java +++ b/tests/club/wpia/gigi/dbObjects/TestUser.java @@ -2,10 +2,17 @@ package club.wpia.gigi.dbObjects; import static org.junit.Assert.*; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.sql.Date; + +import org.hamcrest.CoreMatchers; import org.junit.Test; import club.wpia.gigi.GigiApiException; +import club.wpia.gigi.dbObjects.CATS.CATSType; import club.wpia.gigi.dbObjects.NamePart.NamePartType; +import club.wpia.gigi.testUtils.ArrayContains; import club.wpia.gigi.testUtils.ClientBusinessTest; public class TestUser extends ClientBusinessTest { @@ -64,4 +71,82 @@ public class TestUser extends ClientBusinessTest { assertEquals("HPH", u0.getInitials()); } + @Test + public void testValidCATS() throws IOException, GeneralSecurityException { + Date min11month = new Date(System.currentTimeMillis() - 24L * 60 * 60 * 11 * 31 * 1000L); + Date min12month = new Date(System.currentTimeMillis() - 24L * 60 * 60 * 12 * 31 * 1000L); + + assertFalse(u.hasValidRAChallenge()); + CATS.enterResult(u, CATSType.AGENT_CHALLENGE, min12month, "en_US", "1"); + assertFalse(u.hasValidRAChallenge()); + CATS.enterResult(u, CATSType.AGENT_CHALLENGE, min11month, "en_US", "1"); + assertTrue(u.hasValidRAChallenge()); + + assertFalse(u.hasValidSupportChallenge()); + CATS.enterResult(u, CATSType.SUPPORT_DP_CHALLENGE_NAME, min12month, "en_US", "1"); + assertFalse(u.hasValidSupportChallenge()); + CATS.enterResult(u, CATSType.SUPPORT_DP_CHALLENGE_NAME, min11month, "en_US", "1"); + assertTrue(u.hasValidSupportChallenge()); + + assertFalse(u.hasValidOrgAdminChallenge()); + CATS.enterResult(u, CATSType.ORG_ADMIN_DP_CHALLENGE_NAME, min12month, "en_US", "1"); + assertFalse(u.hasValidOrgAdminChallenge()); + CATS.enterResult(u, CATSType.ORG_ADMIN_DP_CHALLENGE_NAME, min11month, "en_US", "1"); + assertTrue(u.hasValidOrgAdminChallenge()); + + assertFalse(u.hasValidOrgAgentChallenge()); + CATS.enterResult(u, CATSType.ORG_AGENT_CHALLENGE, min12month, "en_US", "1"); + assertFalse(u.hasValidOrgAgentChallenge()); + CATS.enterResult(u, CATSType.ORG_AGENT_CHALLENGE, min11month, "en_US", "1"); + assertTrue(u.hasValidOrgAgentChallenge()); + + assertFalse(u.hasValidTTPAgentChallenge()); + CATS.enterResult(u, CATSType.TTP_AGENT_CHALLENGE, min12month, "en_US", "1"); + assertFalse(u.hasValidTTPAgentChallenge()); + CATS.enterResult(u, CATSType.TTP_AGENT_CHALLENGE, min11month, "en_US", "1"); + assertTrue(u.hasValidTTPAgentChallenge()); + } + + @Test + public void testHasContract() throws GigiApiException { + assertEquals(false, Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT)); + + Contract c = new Contract(u, Contract.ContractType.RA_AGENT_CONTRACT); + getMailReceiver().receive(u.getEmail()); + assertEquals(true, Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT)); + + c.revokeContract(); + getMailReceiver().receive(u.getEmail()); + assertEquals(false, Contract.hasSignedContract(u, Contract.ContractType.RA_AGENT_CONTRACT)); + } + + @Test + public void testWriteUserLog() throws GigiApiException { + String type = "Log test"; + u.writeUserLog(u, type); + String[] result = u.getAdminLog(); + assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type))); + + String type1 = "Log test1"; + u.writeUserLog(u, type1); + result = u.getAdminLog(); + assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type1))); + assertThat(result, ArrayContains.contains(CoreMatchers.equalTo(type))); + } + + @Test + public void testValidVerification() throws GigiApiException { + User u0 = User.getById(createVerifiedUser("f", "l", createUniqueName() + "@email.com", TEST_PASSWORD)); + assertFalse(u0.isValidNameVerification(u0.getPreferredName().toString())); + + add100Points(u0.getId()); + assertTrue(u0.isValidNameVerification(u0.getPreferredName().toString())); + + setVerificationDateToPast(u0.getPreferredName()); + assertFalse(u0.isValidNameVerification(u0.getPreferredName().toString())); + + add100Points(u0.getId()); + assertTrue(u0.isValidNameVerification(u0.getPreferredName().toString())); + } + }