Skip to content

Commit

Permalink
Merge pull request #4456 from mzedel/men-7334
Browse files Browse the repository at this point in the history
MEN-7334 - fix: fixed an issue that would prevent promoting a device to a gateway device
  • Loading branch information
mzedel committed Jun 18, 2024
2 parents 0e6c9a0 + 13b7ecf commit afa8002
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ exports[`CreateGroupExplainerContent Component renders correctly 1`] = `
tabindex="-1"
>
<div
aria-labelledby=":r0:"
aria-labelledby=":r3:"
class="MuiPaper-root MuiPaper-elevation MuiPaper-rounded MuiPaper-elevation24 MuiDialog-paper MuiDialog-paperScrollPaper MuiDialog-paperWidthMd MuiDialog-paperFullWidth emotion-3"
role="dialog"
>
<h2
class="MuiTypography-root MuiTypography-h6 MuiDialogTitle-root emotion-4"
id=":r0:"
id=":r3:"
>
Promoting a device to a gateway
</h2>
Expand Down Expand Up @@ -464,7 +464,7 @@ exports[`CreateGroupExplainerContent Component renders correctly 1`] = `
<span
style="white-space: pre-wrap; word-break: break-word;"
>
JWT_TOKEN='eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjZTNkMGY4Yy1hZWRlLTQwMzAtYjM5MS03ZDUwMjBlYjg3M2UiLCJzdWIiOiJhMzBhNzgwYi1iODQzLTUzNDQtODBlMy0wZmQ5NWE0ZjZmYzMiLCJleHAiOjE2MDY4MTUzNjksImlhdCI6MTYwNjIxMDU2OSwibWVuZGVyLnRlbmFudCI6IjVmODVjMTdiY2U2MmI3ZmE3ZjVmNzA0MCIsIm1lbmRlci51c2VyIjp0cnVlLCJpc3MiOiJNZW5kZXIgVXNlcnMiLCJzY3AiOiJtZW5kZXIuKiIsIm1lbmRlci5wbGFuIjoicHJvZmVzc2lvbmFsIiwibmJmIjoxNjA2MjEwNTY5fQ.qVgYdCzLTf8OdK9uUctqqaY_HWkIiwpekuGvuGQAXCEgOv4bRNDlZRN_ZRSbxQoARG3pquhScbQrjBV9tcF4irTUPlTn3yrsXNO17DpcbTVeKRkb88RDtIKiRw3orVZ_GlIb-ckTQ5dS-Nqlyyf3Fmrhca-gwt6m_xv2UrmJK6eYYTMfggdRRWb-4u7mEkBI_pHPMTQrT8kJ2BeX-vHgazH9AoH0k85LHtFZQXD7pXHlDZRnLxJXukncwMGDmF17374gavYAIyDIzcC8sEBMDnVXgpikeA1sauzirqix6mAVs6XmxdQO7aF0wfXO1_PTYUA3Nk1oQfMYNlEI3U9uLRJRZIq2L8fmrrBryhstKd4y0KlBbGAQrx8NtRkgajjd1ljMfPBUEZrb7uSerVjneiO-aIBO76CuH0zdklphIjpGJeogkBhe8pAYNggp1XsZHgpZfl7IE5faKaDkMGnutaea--Czor6bhqUNCuY4tR0cpQJbNwy6LS9o1CFy4Log'
JWT_TOKEN='veryTest'
wget -O- https://get.mender.io | sudo bash -s -- --jwt-token $JWT_TOKEN mender-gateway --demo
</span>
Expand Down
9 changes: 5 additions & 4 deletions src/js/components/devices/dialogs/make-gateway-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import React from 'react';
// material ui
import { Button, Dialog, DialogActions, DialogContent, DialogTitle } from '@mui/material';

import { getToken } from '../../../auth';
import CopyCode from '../../common/copy-code';
import DocsLink from '../../common/docslink';

export const getCode = (isPreRelease, token) => {
export const getCode = isPreRelease => {
const { target, flags } = isPreRelease
? { target: 'https://get.mender.io/staging', flags: ' -c --experimental' }
: { target: 'https://get.mender.io', flags: '' };
return `JWT_TOKEN='${token}'
return `JWT_TOKEN='${getToken()}'
wget -O- ${target} | sudo bash -s -- --jwt-token $JWT_TOKEN mender-gateway --demo${flags}`;
};

export const MakeGatewayDialog = ({ isPreRelease, onCancel, token }) => (
export const MakeGatewayDialog = ({ isPreRelease, onCancel }) => (
<Dialog open fullWidth maxWidth="md">
<DialogTitle>Promoting a device to a gateway</DialogTitle>
<DialogContent className="onboard-dialog dialog-content">
Expand All @@ -37,7 +38,7 @@ export const MakeGatewayDialog = ({ isPreRelease, onCancel, token }) => (
On the device terminal, run the following command. You can use <DocsLink path="add-ons/remote-terminal" title="Remote Terminal" /> if mender-connect is
enabled on the device.
</p>
<CopyCode code={getCode(isPreRelease, token)} withDescription />
<CopyCode code={getCode(isPreRelease)} withDescription />
<p>
Note: this is only intended for demo or testing purposes. For production installation please refer to the{' '}
<DocsLink path="get-started/mender-gateway" title="full Mender Gateway documentation" />
Expand Down
9 changes: 7 additions & 2 deletions src/js/components/devices/dialogs/make-gateway-dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
// limitations under the License.
import React from 'react';

import { token, undefineds } from '../../../../../tests/mockData';
import { screen } from '@testing-library/react';

import { undefineds } from '../../../../../tests/mockData';
import { render } from '../../../../../tests/setupTests';
import MakeGatewayDialog from './make-gateway-dialog';

describe('CreateGroupExplainerContent Component', () => {
it('renders correctly', async () => {
const { baseElement } = render(<MakeGatewayDialog onCancel={jest.fn} token={token} />);
window.localStorage.getItem.mockImplementation(name => (name === 'JWT' ? JSON.stringify({ token: 'veryTest' }) : undefined));
const { baseElement } = render(<MakeGatewayDialog onCancel={jest.fn} />);
const view = baseElement.getElementsByClassName('MuiDialog-root')[0];
expect(view).toMatchSnapshot();
expect(view).toEqual(expect.not.stringMatching(undefineds));
expect(screen.getByText(/veryTest/)).toBeInTheDocument();
window.localStorage.getItem.mockReset();
});
});

0 comments on commit afa8002

Please sign in to comment.