Skip to content

Commit

Permalink
refactor: systemCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
redcarrot1 committed Sep 4, 2024
1 parent d4e7195 commit c649ce2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SystemCheckService {
private final AppVersionRepository appVersionRepository;
private final SystemCheckRepository systemCheckRepository;

@Transactional(readOnly = true)
public boolean isSystemAvailable() {
Optional<SystemCheck> optionalSystemCheck = systemCheckRepository.findTopByOrderByUpdatedAtDesc();
return optionalSystemCheck.map(SystemCheck::isAvailable)
Expand All @@ -33,10 +34,11 @@ public void changeSystemAvailable(boolean available) {
systemCheckRepository.save(systemCheck);
}

@Transactional(readOnly = true)
public HealthCheckDto healthCheck() {
boolean systemAvailable = isSystemAvailable();
List<AppVersion> supportAppVersionList = appVersionRepository.findAll();

List<AppVersion> supportAppVersionList = appVersionRepository.findAll();
List<OSAndVersion> list = supportAppVersionList.stream()
.map(appVersion -> new OSAndVersion(appVersion.getOs(), appVersion.getVersion()))
.distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ public SystemCheck(boolean available) {
this.available = available;
}

public void updateAvailable(boolean available) {
this.available = available;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

import java.util.List;

public record HealthCheckDto(boolean systemAvailable,
List<OSAndVersion> supportAppVersionList) {
public record HealthCheckDto(boolean systemAvailable, List<OSAndVersion> supportAppVersionList) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,26 @@ void success_1() {
// given
when(systemCheckRepository.findTopByOrderByUpdatedAtDesc())
.thenReturn(Optional.of(new SystemCheck(true)));

List<AppVersion> supportedAppVersion = List.of(
new AppVersion(OperationSystem.ANDROID, "1.0.0"),
new AppVersion(OperationSystem.ANDROID, "1.0.1"),
new AppVersion(OperationSystem.IOS, "1.0.3")
);
when(appVersionRepository.findAll())
.thenReturn(
List.of(
new AppVersion(OperationSystem.ANDROID, "1.0.0"),
new AppVersion(OperationSystem.ANDROID, "1.0.1"),
new AppVersion(OperationSystem.IOS, "1.0.3")
)
);
.thenReturn(supportedAppVersion);

// when
HealthCheckDto healthCheckDto = systemCheckService.healthCheck();

// then
assertThat(healthCheckDto.systemAvailable()).isTrue();
assertThat(healthCheckDto.supportAppVersionList())
.containsExactlyInAnyOrder(
new OSAndVersion(OperationSystem.ANDROID, "1.0.0"),
new OSAndVersion(OperationSystem.ANDROID, "1.0.1"),
new OSAndVersion(OperationSystem.IOS, "1.0.3")
);

List<OSAndVersion> expected = supportedAppVersion.stream()
.map(appVersion -> new OSAndVersion(appVersion.getOs(), appVersion.getVersion()))
.toList();
assertThat(healthCheckDto.supportAppVersionList()).hasSize(3)
.containsExactlyInAnyOrderElementsOf(expected);
}
}

Expand Down

0 comments on commit c649ce2

Please sign in to comment.