Skip to content

Commit

Permalink
Merge pull request #52 from jkuznik/Task-42-Day-SMS-Limit
Browse files Browse the repository at this point in the history
Rollback to base setting of RiskAssessment
  • Loading branch information
jkuznik authored Nov 21, 2024
2 parents ceaf1bf + 08b7340 commit 22f340c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Slf4j
class RiskAssessmentService {

public static final double RISK_THRESHOLD = 0.1;
public static final double RISK_THRESHOLD = 0.7;
private final OpenAIClient openAIClient;

boolean assessRisk(DisasterAddDTO disasterAddDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ class DisasterServiceImpl implements DisasterService {
public DisasterDTO createDisaster(DisasterAddDTO disasterAddDTO, String source) {
Disaster disaster = mapper.mapDisasterAddDtoToDisaster(disasterAddDTO);
disaster.setSource(source);
if (riskAssessment.assessRisk(disasterAddDTO)) {
disaster.setStatus(DisasterStatus.ACTIVE);
disasterRepository.save(disaster);
generateAlert(disaster.getId());
} else {
disaster.setStatus(DisasterStatus.FAKE);
disasterRepository.save(disaster);
}
// if (riskAssessment.assessRisk(disasterAddDTO)) {
// disaster.setStatus(DisasterStatus.ACTIVE);
// disasterRepository.save(disaster);
// generateAlert(disaster.getId());
// } else {
// disaster.setStatus(DisasterStatus.FAKE);
// disasterRepository.save(disaster);
// }

disaster.setStatus(DisasterStatus.ACTIVE);
disasterRepository.save(disaster);
generateAlert(disaster.getId());

return mapper.mapDisasterToDisasterDto(disaster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,51 +33,51 @@ class RiskAssessmentServiceTest {

private final List<String> citiesInPoland = CitiesInPoland.getList();

// @Test
// void shouldReturnTrueWhenRiskScoreAboveThreshold() {
// // given
// DisasterAddDTO disasterAddDTO = new DisasterAddDTO(
// DisasterType.FLOOD,
// FLOOD_DESCRIPTION,
// citiesInPoland.get(1),
// UUID.randomUUID());
//
// // when
// when(openAIClient.getRiskScore(Mockito.anyString())).thenReturn(PROBABILITY_OF_RISK_HIGH);
//
// // then
// assertTrue(riskAssessmentService.assessRisk(disasterAddDTO));
// }
//
// @Test
// void shouldReturnFalseWhenRiskScoreBelowThreshold() {
// // given
// DisasterAddDTO disasterAddDTO = new DisasterAddDTO(
// DisasterType.FIRE,
// FIRE_DESCRIPTION,
// citiesInPoland.get(1),
// UUID.randomUUID());
//
// // when
// when(openAIClient.getRiskScore(Mockito.anyString())).thenReturn(PROBABILITY_OF_RISK_LOW);
//
// // then
// assertFalse(riskAssessmentService.assessRisk(disasterAddDTO));
// }
//
// @Test
// void shouldReturnFalseWhenOpenAIClientThrowsException() {
// // given
// DisasterAddDTO disasterAddDTO = new DisasterAddDTO(
// DisasterType.FIRE,
// FIRE_DESCRIPTION,
// citiesInPoland.get(1),
// UUID.randomUUID());
//
// // when
// when(openAIClient.getRiskScore(Mockito.anyString())).thenThrow(new RuntimeException("Connection error"));
//
// //then
// assertFalse(riskAssessmentService.assessRisk(disasterAddDTO));
// }
@Test
void shouldReturnTrueWhenRiskScoreAboveThreshold() {
// given
DisasterAddDTO disasterAddDTO = new DisasterAddDTO(
DisasterType.FLOOD,
FLOOD_DESCRIPTION,
citiesInPoland.get(1),
UUID.randomUUID());

// when
when(openAIClient.getRiskScore(Mockito.anyString())).thenReturn(PROBABILITY_OF_RISK_HIGH);

// then
assertTrue(riskAssessmentService.assessRisk(disasterAddDTO));
}

@Test
void shouldReturnFalseWhenRiskScoreBelowThreshold() {
// given
DisasterAddDTO disasterAddDTO = new DisasterAddDTO(
DisasterType.FIRE,
FIRE_DESCRIPTION,
citiesInPoland.get(1),
UUID.randomUUID());

// when
when(openAIClient.getRiskScore(Mockito.anyString())).thenReturn(PROBABILITY_OF_RISK_LOW);

// then
assertFalse(riskAssessmentService.assessRisk(disasterAddDTO));
}

@Test
void shouldReturnFalseWhenOpenAIClientThrowsException() {
// given
DisasterAddDTO disasterAddDTO = new DisasterAddDTO(
DisasterType.FIRE,
FIRE_DESCRIPTION,
citiesInPoland.get(1),
UUID.randomUUID());

// when
when(openAIClient.getRiskScore(Mockito.anyString())).thenThrow(new RuntimeException("Connection error"));

//then
assertFalse(riskAssessmentService.assessRisk(disasterAddDTO));
}
}

0 comments on commit 22f340c

Please sign in to comment.