add /status/open-channels/pubkeys endpoint

This commit is contained in:
Carsten Otto
2021-11-25 19:42:16 +01:00
parent fbdfe5a893
commit 1e101b130b
5 changed files with 102 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package de.cotto.lndmanagej.controller;
import de.cotto.lndmanagej.metrics.Metrics;
import de.cotto.lndmanagej.service.ChannelService;
import de.cotto.lndmanagej.service.OwnNodeService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -8,9 +9,16 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import java.util.List;
import java.util.Set;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL;
import static de.cotto.lndmanagej.model.LocalOpenChannelFixtures.LOCAL_OPEN_CHANNEL_TO_NODE_3;
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;
@WebMvcTest(controllers = StatusController.class)
class StatusControllerIT {
@@ -19,6 +27,9 @@ class StatusControllerIT {
@Autowired
private MockMvc mockMvc;
@MockBean
private ChannelService channelService;
@MockBean
@SuppressWarnings("unused")
private Metrics metrics;
@@ -32,4 +43,15 @@ class StatusControllerIT {
mockMvc.perform(get(PREFIX + "/synced-to-chain"))
.andExpect(content().string("true"));
}
@Test
void getPubkeysForOpenChannels() throws Exception {
when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_OPEN_CHANNEL_TO_NODE_3, LOCAL_OPEN_CHANNEL));
List<String> sortedPubkeys = List.of(
LOCAL_OPEN_CHANNEL.getRemotePubkey().toString(),
LOCAL_OPEN_CHANNEL_TO_NODE_3.getRemotePubkey().toString()
);
mockMvc.perform(get(PREFIX + "/open-channels/pubkeys"))
.andExpect(jsonPath("$.pubkeys", is(sortedPubkeys)));
}
}