diff --git a/application/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerIT.java b/application/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerIT.java index bf86bdb1..501d9cb6 100644 --- a/application/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerIT.java +++ b/application/src/integrationTest/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerIT.java @@ -2,6 +2,7 @@ package de.cotto.lndmanagej.controller; import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.service.ChannelService; +import de.cotto.lndmanagej.service.NodeService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; @@ -12,9 +13,12 @@ import java.util.Optional; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL; +import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2; +import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; +import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @WebMvcTest(controllers = ChannelDetailsController.class) @@ -27,6 +31,9 @@ class ChannelDetailsControllerIT { @MockBean private ChannelService channelService; + @MockBean + private NodeService nodeService; + @MockBean @SuppressWarnings("unused") private Metrics metrics; @@ -38,9 +45,12 @@ class ChannelDetailsControllerIT { } @Test - void details() throws Exception { + void getChannelDetails() throws Exception { + when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2); when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL)); mockMvc.perform(get(CHANNEL_PREFIX + "/details")) - .andExpect(content().json("{\"channelId\":\"" + CHANNEL_ID.getShortChannelId() + "\"}")); + .andExpect(jsonPath("$.channelId", is(String.valueOf(CHANNEL_ID.getShortChannelId())))) + .andExpect(jsonPath("$.remotePubkey", is(PUBKEY_2.toString()))) + .andExpect(jsonPath("$.remoteAlias", is(ALIAS_2))); } } \ No newline at end of file diff --git a/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsController.java b/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsController.java index 19c219c6..3e8c845d 100644 --- a/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsController.java +++ b/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsController.java @@ -4,7 +4,9 @@ import com.codahale.metrics.MetricRegistry; import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.model.ChannelId; import de.cotto.lndmanagej.model.LocalChannel; +import de.cotto.lndmanagej.model.Pubkey; import de.cotto.lndmanagej.service.ChannelService; +import de.cotto.lndmanagej.service.NodeService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -14,10 +16,12 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/api/channel/{channelId}") public class ChannelDetailsController { private final ChannelService channelService; + private final NodeService nodeService; private final Metrics metrics; - public ChannelDetailsController(ChannelService channelService, Metrics metrics) { + public ChannelDetailsController(ChannelService channelService, NodeService nodeService, Metrics metrics) { this.channelService = channelService; + this.nodeService = nodeService; this.metrics = metrics; } @@ -28,6 +32,8 @@ public class ChannelDetailsController { if (localChannel == null) { throw new NotFoundException(); } - return new ChannelDetailsDto(localChannel.getId()); + Pubkey remotePubkey = localChannel.getRemotePubkey(); + String remoteAlias = nodeService.getAlias(remotePubkey); + return new ChannelDetailsDto(localChannel.getId(), remotePubkey, remoteAlias); } } diff --git a/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsDto.java b/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsDto.java index 596b6269..19144482 100644 --- a/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsDto.java +++ b/application/src/main/java/de/cotto/lndmanagej/controller/ChannelDetailsDto.java @@ -3,6 +3,11 @@ package de.cotto.lndmanagej.controller; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import de.cotto.lndmanagej.model.ChannelId; +import de.cotto.lndmanagej.model.Pubkey; -public record ChannelDetailsDto(@JsonSerialize(using = ToStringSerializer.class) ChannelId channelId) { +public record ChannelDetailsDto( + @JsonSerialize(using = ToStringSerializer.class) ChannelId channelId, + @JsonSerialize(using = ToStringSerializer.class) Pubkey remotePubkey, + String remoteAlias +) { } diff --git a/application/src/test/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerTest.java b/application/src/test/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerTest.java index 91df7129..00003c5a 100644 --- a/application/src/test/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerTest.java +++ b/application/src/test/java/de/cotto/lndmanagej/controller/ChannelDetailsControllerTest.java @@ -2,6 +2,7 @@ package de.cotto.lndmanagej.controller; import de.cotto.lndmanagej.metrics.Metrics; import de.cotto.lndmanagej.service.ChannelService; +import de.cotto.lndmanagej.service.NodeService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -12,6 +13,8 @@ import java.util.Optional; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL; +import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2; +import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.argThat; @@ -26,6 +29,9 @@ class ChannelDetailsControllerTest { @Mock private ChannelService channelService; + @Mock + private NodeService nodeService; + @Mock private Metrics metrics; @@ -37,9 +43,11 @@ class ChannelDetailsControllerTest { @Test void getChannelDetails() throws NotFoundException { + ChannelDetailsDto expectedDetails = new ChannelDetailsDto(CHANNEL_ID, PUBKEY_2, ALIAS_2); + when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2); when(channelService.getLocalChannel(CHANNEL_ID)).thenReturn(Optional.of(LOCAL_OPEN_CHANNEL)); - assertThat(channelDetailsController.getChannelDetails(CHANNEL_ID)) - .isEqualTo(new ChannelDetailsDto(CHANNEL_ID)); + + assertThat(channelDetailsController.getChannelDetails(CHANNEL_ID)).isEqualTo(expectedDetails); verify(metrics).mark(argThat(name -> name.endsWith(".getChannelDetails"))); } } \ No newline at end of file