Skip to content

Commit

Permalink
Change naming of props and add studentID to save
Browse files Browse the repository at this point in the history
  • Loading branch information
eckermania committed Dec 13, 2024
1 parent 14d116d commit f4e3a7e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ private AssessmentStudent processStudent(AssessmentStudentEntity assessmentStude
if (validationIssues.isEmpty()) {
if (currentAssessmentStudentEntity != null) {
BeanUtils.copyProperties(assessmentStudentEntity, currentAssessmentStudentEntity, "districtID", "schoolID", "studentID", "givenName", "surName", "pen", "localID", "isElectronicExam", "courseStatusCode", "assessmentStudentStatusCode", "createUser", "createDate");

if (assessmentStudentEntity.getStudentID() == null){
assessmentStudentEntity.setStudentID(UUID.fromString(studentApiStudent.getStudentID()));
}

TransformUtil.uppercaseFields(currentAssessmentStudentEntity);
return mapper.toStructure(createAssessmentStudentWithHistory(currentAssessmentStudentEntity));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.bc.gov.educ.eas.api.model.v1.AssessmentEntity;
import ca.bc.gov.educ.eas.api.repository.v1.AssessmentRepository;
import ca.bc.gov.educ.eas.api.struct.v1.AssessmentStudent;
import ca.bc.gov.educ.eas.api.util.PenUtil;
import ca.bc.gov.educ.eas.api.util.ValidationUtil;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -33,6 +34,10 @@ public class AssessmentStudentValidator {
public List<FieldError> validatePayload(AssessmentStudent assessmentStudent, boolean isCreateOperation) {
final List<FieldError> apiValidationErrors = new ArrayList<>();

if (StringUtils.isNotEmpty(assessmentStudent.getPen()) && !PenUtil.validCheckDigit(assessmentStudent.getPen())) {
apiValidationErrors.add(ValidationUtil.createFieldError(ASSESSMENT_STUDENT, "pen", assessmentStudent.getPen(), "Invalid Student Pen."));
}

Optional<AssessmentEntity> assessmentEntity = assessmentRepository.findById(UUID.fromString(assessmentStudent.getAssessmentID()));
if (assessmentEntity.isEmpty()) {
apiValidationErrors.add(ValidationUtil.createFieldError(ASSESSMENT_STUDENT, "assessmentID", assessmentStudent.getAssessmentID(), "Invalid assessment session."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ void testUpdateStudent_GivenNullID_ShouldReturn400() throws Exception {
.andExpect(jsonPath("$.subErrors[?(@.field == 'assessmentStudentID')]").exists());
}

@Test
void testUpdateStudent_GivenInvalidPEN_ShouldReturn400() throws Exception {
final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_EAS_STUDENT";
final SecurityMockMvcRequestPostProcessors.OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority);

AssessmentStudent student = createMockStudent();
student.setPen("123456789");

this.mockMvc.perform(
put(URL.BASE_URL_STUDENT + "/" + student.getAssessmentStudentID())
.contentType(APPLICATION_JSON)
.content(asJsonString(student))
.with(mockAuthority))
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect(MockMvcResultMatchers.jsonPath("$.subErrors[0].field").value("pen"));
}

@Test
void testUpdateStudent_GivenValidPayload_ShouldReturnStudent() throws Exception {
final GrantedAuthority grantedAuthority = () -> "SCOPE_WRITE_EAS_STUDENT";
Expand Down

0 comments on commit f4e3a7e

Please sign in to comment.