Search in sources :

Example 6 with Profile

use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.

the class ProfileControllerTest method testSubmitEthicsTraining_success.

@Test
public void testSubmitEthicsTraining_success() throws Exception {
    createUser();
    Profile profile = profileController.completeEthicsTraining().getBody();
    assertThat(profile.getDataAccessLevel()).isEqualTo(DataAccessLevel.UNREGISTERED);
    assertThat(profile.getBlockscoreIdVerificationStatus()).isEqualTo(BlockscoreIdVerificationStatus.UNVERIFIED);
    assertThat(profile.getDemographicSurveyCompletionTime()).isNull();
    assertThat(profile.getTermsOfServiceCompletionTime()).isNull();
    assertThat(profile.getEthicsTrainingCompletionTime()).isEqualTo(NOW.toEpochMilli());
}
Also used : Profile(org.pmiops.workbench.model.Profile) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 7 with Profile

use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.

the class ProfileControllerTest method testMe_secondCallInitializesProject.

@Test
public void testMe_secondCallInitializesProject() throws Exception {
    createUser();
    when(fireCloudService.isRequesterEnabledInFirecloud()).thenReturn(true);
    Profile profile = profileController.getMe().getBody();
    assertThat(profile.getFreeTierBillingProjectStatus()).isEqualTo(BillingProjectStatus.PENDING);
    // Simulate FC "Ready".
    org.pmiops.workbench.firecloud.model.BillingProjectMembership membership = new org.pmiops.workbench.firecloud.model.BillingProjectMembership();
    membership.setCreationStatus(CreationStatusEnum.READY);
    membership.setProjectName(BILLING_PROJECT_NAME);
    when(fireCloudService.getBillingProjectMemberships()).thenReturn(ImmutableList.of(membership));
    profile = profileController.getMe().getBody();
    assertThat(profile.getFreeTierBillingProjectStatus()).isEqualTo(BillingProjectStatus.READY);
    verify(fireCloudService).grantGoogleRoleToUser(BILLING_PROJECT_NAME, FireCloudService.BIGQUERY_JOB_USER_GOOGLE_ROLE, PRIMARY_EMAIL);
}
Also used : BillingProjectMembership(org.pmiops.workbench.model.BillingProjectMembership) Profile(org.pmiops.workbench.model.Profile) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 8 with Profile

use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.

the class ProfileControllerTest method testMe_successDevProjectConflict.

@Test
public void testMe_successDevProjectConflict() throws Exception {
    createUser();
    when(fireCloudService.isRequesterEnabledInFirecloud()).thenReturn(true);
    Profile profile = profileController.getMe().getBody();
    String projectName = BILLING_PROJECT_PREFIX + PRIMARY_EMAIL.hashCode();
    doThrow(new ApiException(HttpStatus.CONFLICT.value(), "conflict")).when(fireCloudService).createAllOfUsBillingProject(projectName);
    // When a conflict occurs in dev, log the exception but continue.
    assertProfile(profile, PRIMARY_EMAIL, CONTACT_EMAIL, FAMILY_NAME, GIVEN_NAME, DataAccessLevel.UNREGISTERED, TIMESTAMP, projectName, true);
    verify(fireCloudService).registerUser(CONTACT_EMAIL, GIVEN_NAME, FAMILY_NAME);
    verify(fireCloudService).createAllOfUsBillingProject(projectName);
    verify(fireCloudService).addUserToBillingProject(PRIMARY_EMAIL, projectName);
}
Also used : Profile(org.pmiops.workbench.model.Profile) ApiException(org.pmiops.workbench.firecloud.ApiException) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 9 with Profile

use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.

the class ProfileControllerTest method testMe_success.

@Test
public void testMe_success() throws Exception {
    createUser();
    when(fireCloudService.isRequesterEnabledInFirecloud()).thenReturn(true);
    Profile profile = profileController.getMe().getBody();
    assertProfile(profile, PRIMARY_EMAIL, CONTACT_EMAIL, FAMILY_NAME, GIVEN_NAME, DataAccessLevel.UNREGISTERED, TIMESTAMP, BILLING_PROJECT_NAME, true);
    verify(fireCloudService).registerUser(CONTACT_EMAIL, GIVEN_NAME, FAMILY_NAME);
    verify(fireCloudService).createAllOfUsBillingProject(BILLING_PROJECT_NAME);
    verify(fireCloudService).addUserToBillingProject(PRIMARY_EMAIL, BILLING_PROJECT_NAME);
}
Also used : Profile(org.pmiops.workbench.model.Profile) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 10 with Profile

use of org.pmiops.workbench.model.Profile in project workbench by all-of-us.

the class ProfileControllerTest method testMe_secondCallErrorsProject.

@Test
public void testMe_secondCallErrorsProject() throws Exception {
    createUser();
    when(fireCloudService.isRequesterEnabledInFirecloud()).thenReturn(true);
    Profile profile = profileController.getMe().getBody();
    assertThat(profile.getFreeTierBillingProjectStatus()).isEqualTo(BillingProjectStatus.PENDING);
    // Simulate FC "Error".
    org.pmiops.workbench.firecloud.model.BillingProjectMembership membership = new org.pmiops.workbench.firecloud.model.BillingProjectMembership();
    membership.setCreationStatus(CreationStatusEnum.ERROR);
    membership.setProjectName(BILLING_PROJECT_NAME);
    when(fireCloudService.getBillingProjectMemberships()).thenReturn(ImmutableList.of(membership));
    profile = profileController.getMe().getBody();
    assertThat(profile.getFreeTierBillingProjectStatus()).isEqualTo(BillingProjectStatus.ERROR);
    verify(fireCloudService, never()).grantGoogleRoleToUser(any(), any(), any());
}
Also used : BillingProjectMembership(org.pmiops.workbench.model.BillingProjectMembership) Profile(org.pmiops.workbench.model.Profile) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Aggregations

Profile (org.pmiops.workbench.model.Profile)17 Test (org.junit.Test)13 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)13 BillingProjectMembership (org.pmiops.workbench.model.BillingProjectMembership)4 ApiException (org.pmiops.workbench.firecloud.ApiException)3 Address (com.blockscore.models.Address)2 WorkbenchConfig (org.pmiops.workbench.config.WorkbenchConfig)2 FireCloudConfig (org.pmiops.workbench.config.WorkbenchConfig.FireCloudConfig)2 User (org.pmiops.workbench.db.model.User)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 AuthorityRequired (org.pmiops.workbench.annotations.AuthorityRequired)1 ProfileService (org.pmiops.workbench.auth.ProfileService)1 UserAuthentication (org.pmiops.workbench.auth.UserAuthentication)1 WorkbenchEnvironment (org.pmiops.workbench.config.WorkbenchEnvironment)1 UserService (org.pmiops.workbench.db.dao.UserService)1 CreateAccountRequest (org.pmiops.workbench.model.CreateAccountRequest)1 EmailVerificationStatus (org.pmiops.workbench.model.EmailVerificationStatus)1 IdVerificationListResponse (org.pmiops.workbench.model.IdVerificationListResponse)1 IdVerificationRequest (org.pmiops.workbench.model.IdVerificationRequest)1