get channel IDs for channels with peer

This commit is contained in:
Carsten Otto
2021-11-11 20:14:04 +01:00
parent 6ad011696b
commit 07d9c7c5f7
12 changed files with 220 additions and 35 deletions

View File

@@ -1,6 +1,6 @@
package de.cotto.lndmanagej.controller;
import de.cotto.lndmanagej.grpc.GrpcNodeInfo;
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;
@@ -8,12 +8,17 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import java.util.List;
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS;
import static de.cotto.lndmanagej.model.NodeFixtures.NODE;
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
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 = NodeController.class)
class NodeControllerIT {
@@ -21,11 +26,11 @@ class NodeControllerIT {
private MockMvc mockMvc;
@MockBean
private GrpcNodeInfo grpcNodeInfo;
private NodeService nodeService;
@Test
void getAlias() throws Exception {
when(grpcNodeInfo.getNode(PUBKEY)).thenReturn(NODE);
when(nodeService.getAlias(PUBKEY)).thenReturn(ALIAS);
mockMvc.perform(get("/api/node/" + PUBKEY + "/alias")).andExpect(content().string(ALIAS));
}
@@ -33,4 +38,12 @@ class NodeControllerIT {
void getAlias_error() throws Exception {
mockMvc.perform(get("/api/node/xxx/alias")).andExpect(MockMvcResultMatchers.status().isBadRequest());
}
@Test
void getOpenChannelIds() throws Exception {
when(nodeService.getOpenChannelIds(PUBKEY)).thenReturn(List.of(CHANNEL_ID, CHANNEL_ID_3));
mockMvc.perform(get("/api/node/" + PUBKEY + "/open-channels"))
.andExpect(jsonPath("$[0]", is(CHANNEL_ID.shortChannelId())))
.andExpect(jsonPath("$[1]", is(CHANNEL_ID_3.shortChannelId())));
}
}