Skip to content

Commit 882298c

Browse files
authored
[JN-630] add prereg survey - dropped commit (#617)
1 parent 3f43c40 commit 882298c

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

api-admin/src/main/java/bio/terra/pearl/api/admin/service/portal/PortalExtService.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import bio.terra.pearl.core.service.portal.PortalEnvironmentConfigService;
1212
import bio.terra.pearl.core.service.portal.PortalEnvironmentService;
1313
import bio.terra.pearl.core.service.portal.PortalService;
14+
import bio.terra.pearl.core.service.portal.exception.PortalConfigMissing;
15+
import bio.terra.pearl.core.service.portal.exception.PortalEnvironmentMissing;
1416
import java.util.List;
1517
import java.util.UUID;
1618
import org.springframework.beans.BeanUtils;
@@ -61,9 +63,14 @@ public PortalEnvironmentConfig updateConfig(
6163
"You do not have permissions to update portal configurations");
6264
}
6365
authUtilService.authUserToPortal(user, portalShortcode);
64-
PortalEnvironment portalEnv = portalEnvironmentService.findOne(portalShortcode, envName).get();
66+
PortalEnvironment portalEnv =
67+
portalEnvironmentService
68+
.findOne(portalShortcode, envName)
69+
.orElseThrow(PortalEnvironmentMissing::new);
6570
PortalEnvironmentConfig config =
66-
portalEnvironmentConfigService.find(portalEnv.getPortalEnvironmentConfigId()).get();
71+
portalEnvironmentConfigService
72+
.find(portalEnv.getPortalEnvironmentConfigId())
73+
.orElseThrow(PortalConfigMissing::new);
6774
BeanUtils.copyProperties(newConfig, config, "id", "createdAt");
6875
config = portalEnvironmentConfigService.update(config);
6976
return config;
@@ -86,7 +93,10 @@ public PortalEnvironment updateEnvironment(
8693
if (updatedEnv.getPreRegSurveyId() != null) {
8794
authUtilService.authSurveyToPortal(portal, updatedEnv.getPreRegSurveyId());
8895
}
89-
PortalEnvironment portalEnv = portalEnvironmentService.findOne(portalShortcode, envName).get();
96+
PortalEnvironment portalEnv =
97+
portalEnvironmentService
98+
.findOne(portalShortcode, envName)
99+
.orElseThrow(PortalEnvironmentMissing::new);
90100
portalEnv.setSiteContentId(updatedEnv.getSiteContentId());
91101
portalEnv.setPreRegSurveyId(updatedEnv.getPreRegSurveyId());
92102
return portalEnvironmentService.update(portalEnv);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package bio.terra.pearl.core.service.portal.exception;
2+
3+
import java.util.function.Supplier;
4+
5+
/** throw if the invariant that all portals must have a config object is violated */
6+
public class PortalConfigMissing extends RuntimeException {
7+
public static final Supplier<PortalConfigMissing> SUPPLIER = PortalConfigMissing::new;
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package bio.terra.pearl.core.service.portal.exception;
2+
3+
/** throw if the invariant that all portals must have the sandbox/irb/live environments is violated */
4+
public class PortalEnvironmentMissing extends RuntimeException {
5+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { render, screen } from '@testing-library/react'
2+
import React from 'react'
3+
import { mockPortalEnvContext } from 'test-utils/mocking-utils'
4+
import { setupRouterTest } from 'test-utils/router-testing-utils'
5+
import userEvent from '@testing-library/user-event'
6+
import CreatePreRegSurveyModal from './CreatePreRegSurveyModal'
7+
8+
describe('CreatePreRegSurveyModal', () => {
9+
test('disables Create button when survey name and stable ID are blank', () => {
10+
const portalEnvContext = mockPortalEnvContext('sandbox')
11+
const { RoutedComponent } = setupRouterTest(<CreatePreRegSurveyModal
12+
portalEnvContext={portalEnvContext}
13+
onDismiss={jest.fn()}/>)
14+
render(RoutedComponent)
15+
16+
const createButton = screen.getByText('Create')
17+
expect(createButton).toBeDisabled()
18+
})
19+
20+
test('enables Create button when survey name and stable ID are filled out', async () => {
21+
const user = userEvent.setup()
22+
const portalEnvContext = mockPortalEnvContext('sandbox')
23+
const { RoutedComponent } = setupRouterTest(<CreatePreRegSurveyModal
24+
portalEnvContext={portalEnvContext}
25+
onDismiss={jest.fn()}/>)
26+
render(RoutedComponent)
27+
28+
const surveyNameInput = screen.getByLabelText('Survey Name')
29+
const surveyStableIdInput = screen.getByLabelText('Survey Stable ID')
30+
await user.type(surveyNameInput, 'Test Survey')
31+
await user.type(surveyStableIdInput, 'test_survey_id')
32+
33+
const createButton = screen.getByText('Create')
34+
expect(createButton).toBeEnabled()
35+
})
36+
37+
test('should autofill the stable ID as the user fills in the survey name', async () => {
38+
const user = userEvent.setup()
39+
const portalEnvContext = mockPortalEnvContext('sandbox')
40+
const { RoutedComponent } = setupRouterTest(<CreatePreRegSurveyModal
41+
portalEnvContext={portalEnvContext}
42+
onDismiss={jest.fn()}/>)
43+
render(RoutedComponent)
44+
45+
const surveyNameInput = screen.getByLabelText('Survey Name')
46+
const surveyStableIdInput = screen.getByLabelText('Survey Stable ID')
47+
await user.type(surveyNameInput, 'Test Survey')
48+
49+
//Confirm that auto-fill stable ID worked
50+
expect(surveyStableIdInput).toHaveValue('testSurvey')
51+
})
52+
})

0 commit comments

Comments
 (0)