mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-20 14:34:24 +01:00
return empty rating as -1, include message in output for node details
This commit is contained in:
@@ -26,6 +26,6 @@ public record Rating(Optional<Long> rating) {
|
||||
}
|
||||
|
||||
public long getRating() {
|
||||
return rating.orElse(0L);
|
||||
return rating.orElse(-1L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class RatingTest {
|
||||
|
||||
@Test
|
||||
void getRating() {
|
||||
assertThat(Rating.EMPTY.getRating()).isEqualTo(0);
|
||||
assertThat(Rating.EMPTY.getRating()).isEqualTo(-1);
|
||||
assertThat(new Rating(1).getRating()).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,6 @@ public class NodeDetailsDtoFixture {
|
||||
FlowReportDto.createFromModel(FLOW_REPORT),
|
||||
RebalanceReportDto.createFromModel(REBALANCE_REPORT),
|
||||
CHANNEL_WARNINGS.descriptions(),
|
||||
RatingFixtures.RATING.getRating()
|
||||
RatingDto.fromModel(RatingFixtures.RATING)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,8 @@ class NodeControllerIT {
|
||||
.andExpect(jsonPath("$.onlineReport.changes", is(5)))
|
||||
.andExpect(jsonPath("$.onlineReport.daysForChanges", is(7)))
|
||||
.andExpect(jsonPath("$.onlineReport.since", is("2021-12-23T01:02:03Z")))
|
||||
.andExpect(jsonPath("$.rating", is(123)));
|
||||
.andExpect(jsonPath("$.rating.rating", is(123)))
|
||||
.andExpect(jsonPath("$.rating.message", is("")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -172,4 +173,4 @@ class NodeControllerIT {
|
||||
.andExpect(jsonPath("$.earnedMilliSat", is("1234")))
|
||||
.andExpect(jsonPath("$.sourcedMilliSat", is("567")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class RatingControllerIT {
|
||||
void getRatingForPeer_no_rating() throws Exception {
|
||||
when(ratingService.getRatingForPeer(PUBKEY)).thenReturn(Rating.EMPTY);
|
||||
mockMvc.perform(get(PREFIX + "/peer/" + PUBKEY + RATING))
|
||||
.andExpect(content().json("{\"rating\": 0, \"message\": \"Unable to compute rating\"}"));
|
||||
.andExpect(content().json("{\"rating\": -1, \"message\": \"Unable to compute rating\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,6 +64,6 @@ class RatingControllerIT {
|
||||
void getRatingForChannel_empty() throws Exception {
|
||||
when(ratingService.getRatingForChannel(CHANNEL_ID)).thenReturn(Optional.of(Rating.EMPTY));
|
||||
mockMvc.perform(get(PREFIX + "/channel/" + CHANNEL_ID + RATING))
|
||||
.andExpect(content().json("{\"rating\": 0, \"message\": \"Unable to compute rating\"}"));
|
||||
.andExpect(content().json("{\"rating\": -1, \"message\": \"Unable to compute rating\"}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public record NodeDetailsDto(
|
||||
FlowReportDto flowReport,
|
||||
RebalanceReportDto rebalanceReport,
|
||||
Set<String> warnings,
|
||||
long rating
|
||||
RatingDto rating
|
||||
) {
|
||||
public static NodeDetailsDto createFromModel(NodeDetails nodeDetails) {
|
||||
return new NodeDetailsDto(
|
||||
@@ -38,7 +38,7 @@ public record NodeDetailsDto(
|
||||
FlowReportDto.createFromModel(nodeDetails.flowReport()),
|
||||
RebalanceReportDto.createFromModel(nodeDetails.rebalanceReport()),
|
||||
nodeDetails.warnings().descriptions(),
|
||||
nodeDetails.rating().getRating()
|
||||
RatingDto.fromModel(nodeDetails.rating())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@ class NodeDetailsDtoTest {
|
||||
FlowReportDto.createFromModel(FLOW_REPORT),
|
||||
RebalanceReportDto.createFromModel(REBALANCE_REPORT),
|
||||
NODE_WARNINGS.descriptions(),
|
||||
RatingFixtures.RATING.getRating()
|
||||
RatingDto.fromModel(RatingFixtures.RATING)
|
||||
);
|
||||
assertThat(NodeDetailsDto.createFromModel(NODE_DETAILS)).isEqualTo(expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class RatingDtoTest {
|
||||
@Test
|
||||
void fromModel_empty() {
|
||||
assertThat(RatingDto.fromModel(Rating.EMPTY)).isEqualTo(new RatingDto(0, "Unable to compute rating"));
|
||||
assertThat(RatingDto.fromModel(Rating.EMPTY)).isEqualTo(new RatingDto(-1, "Unable to compute rating"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user