diff --git a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java index 96cf072d..d7bb5588 100644 --- a/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java +++ b/web/src/integrationTest/java/de/cotto/lndmanagej/controller/NodeControllerIT.java @@ -106,6 +106,15 @@ class NodeControllerIT { .andExpect(jsonPath("$.channels", is(channelIds))); } + @Test + void getAllChannelIds() throws Exception { + when(channelService.getAllChannelsWith(PUBKEY_2)).thenReturn(Set.of(LOCAL_OPEN_CHANNEL, CLOSED_CHANNEL_3)); + List channelIds = List.of(CHANNEL_ID.toString(), CHANNEL_ID_3.toString()); + mockMvc.perform(get(NODE_PREFIX + "/all-channels")) + .andExpect(jsonPath("$.node", is(PUBKEY_2.toString()))) + .andExpect(jsonPath("$.channels", is(channelIds))); + } + @Test void getBalance() throws Exception { when(balanceService.getBalanceInformation(PUBKEY_2)).thenReturn(BALANCE_INFORMATION); diff --git a/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java b/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java index 89dff6bd..b48ef3e4 100644 --- a/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java +++ b/web/src/main/java/de/cotto/lndmanagej/controller/NodeController.java @@ -84,6 +84,13 @@ public class NodeController { return new ChannelsForNodeDto(pubkey, channels); } + @GetMapping("/all-channels") + public ChannelsForNodeDto getAllChannelIdsForPubkey(@PathVariable Pubkey pubkey) { + mark("getAllChannelIdsForPubkey"); + List channels = toSortedList(channelService.getAllChannelsWith(pubkey)); + return new ChannelsForNodeDto(pubkey, channels); + } + @GetMapping("/balance") public BalanceInformationDto getBalance(@PathVariable Pubkey pubkey) { mark("getBalance"); diff --git a/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java b/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java index a9bb59da..b10a594b 100644 --- a/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java +++ b/web/src/test/java/de/cotto/lndmanagej/controller/NodeControllerTest.java @@ -141,6 +141,21 @@ class NodeControllerTest { .isEqualTo(new ChannelsForNodeDto(PUBKEY, List.of(CHANNEL_ID, CHANNEL_ID_2))); } + @Test + void getAllChannelIds() { + when(channelService.getAllChannelsWith(PUBKEY)).thenReturn(Set.of(LOCAL_OPEN_CHANNEL, CLOSED_CHANNEL_3)); + assertThat(nodeController.getAllChannelIdsForPubkey(PUBKEY)) + .isEqualTo(new ChannelsForNodeDto(PUBKEY, List.of(CHANNEL_ID, CHANNEL_ID_3))); + verify(metrics).mark(argThat(name -> name.endsWith(".getAllChannelIdsForPubkey"))); + } + + @Test + void getAllChannelIds_ordered() { + when(channelService.getAllChannelsWith(PUBKEY)).thenReturn(Set.of(CLOSED_CHANNEL_2, LOCAL_OPEN_CHANNEL)); + assertThat(nodeController.getAllChannelIdsForPubkey(PUBKEY)) + .isEqualTo(new ChannelsForNodeDto(PUBKEY, List.of(CHANNEL_ID, CHANNEL_ID_2))); + } + @Test void getBalance() { when(balanceService.getBalanceInformation(PUBKEY)).thenReturn(BALANCE_INFORMATION);