Skip to content

Commit

Permalink
Avoiding multiple DB calls for status update
Browse files Browse the repository at this point in the history
[#180196891]
  • Loading branch information
sree-cfa committed Dec 2, 2021
1 parent d09dab7 commit 81a956a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,9 @@ ModelAndView postFormPage(

Application application = applicationFactory.newApplication(applicationData);
applicationRepository.save(application);
applicationRepository.updateStatusToInProgress(application, routingDecisionService);
if (applicationConfiguration.getLandmarkPages().isStartTimerPage(pageName)) {
applicationRepository.updateStatusToInProgress(application, routingDecisionService);
}
return new ModelAndView(String.format("redirect:/pages/%s/navigation", pageName));
} else {
return new ModelAndView("redirect:/pages/" + pageName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void shouldSaveApplicationOnEveryFormSubmission() throws Exception {
when(applicationRepository.getNextId()).thenReturn(applicationId);
when(applicationFactory.newApplication(applicationData)).thenReturn(application);

mockMvc.perform(post("/pages/secondPage")
mockMvc.perform(post("/pages/firstPage")
.param("foo[]", "some value")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE));

Expand All @@ -262,8 +262,32 @@ void shouldSaveApplicationOnEveryFormSubmission() throws Exception {
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE));

verify(applicationRepository, times(2)).save(application);
verify(applicationRepository, times(2)).updateStatusToInProgress(application,
routingDecisionService);
assertThat(applicationData.getId()).isEqualTo(applicationId);
}

@Test
void shouldSaveApplicationStatusOnStartTimerPage() throws Exception {
applicationData.setStartTimeOnce(Instant.now());

String applicationId = "someId";
applicationData.setId(applicationId);
Application application = Application.builder()
.id(applicationId)
.applicationData(applicationData)
.build();
when(applicationRepository.getNextId()).thenReturn(applicationId);
when(applicationFactory.newApplication(applicationData)).thenReturn(application);

mockMvc.perform(post("/pages/firstPage")
.param("foo[]", "some value")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE));

mockMvc.perform(post("/pages/secondPage")
.param("foo[]", "some other value")
.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE));

verify(applicationRepository, times(1))
.updateStatusToInProgress(application, routingDecisionService);
assertThat(applicationData.getId()).isEqualTo(applicationId);
}

Expand Down

0 comments on commit 81a956a

Please sign in to comment.