Browse Source

fix: custom eclair nodes are not added to a new network

master
jamaljsr 5 years ago
parent
commit
e53364ea51
  1. 2
      src/components/nodeImages/CustomImagesTable.spec.tsx
  2. 4
      src/components/nodeImages/NodeImagesView.spec.tsx
  3. 5
      src/store/models/network.spec.ts
  4. 8
      src/utils/network.ts
  5. 7
      src/utils/tests/helpers.ts

2
src/components/nodeImages/CustomImagesTable.spec.tsx

@ -106,7 +106,7 @@ describe('CustomImagesTable Component', () => {
expect(
await findByText(`The custom image '${name}' has been removed`),
).toBeInTheDocument();
expect(store.getState().app.settings.nodeImages.custom.length).toBe(1);
expect(store.getState().app.settings.nodeImages.custom.length).toBe(2);
});
it('should display an error if removing a custom node fails', async () => {

4
src/components/nodeImages/NodeImagesView.spec.tsx

@ -96,14 +96,14 @@ describe('NodeImagesView Component', () => {
it('should add a new Custom Image', async () => {
const { getByText, getByLabelText, findByText, store } = renderComponent();
expect(store.getState().app.settings.nodeImages.custom).toHaveLength(2);
expect(store.getState().app.settings.nodeImages.custom).toHaveLength(3);
fireEvent.click(getByText('Add a Custom Node'));
expect(await findByText('Custom Node Details')).toBeInTheDocument();
fireEvent.change(getByLabelText('Name'), { target: { value: 'My Image' } });
fireEvent.change(getByLabelText('Docker Image'), { target: { value: 'test-image' } });
fireEvent.click(getByText('Save'));
await waitForElementToBeRemoved(() => getByText('Custom Node Details'));
expect(store.getState().app.settings.nodeImages.custom).toHaveLength(3);
expect(store.getState().app.settings.nodeImages.custom).toHaveLength(4);
// confirm the new image was added at the start of the list
expect(store.getState().app.settings.nodeImages.custom[0].name).toBe('My Image');
});

5
src/store/models/network.spec.ts

@ -161,7 +161,7 @@ describe('Network model', () => {
const custom: CustomImage[] = [
...testCustomImages,
{
id: '789',
id: '012',
name: 'Another Custom Image',
implementation: 'bitcoind',
dockerImage: 'my-bitcoind:latest',
@ -180,7 +180,8 @@ describe('Network model', () => {
customNodes: {
'123': 1, // LND
'456': 1, // c-lightning
'789': 1, // bitcoind
'789': 1, // Eclair
'012': 1, // bitcoind
'999': 1, // invalid
},
};

8
src/utils/network.ts

@ -316,16 +316,16 @@ export const createNetwork = (config: {
// add custom lightning nodes
customImages
.filter(
i => i.image.implementation === 'LND' || i.image.implementation === 'c-lightning',
)
.filter(i => ['LND', 'c-lightning', 'eclair'].includes(i.image.implementation))
.forEach(({ image, count }) => {
const { latest, compatibility } = repoState.images.LND;
const docker = { image: image.dockerImage, command: image.command };
const createFunc =
image.implementation === 'LND'
? createLndNetworkNode
: createCLightningNetworkNode;
: image.implementation === 'c-lightning'
? createCLightningNetworkNode
: createEclairNetworkNode;
range(count).forEach(() => {
lightning.push(createFunc(network, latest, compatibility, docker, status));
});

7
src/utils/tests/helpers.ts

@ -39,6 +39,13 @@ export const testCustomImages: CustomImage[] = [
dockerImage: 'my-clightning:latest',
command: 'another-command',
},
{
id: '789',
name: 'One More Custom Image',
implementation: 'eclair',
dockerImage: 'my-eclair:latest',
command: 'another-command',
},
];
export const getNetwork = (networkId = 1, name?: string, status?: Status): Network =>

Loading…
Cancel
Save