Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-tco committed Oct 9, 2023
1 parent 585b60f commit acae69c
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,53 @@ void removeAttachment_RemovesFileFromS3_AndDeletesDatabaseEntry() {
verify(submissionService).handleSectionReview(APPLICANT_USER_ID, SUBMISSION_ID, SECTION_ID_1, Boolean.FALSE);
}

@Test
void postAttachment_SavesTheDocumentCleansFilenameAndCreatesADatabaseEntry() {

final String questionId = UUID.randomUUID().toString();

final SubmissionQuestionValidation validation = SubmissionQuestionValidation.builder()
.mandatory(true)
.allowedTypes(new String[] {"txt"})
.build();

final SubmissionQuestion question = SubmissionQuestion.builder()
.questionId(questionId)
.validation(validation)
.build();

section2.setQuestions(List.of(question));

final MultipartFile file = new MockMultipartFile(
"file",
"<>/?|hello.txt",
MediaType.TEXT_PLAIN_VALUE,
"Hello, World!".getBytes()
);

final GetNavigationParamsDto expectedNavigation = GetNavigationParamsDto.builder().build();

when(grantApplicantService.getApplicantFromPrincipal())
.thenReturn(grantApplicant);

when(submissionService.getSubmissionFromDatabaseBySubmissionId(APPLICANT_USER_ID, SUBMISSION_ID))
.thenReturn(submission);

when(submissionService.getNextNavigation(APPLICANT_USER_ID, SUBMISSION_ID, SECTION_ID_2, questionId, false))
.thenReturn(expectedNavigation);

final ArgumentCaptor<GrantAttachment> attachmentCaptor = ArgumentCaptor.forClass(GrantAttachment.class);

final ResponseEntity<GetNavigationParamsDto> methodResponse = controllerUnderTest.postAttachment(SUBMISSION_ID, SECTION_ID_2, questionId, file);

verify(attachmentService).attachmentFile(application.getId() + "/" + SUBMISSION_ID + "/" + questionId + "/" + file.getOriginalFilename().replaceAll("[<>\"\\\\/|?*\\\\]", "_"), file);
verify(grantAttachmentService).createAttachment(attachmentCaptor.capture());
verify(submissionService).saveSubmission(submission);

assertThat(methodResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(methodResponse.getBody()).isEqualTo(expectedNavigation);
}

@Test
void getNextNavigationForQuestion_ReturnsExpectedResult() {

Expand Down

0 comments on commit acae69c

Please sign in to comment.