Skip to content

Commit

Permalink
Added rule to shouldCreateHistory method to check if a school's isCan…
Browse files Browse the repository at this point in the history
…IssueTranscripts property has changed since the last cache.
  • Loading branch information
cditcher committed Jan 7, 2025
1 parent 1455af9 commit cdb69fa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<School> 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));
}
}

0 comments on commit cdb69fa

Please sign in to comment.