Skip to content

Commit

Permalink
[JN-630] add prereg survey - dropped commit (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
devonbush authored Nov 3, 2023
1 parent 3f43c40 commit 882298c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import bio.terra.pearl.core.service.portal.PortalEnvironmentConfigService;
import bio.terra.pearl.core.service.portal.PortalEnvironmentService;
import bio.terra.pearl.core.service.portal.PortalService;
import bio.terra.pearl.core.service.portal.exception.PortalConfigMissing;
import bio.terra.pearl.core.service.portal.exception.PortalEnvironmentMissing;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.BeanUtils;
Expand Down Expand Up @@ -61,9 +63,14 @@ public PortalEnvironmentConfig updateConfig(
"You do not have permissions to update portal configurations");
}
authUtilService.authUserToPortal(user, portalShortcode);
PortalEnvironment portalEnv = portalEnvironmentService.findOne(portalShortcode, envName).get();
PortalEnvironment portalEnv =
portalEnvironmentService
.findOne(portalShortcode, envName)
.orElseThrow(PortalEnvironmentMissing::new);
PortalEnvironmentConfig config =
portalEnvironmentConfigService.find(portalEnv.getPortalEnvironmentConfigId()).get();
portalEnvironmentConfigService
.find(portalEnv.getPortalEnvironmentConfigId())
.orElseThrow(PortalConfigMissing::new);
BeanUtils.copyProperties(newConfig, config, "id", "createdAt");
config = portalEnvironmentConfigService.update(config);
return config;
Expand All @@ -86,7 +93,10 @@ public PortalEnvironment updateEnvironment(
if (updatedEnv.getPreRegSurveyId() != null) {
authUtilService.authSurveyToPortal(portal, updatedEnv.getPreRegSurveyId());
}
PortalEnvironment portalEnv = portalEnvironmentService.findOne(portalShortcode, envName).get();
PortalEnvironment portalEnv =
portalEnvironmentService
.findOne(portalShortcode, envName)
.orElseThrow(PortalEnvironmentMissing::new);
portalEnv.setSiteContentId(updatedEnv.getSiteContentId());
portalEnv.setPreRegSurveyId(updatedEnv.getPreRegSurveyId());
return portalEnvironmentService.update(portalEnv);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package bio.terra.pearl.core.service.portal.exception;

import java.util.function.Supplier;

/** throw if the invariant that all portals must have a config object is violated */
public class PortalConfigMissing extends RuntimeException {
public static final Supplier<PortalConfigMissing> SUPPLIER = PortalConfigMissing::new;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package bio.terra.pearl.core.service.portal.exception;

/** throw if the invariant that all portals must have the sandbox/irb/live environments is violated */
public class PortalEnvironmentMissing extends RuntimeException {
}
52 changes: 52 additions & 0 deletions ui-admin/src/portal/CreatePreRegSurveyModal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { render, screen } from '@testing-library/react'
import React from 'react'
import { mockPortalEnvContext } from 'test-utils/mocking-utils'
import { setupRouterTest } from 'test-utils/router-testing-utils'
import userEvent from '@testing-library/user-event'
import CreatePreRegSurveyModal from './CreatePreRegSurveyModal'

describe('CreatePreRegSurveyModal', () => {
test('disables Create button when survey name and stable ID are blank', () => {
const portalEnvContext = mockPortalEnvContext('sandbox')
const { RoutedComponent } = setupRouterTest(<CreatePreRegSurveyModal
portalEnvContext={portalEnvContext}
onDismiss={jest.fn()}/>)
render(RoutedComponent)

const createButton = screen.getByText('Create')
expect(createButton).toBeDisabled()
})

test('enables Create button when survey name and stable ID are filled out', async () => {
const user = userEvent.setup()
const portalEnvContext = mockPortalEnvContext('sandbox')
const { RoutedComponent } = setupRouterTest(<CreatePreRegSurveyModal
portalEnvContext={portalEnvContext}
onDismiss={jest.fn()}/>)
render(RoutedComponent)

const surveyNameInput = screen.getByLabelText('Survey Name')
const surveyStableIdInput = screen.getByLabelText('Survey Stable ID')
await user.type(surveyNameInput, 'Test Survey')
await user.type(surveyStableIdInput, 'test_survey_id')

const createButton = screen.getByText('Create')
expect(createButton).toBeEnabled()
})

test('should autofill the stable ID as the user fills in the survey name', async () => {
const user = userEvent.setup()
const portalEnvContext = mockPortalEnvContext('sandbox')
const { RoutedComponent } = setupRouterTest(<CreatePreRegSurveyModal
portalEnvContext={portalEnvContext}
onDismiss={jest.fn()}/>)
render(RoutedComponent)

const surveyNameInput = screen.getByLabelText('Survey Name')
const surveyStableIdInput = screen.getByLabelText('Survey Stable ID')
await user.type(surveyNameInput, 'Test Survey')

//Confirm that auto-fill stable ID worked
expect(surveyStableIdInput).toHaveValue('testSurvey')
})
})

0 comments on commit 882298c

Please sign in to comment.