diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java index 1b4e6fa8..1d85ac95 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java @@ -1,6 +1,7 @@ package ca.bc.gov.educ.api.trax.service; import ca.bc.gov.educ.api.trax.model.dto.institute.School; +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail; import ca.bc.gov.educ.api.trax.service.institute.SchoolService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; @@ -23,6 +24,11 @@ protected SchoolEventBaseService(@Qualifier("instituteSchoolService") SchoolServ */ protected boolean shouldCreateHistory(School school) { // currently only schools that can issue transcripts qualify + SchoolDetail schoolDetail = this.schoolService.getSchoolDetailByIdFromInstituteApi(school.getSchoolId()); + // if the school's ability to issue transcripts has changed, return true + if (schoolDetail.isCanIssueTranscripts() != school.isCanIssueTranscripts()){ + return true; + } return school.isCanIssueTranscripts(); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseServiceTest.java new file mode 100644 index 00000000..431cb26b --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseServiceTest.java @@ -0,0 +1,68 @@ +package ca.bc.gov.educ.api.trax.service; + +import ca.bc.gov.educ.api.trax.model.dto.institute.School; +import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail; +import ca.bc.gov.educ.api.trax.service.institute.SchoolService; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; + +class SchoolEventBaseServiceTest { + + @Mock + private SchoolService schoolService; + private AutoCloseable closeable; + + @InjectMocks + private SchoolEventBaseService schoolEventBaseService = new SchoolCreatedService(schoolService) {}; + + @BeforeEach + public void setUp() { + closeable = openMocks(this); + } + + @AfterEach + public void finish() throws Exception { + closeable.close(); + } + + @Test + void shouldCreateHistory_whenSchoolCanIssueTranscriptsChanged() { + School school = new School(); + school.setSchoolId("123"); + school.setCanIssueTranscripts(false); + SchoolDetail schoolDetail = new SchoolDetail(); + schoolDetail.setCanIssueTranscripts(true); + when(schoolService.getSchoolDetailByIdFromInstituteApi("123")).thenReturn(schoolDetail); + assertTrue(schoolEventBaseService.shouldCreateHistory(school)); + } + + @Test + void shouldCreateHistory_whenSchoolCanIssueTranscriptsIsTrue() { + School school = new School(); + school.setSchoolId("123"); + school.setCanIssueTranscripts(true); + SchoolDetail schoolDetail = new SchoolDetail(); + schoolDetail.setCanIssueTranscripts(true); + when(schoolService.getSchoolDetailByIdFromInstituteApi("123")).thenReturn(schoolDetail); + assertTrue(schoolEventBaseService.shouldCreateHistory(school)); + } + + @Test + void shouldNotCreateHistory_whenSchoolCanIssueTranscriptsIsFalse() { + School school = new School(); + school.setSchoolId("123"); + school.setCanIssueTranscripts(false); + SchoolDetail schoolDetail = new SchoolDetail(); + schoolDetail.setCanIssueTranscripts(false); + when(schoolService.getSchoolDetailByIdFromInstituteApi("123")).thenReturn(schoolDetail); + assertFalse(schoolEventBaseService.shouldCreateHistory(school)); + } +} \ No newline at end of file