Skip to content

Commit

Permalink
VKT(Frontend & Backend): Perutun ilmoittautumisen tietojen päivitykse…
Browse files Browse the repository at this point in the history
…n korjaus (#631)

* VKT(Frontend & Backend): Fix enrollment update when using canceled enrollment

* VKT(Frontend & Backend): Fix enrollment to queue when using canceled enrollment [deploy]

* VKT(Backend): test for updating enrollment
  • Loading branch information
jrkkp authored Jan 8, 2024
1 parent b2186fe commit 4a6426d
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 3 deletions.
12 changes: 12 additions & 0 deletions backend/vkt/src/main/java/fi/oph/vkt/api/PublicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public PublicEnrollmentDTO createEnrollment(
return publicEnrollmentService.createEnrollment(dto, reservationId, person);
}

@PostMapping(path = "/enrollment/update")
@ResponseStatus(HttpStatus.CREATED)
public PublicEnrollmentDTO updateEnrollment(
@RequestBody @Valid final PublicEnrollmentCreateDTO dto,
@RequestParam final long examEventId,
final HttpSession session
) {
final Person person = publicPersonService.getPerson(SessionUtil.getPersonId(session));

return publicEnrollmentService.updateEnrollmentForPayment(dto, examEventId, person);
}

@PostMapping(path = "/enrollment/queue")
@ResponseStatus(HttpStatus.CREATED)
public PublicEnrollmentDTO createEnrollmentToQueue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,21 @@ public Enrollment getEnrollmentByExamEventAndPaymentLink(final long examEventId,

return enrollment;
}

@Transactional
public PublicEnrollmentDTO updateEnrollmentForPayment(
final PublicEnrollmentCreateDTO dto,
final long examEventId,
final Person person
) {
final ExamEvent examEvent = examEventRepository.getReferenceById(examEventId);
final Enrollment enrollment = createOrUpdateExistingEnrollment(
dto,
examEvent,
person,
EnrollmentStatus.EXPECTING_PAYMENT_UNFINISHED_ENROLLMENT
);

return createEnrollmentDTO(enrollment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ public void testInitialiseEnrollmentShouldUpdateExpiresAtForExistingReservation(
assertTrue(reservationRepository.findById(dto.reservation().id()).isPresent());
}

@Test
public void testUpdateCanceledEnrollment() {
final ExamEvent examEvent = createExamEvent(2);
final Enrollment enrollment = createEnrollment(examEvent, EnrollmentStatus.EXPECTING_PAYMENT_UNFINISHED_ENROLLMENT);
final Person person = enrollment.getPerson();

publicEnrollmentService.initialiseEnrollment(examEvent.getId(), person);
assertEquals(EnrollmentStatus.CANCELED_UNFINISHED_ENROLLMENT, enrollment.getStatus());

final PublicEnrollmentCreateDTO dto = createDTOBuilder().oralSkill(false).digitalCertificateConsent(false).build();
publicEnrollmentService.updateEnrollmentForPayment(dto, examEvent.getId(), person);

assertEquals(EnrollmentStatus.EXPECTING_PAYMENT_UNFINISHED_ENROLLMENT, enrollment.getStatus());
assertFalse(enrollment.isOralSkill());
}

@Test
public void testInitialiseEnrollmentWithUnfinishedPayment() {
final ExamEvent examEvent = createExamEvent(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useDialog } from 'shared/hooks';

import { useCommonTranslation, usePublicTranslation } from 'configs/i18n';
import { useAppDispatch } from 'configs/redux';
import { EnrollmentStatus } from 'enums/app';
import { PublicEnrollmentFormStep } from 'enums/publicEnrollment';
import {
PublicEnrollment,
Expand All @@ -20,6 +21,7 @@ import {
cancelPublicEnrollment,
cancelPublicEnrollmentAndRemoveReservation,
loadPublicEnrollmentSave,
loadPublicEnrollmentUpdate,
setLoadingPayment,
} from 'redux/reducers/publicEnrollment';
import { RouteUtils } from 'utils/routes';
Expand Down Expand Up @@ -96,7 +98,7 @@ export const PublicEnrollmentControlButtons = ({

useEffect(() => {
if (submitStatus === APIResponseStatus.Success) {
if (reservation) {
if (enrollment.status != EnrollmentStatus.QUEUED) {
// Safari needs time to re-render loading indicator
setTimeout(() => {
window.location.href = RouteUtils.getPaymentCreateApiRoute(
Expand All @@ -116,7 +118,7 @@ export const PublicEnrollmentControlButtons = ({
dispatch,
examEventId,
enrollment.id,
reservation,
enrollment.status,
]);

const handleBackBtnClick = () => {
Expand All @@ -138,13 +140,20 @@ export const PublicEnrollmentControlButtons = ({
if (isStepValid) {
setIsPaymentLoading(true);
setShowValidation(false);
if (isPaymentLinkPreviewView || enrollment.id) {
if (isPaymentLinkPreviewView) {
// Safari needs time to re-render loading indicator
setTimeout(() => {
window.location.href = RouteUtils.getPaymentCreateApiRoute(
enrollment.id
);
}, 200);
} else if (enrollment.id) {
dispatch(
loadPublicEnrollmentUpdate({
enrollment,
examEventId,
})
);
} else {
dispatch(
loadPublicEnrollmentSave({
Expand Down
10 changes: 10 additions & 0 deletions frontend/packages/vkt/src/redux/reducers/publicEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ const publicEnrollmentSlice = createSlice({
},
};
},
loadPublicEnrollmentUpdate(
state,
_action: PayloadAction<{
enrollment: PublicEnrollment;
examEventId: number;
}>
) {
state.enrollmentSubmitStatus = APIResponseStatus.InProgress;
},
loadPublicEnrollmentSave(
state,
_action: PayloadAction<{
Expand Down Expand Up @@ -198,6 +207,7 @@ export const {
resetPublicEnrollment,
updatePublicEnrollment,
loadPublicEnrollmentSave,
loadPublicEnrollmentUpdate,
rejectPublicEnrollmentSave,
storePublicEnrollmentSave,
setPublicEnrollmentExamEventIdIfNotSet,
Expand Down
36 changes: 36 additions & 0 deletions frontend/packages/vkt/src/redux/sagas/publicEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
cancelPublicEnrollmentAndRemoveReservation,
loadEnrollmentInitialisation,
loadPublicEnrollmentSave,
loadPublicEnrollmentUpdate,
loadPublicExamEvent,
rejectEnrollmentInitialisation,
rejectPublicEnrollmentSave,
Expand Down Expand Up @@ -117,6 +118,40 @@ function* cancelPublicEnrollmentAndRemoveReservationSaga(
}
}

function* loadPublicEnrollmentUpdateSaga(
action: PayloadAction<{
enrollment: PublicEnrollment;
examEventId: number;
}>
) {
const { enrollment, examEventId } = action.payload;

try {
const {
emailConfirmation: _unused1,
id: _unused2,
hasPreviousEnrollment: _unused3,
privacyStatementConfirmation: _unused4,
status: _unused5,
examEventId: _unused6,
...body
} = enrollment;

const updateUrl = `${APIEndpoints.PublicEnrollment}/update?examEventId=${examEventId}`;

const response: AxiosResponse<PublicEnrollment> = yield call(
axiosInstance.post,
updateUrl,
body
);
yield put(storePublicEnrollmentSave(response.data));
} catch (error) {
const errorMessage = NotifierUtils.getAPIErrorMessage(error as AxiosError);
yield put(setAPIError(errorMessage));
yield put(rejectPublicEnrollmentSave());
}
}

function* loadPublicEnrollmentSaveSaga(
action: PayloadAction<{
enrollment: PublicEnrollment;
Expand Down Expand Up @@ -166,4 +201,5 @@ export function* watchPublicEnrollments() {
cancelPublicEnrollmentAndRemoveReservationSaga
);
yield takeLatest(loadPublicEnrollmentSave, loadPublicEnrollmentSaveSaga);
yield takeLatest(loadPublicEnrollmentUpdate, loadPublicEnrollmentUpdateSaga);
}

0 comments on commit 4a6426d

Please sign in to comment.