Skip to content

Commit

Permalink
GAP-2462 | implement versioning for section reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorFayleAND committed Mar 12, 2024
1 parent fa28e8a commit 9a8457f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public ResponseEntity<String> updateSectionOrder(final HttpServletRequest reques
final @RequestBody ApplicationSectionOrderPatchDto sectionOrderPatchDto) {
try {
this.applicationFormSectionService.updateSectionOrder(applicationId, sectionOrderPatchDto.getSectionId(),
sectionOrderPatchDto.getIncrement());
sectionOrderPatchDto.getIncrement(), sectionOrderPatchDto.getVersion());
logApplicationUpdatedEvent(request.getSession().getId(), applicationId);
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public class ApplicationSectionOrderPatchDto {

private Integer increment;

private Integer version;

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ public void updateSectionTitle(final Integer applicationId, final String section
this.applicationFormRepository.save(applicationForm);
}

public void updateSectionOrder(final Integer applicationId, final String sectionId, final Integer increment) {
public void updateSectionOrder(final Integer applicationId, final String sectionId, final Integer increment, final Integer version) {
ApplicationFormEntity applicationForm = this.applicationFormRepository.findById(applicationId)
.orElseThrow(() -> new NotFoundException(
"Application with id " + applicationId + " does not exist or insufficient permissions"));

ApplicationFormUtils.verifyApplicationFormVersion(version, applicationForm);

List<ApplicationFormSectionDTO> sections = applicationForm.getDefinition().getSections();
ApplicationFormSectionDTO section = applicationForm.getDefinition().getSectionById(sectionId);
int index = sections.indexOf(section);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class updateSectionOrder {
void updateSectionOrderHappyPathTest() throws Exception {

doNothing().when(ApplicationFormSectionsControllerTest.this.applicationFormSectionService)
.updateSectionOrder(SAMPLE_APPLICATION_ID, "A-random-uuid", 1);
.updateSectionOrder(SAMPLE_APPLICATION_ID, "A-random-uuid", 1, SAMPLE_VERSION);

ApplicationSectionOrderPatchDto applicationSectionOrderPatchDto = ApplicationSectionOrderPatchDto.builder()
.sectionId("test").increment(1).build();
Expand All @@ -375,7 +375,7 @@ void updateSectionOrder_AccessDeniedTest() throws Exception {

doThrow(new AccessDeniedException("Error message"))
.when(ApplicationFormSectionsControllerTest.this.applicationFormSectionService)
.updateSectionOrder(SAMPLE_APPLICATION_ID, "test", 1);
.updateSectionOrder(SAMPLE_APPLICATION_ID, "test", 1, SAMPLE_VERSION);

ApplicationSectionOrderPatchDto applicationSectionOrderPatchDto = ApplicationSectionOrderPatchDto.builder()
.sectionId("test").increment(1).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void updateSectionOrderSuccessful() {
.thenReturn(Optional.of(testApplicationFormEntity));

ApplicationFormSectionServiceTest.this.applicationFormSectionService.updateSectionOrder(applicationId,
sectionId, increment);
sectionId, increment, SAMPLE_VERSION);

Mockito.verify(ApplicationFormSectionServiceTest.this.applicationFormRepository).save(argument.capture());
utilMock.close();
Expand All @@ -402,7 +402,7 @@ void updateSectionOrderOutsideOfRange() {
.thenReturn(Optional.of(testApplicationFormEntity));

assertThatThrownBy(() -> ApplicationFormSectionServiceTest.this.applicationFormSectionService
.updateSectionOrder(applicationId, sectionId, increment))
.updateSectionOrder(applicationId, sectionId, increment, SAMPLE_VERSION))
.isInstanceOf(FieldViolationException.class).hasMessage("Section is already at the bottom");

utilMock.close();
Expand All @@ -417,7 +417,7 @@ void updateSectionOrderUnauthorised() {
final Integer increment = 1;

assertThatThrownBy(() -> ApplicationFormSectionServiceTest.this.applicationFormSectionService
.updateSectionOrder(applicationId, sectionId, increment)).isInstanceOf(NotFoundException.class)
.updateSectionOrder(applicationId, sectionId, increment, SAMPLE_VERSION)).isInstanceOf(NotFoundException.class)
.hasMessage("Application with id " + applicationId
+ " does not exist or insufficient permissions");

Expand Down

0 comments on commit 9a8457f

Please sign in to comment.