foreman_webhooks 6.0.1 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/foreman_webhooks/engine.rb +1 -1
- data/lib/foreman_webhooks/version.rb +1 -1
- data/package.json +0 -12
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/__tests__/actionCellFormatter.test.js +5 -19
- data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookTable/Components/Formatters/actionCellFormatter.js +1 -2
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookCreateModal.js +1 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookDeleteModal.js +1 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModal.js +1 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookTestModal.js +2 -7
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/WebhooksIndexPage.fixtures.js +0 -9
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/integration.test.js +125 -31
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3736b6b94dcf1e4b0b6fc6740f2013ae6db9844283b552bc6ac377207a4a1710
|
|
4
|
+
data.tar.gz: 893d4a5c19140ba592fd133775cf8a5d50aa6788f97710f9d13b955486b82835
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6fb7905519c9fc2f88ba654a37df8790d9e515677acbdab39fde0e5a36abc0fa2f7ba55ef53bdf9002c4de9fff889b2fa01e0d4d48f4d3e15c4ddff2edf20360
|
|
7
|
+
data.tar.gz: 6289f1f2d3eccb7c8052fdfff09305931b7553ab8b20369d4556d43b9c8c91c196bf148660e006aaad2ba922365aecaae03c8002c997564e8a30f17ffd4045e8
|
|
@@ -14,7 +14,7 @@ module ForemanWebhooks
|
|
|
14
14
|
initializer 'foreman_webhooks.register_plugin', before: :finisher_hook do |app|
|
|
15
15
|
app.reloader.to_prepare do
|
|
16
16
|
Foreman::Plugin.register :foreman_webhooks do
|
|
17
|
-
requires_foreman '>= 5.
|
|
17
|
+
requires_foreman '>= 5.1'
|
|
18
18
|
register_gettext
|
|
19
19
|
|
|
20
20
|
apipie_documented_controllers ["#{ForemanWebhooks::Engine.root}/app/controllers/api/v2/*.rb"]
|
data/package.json
CHANGED
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
"description": "This plugins allows to configure Webhooks for Foreman.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"lint": "tfm-lint --plugin -d /webpack",
|
|
8
|
-
"test": "tfm-test --plugin",
|
|
9
|
-
"test:watch": "tfm-test --plugin --watchAll",
|
|
10
|
-
"test:current": "tfm-test --plugin --watch",
|
|
11
|
-
"publish-coverage": "tfm-publish-coverage",
|
|
12
7
|
"create-react-component": "yo react-domain"
|
|
13
8
|
},
|
|
14
9
|
"repository": {
|
|
@@ -18,15 +13,8 @@
|
|
|
18
13
|
"bugs": {
|
|
19
14
|
"url": "https://projects.theforeman.org/projects/webhooks/issues"
|
|
20
15
|
},
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"@theforeman/vendor": "^8.15.0"
|
|
23
|
-
},
|
|
24
16
|
"devDependencies": {
|
|
25
17
|
"@babel/core": "^7.7.0",
|
|
26
|
-
"@theforeman/builder": ">= 0",
|
|
27
|
-
"@theforeman/test": ">= 0",
|
|
28
|
-
"@theforeman/vendor-dev": ">= 0",
|
|
29
|
-
"@theforeman/eslint-plugin-foreman": ">= 0",
|
|
30
18
|
"babel-eslint": "^10.0.0",
|
|
31
19
|
"eslint": "^6.8.0",
|
|
32
20
|
"eslint-plugin-spellcheck": "^0.0.17",
|
|
@@ -4,18 +4,6 @@ import '@testing-library/jest-dom';
|
|
|
4
4
|
|
|
5
5
|
import actionCellFormatter from '../actionCellFormatter';
|
|
6
6
|
|
|
7
|
-
jest.mock(
|
|
8
|
-
'foremanReact/components/common/table',
|
|
9
|
-
() => ({
|
|
10
|
-
cellFormatter: content => (
|
|
11
|
-
<div data-testid="cell-formatter-mock">
|
|
12
|
-
{content === false ? null : content}
|
|
13
|
-
</div>
|
|
14
|
-
),
|
|
15
|
-
}),
|
|
16
|
-
{ virtual: true }
|
|
17
|
-
);
|
|
18
|
-
|
|
19
7
|
jest.mock('../../ActionButtons/ActionButton', () => {
|
|
20
8
|
// eslint-disable-next-line global-require
|
|
21
9
|
const PropTypes = require('prop-types');
|
|
@@ -50,13 +38,12 @@ describe('actionCellFormatter', () => {
|
|
|
50
38
|
jest.clearAllMocks();
|
|
51
39
|
});
|
|
52
40
|
|
|
53
|
-
it('
|
|
41
|
+
it('renders the action control when rowData is present and the row is editable', () => {
|
|
54
42
|
const formatter = actionCellFormatter(webhookActions);
|
|
55
43
|
const row = { id: 10, name: 'Wh', can_edit: true, can_delete: true };
|
|
56
44
|
|
|
57
45
|
render(formatter(null, { rowData: row }));
|
|
58
46
|
|
|
59
|
-
expect(screen.getByTestId('cell-formatter-mock')).toBeInTheDocument();
|
|
60
47
|
const action = screen.getByTestId('action-button');
|
|
61
48
|
expect(action).toHaveAttribute('data-id', '10');
|
|
62
49
|
expect(action).toHaveAttribute('data-name', 'Wh');
|
|
@@ -75,23 +62,22 @@ describe('actionCellFormatter', () => {
|
|
|
75
62
|
);
|
|
76
63
|
});
|
|
77
64
|
|
|
78
|
-
it('renders
|
|
65
|
+
it('renders nothing when rowData is present but the row is not editable', () => {
|
|
79
66
|
const formatter = actionCellFormatter(webhookActions);
|
|
80
67
|
const row = { id: 5, name: 'B', can_edit: false };
|
|
81
68
|
|
|
82
|
-
render(formatter(null, { rowData: row }));
|
|
69
|
+
const { container } = render(formatter(null, { rowData: row }));
|
|
83
70
|
|
|
84
|
-
expect(
|
|
71
|
+
expect(container).toBeEmptyDOMElement();
|
|
85
72
|
expect(screen.queryByTestId('action-button')).not.toBeInTheDocument();
|
|
86
73
|
});
|
|
87
74
|
|
|
88
|
-
it('returns the action control
|
|
75
|
+
it('returns the action control when rowData is omitted', () => {
|
|
89
76
|
const formatter = actionCellFormatter(webhookActions);
|
|
90
77
|
const row = { id: 20, name: 'Direct', can_edit: true, canDelete: true };
|
|
91
78
|
|
|
92
79
|
render(formatter(row));
|
|
93
80
|
|
|
94
|
-
expect(screen.queryByTestId('cell-formatter-mock')).not.toBeInTheDocument();
|
|
95
81
|
expect(screen.getByTestId('action-button')).toHaveAttribute(
|
|
96
82
|
'data-id',
|
|
97
83
|
'20'
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { cellFormatter } from 'foremanReact/components/common/table';
|
|
3
2
|
import { ActionButton } from '../ActionButtons/ActionButton';
|
|
4
3
|
|
|
5
4
|
const actionCellFormatter = webhookActions => (value, extra) => {
|
|
@@ -17,7 +16,7 @@ const actionCellFormatter = webhookActions => (value, extra) => {
|
|
|
17
16
|
/>
|
|
18
17
|
);
|
|
19
18
|
|
|
20
|
-
return
|
|
19
|
+
return content;
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
export default actionCellFormatter;
|
data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookCreateModal.js
CHANGED
|
@@ -46,9 +46,7 @@ const WebhookCreateModal = ({ onSuccess, onCancel, isOpen }) => {
|
|
|
46
46
|
onSuccess();
|
|
47
47
|
},
|
|
48
48
|
handleError: () => setIsSubmitting(false),
|
|
49
|
-
errorToast:
|
|
50
|
-
// eslint-disable-next-line camelcase
|
|
51
|
-
response?.data?.error?.full_messages?.[0] || response,
|
|
49
|
+
errorToast: true,
|
|
52
50
|
})
|
|
53
51
|
);
|
|
54
52
|
};
|
data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookDeleteModal.js
CHANGED
|
@@ -23,9 +23,7 @@ const WebhookDeleteModal = ({ toDelete, onSuccess, modalState }) => {
|
|
|
23
23
|
key: WEBHOOK_DELETE_MODAL_ID,
|
|
24
24
|
successToast: () =>
|
|
25
25
|
sprintf(__('Webhook %s was successfully deleted'), name),
|
|
26
|
-
errorToast:
|
|
27
|
-
// eslint-disable-next-line camelcase
|
|
28
|
-
response?.response?.data?.error?.full_messages?.[0] || response,
|
|
26
|
+
errorToast: true,
|
|
29
27
|
handleSuccess: () => {
|
|
30
28
|
setIsSubmitting(false);
|
|
31
29
|
onSuccess();
|
data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModal.js
CHANGED
|
@@ -73,9 +73,7 @@ const WebhookEditModal = ({ toEdit, onSuccess, modalState }) => {
|
|
|
73
73
|
onSuccess();
|
|
74
74
|
},
|
|
75
75
|
handleError: () => setIsSubmitting(false),
|
|
76
|
-
errorToast:
|
|
77
|
-
// eslint-disable-next-line camelcase
|
|
78
|
-
response?.data?.error?.full_messages?.[0] || response,
|
|
76
|
+
errorToast: true,
|
|
79
77
|
})
|
|
80
78
|
);
|
|
81
79
|
};
|
data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookTestModal.js
CHANGED
|
@@ -31,12 +31,6 @@ const WebhookTestModal = ({ toTest, modalState }) => {
|
|
|
31
31
|
|
|
32
32
|
const [value, setValue] = useState(initialTestValues);
|
|
33
33
|
|
|
34
|
-
const errorToast = error =>
|
|
35
|
-
sprintf(
|
|
36
|
-
__('Webhook test failed: %s'),
|
|
37
|
-
error?.response?.data?.error?.message
|
|
38
|
-
);
|
|
39
|
-
|
|
40
34
|
const handleSubmit = values => {
|
|
41
35
|
dispatch(
|
|
42
36
|
APIActions.post({
|
|
@@ -47,7 +41,8 @@ const WebhookTestModal = ({ toTest, modalState }) => {
|
|
|
47
41
|
controller: 'webhooks',
|
|
48
42
|
},
|
|
49
43
|
successToast: () => sprintf(__('Webhook %s test was successful'), name),
|
|
50
|
-
errorToast:
|
|
44
|
+
errorToast: (_error, parsedMessage) =>
|
|
45
|
+
sprintf(__('Webhook test failed: %s'), parsedMessage),
|
|
51
46
|
handleSuccess: () => modalState.closeModal(),
|
|
52
47
|
})
|
|
53
48
|
);
|
|
@@ -100,12 +100,3 @@ export const spySelector = selectors => {
|
|
|
100
100
|
selectors.selectMessage.mockImplementation(() => ({}));
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
export const spyEditSelector = selectors => {
|
|
104
|
-
jest.spyOn(selectors, 'selectIsLoading');
|
|
105
|
-
jest.spyOn(selectors, 'selectWebhookValues');
|
|
106
|
-
jest.spyOn(selectors, 'selectWebhookTemplateId');
|
|
107
|
-
|
|
108
|
-
selectors.selectIsLoading.mockImplementation(() => false);
|
|
109
|
-
selectors.selectWebhookValues.mockImplementation(() => ({}));
|
|
110
|
-
selectors.selectWebhookTemplateId.mockImplementation(() => 1);
|
|
111
|
-
};
|
data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/integration.test.js
CHANGED
|
@@ -1,38 +1,132 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from 'foremanReact/redux/API';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
import { screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { MemoryRouter } from 'react-router-dom';
|
|
5
|
+
import '@testing-library/jest-dom';
|
|
6
|
+
|
|
7
|
+
import { rtlHelpers } from 'foremanReact/common/rtlTestHelpers';
|
|
8
|
+
import { API } from 'foremanReact/redux/API';
|
|
9
|
+
|
|
10
|
+
jest.mock('foremanReact/redux/API/API');
|
|
11
|
+
|
|
12
|
+
import WebhooksIndexPage from '../WebhooksIndexPage';
|
|
13
|
+
import { WEBHOOKS_API_PLAIN_PATH } from '../../constants';
|
|
14
|
+
|
|
15
|
+
const { renderWithStoreAndI18n } = rtlHelpers;
|
|
16
|
+
|
|
17
|
+
const webhooksApiResponse = {
|
|
18
|
+
data: {
|
|
19
|
+
results: [
|
|
20
|
+
{
|
|
21
|
+
id: 1,
|
|
22
|
+
name: 'my-webhook',
|
|
23
|
+
target_url: 'https://my-machine.example.com',
|
|
24
|
+
can_edit: true,
|
|
25
|
+
can_delete: true,
|
|
26
|
+
enabled: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 2,
|
|
30
|
+
name: 'your-webhook',
|
|
31
|
+
target_url: 'https://your-machine.example.com',
|
|
32
|
+
can_edit: false,
|
|
33
|
+
can_delete: false,
|
|
34
|
+
enabled: false,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
page: 1,
|
|
38
|
+
per_page: 20,
|
|
39
|
+
subtotal: 2,
|
|
40
|
+
total: 2,
|
|
41
|
+
search: '',
|
|
42
|
+
can_create: true,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const webhookTemplatesApiResponse = {
|
|
47
|
+
data: {
|
|
48
|
+
results: [{ id: 1, name: 'Default webhook template' }],
|
|
49
|
+
subtotal: 1,
|
|
50
|
+
page: 1,
|
|
51
|
+
per_page: 20,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const webhookEventsApiResponse = {
|
|
56
|
+
data: ['host_created', 'host_updated'],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const mockIndexApiGet = () => {
|
|
60
|
+
API.get.mockImplementation(url => {
|
|
61
|
+
const path = typeof url === 'string' ? url : '';
|
|
62
|
+
|
|
63
|
+
if (path.includes('/events')) {
|
|
64
|
+
return Promise.resolve(webhookEventsApiResponse);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (path.includes('webhook_templates')) {
|
|
68
|
+
return Promise.resolve(webhookTemplatesApiResponse);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (path.includes(WEBHOOKS_API_PLAIN_PATH) && !path.includes('/events')) {
|
|
72
|
+
return Promise.resolve(webhooksApiResponse);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return Promise.resolve({ data: { results: [], total: 0, subtotal: 0 } });
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const renderPage = () =>
|
|
80
|
+
renderWithStoreAndI18n(
|
|
81
|
+
<MemoryRouter initialEntries={['/webhooks']}>
|
|
82
|
+
<WebhooksIndexPage />
|
|
83
|
+
</MemoryRouter>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
describe('WebhooksIndexPage integration', () => {
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
mockIndexApiGet();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
afterEach(() => {
|
|
92
|
+
jest.clearAllMocks();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('renders the webhooks table after the index API loads', async () => {
|
|
96
|
+
renderPage();
|
|
97
|
+
|
|
98
|
+
expect(
|
|
99
|
+
await screen.findByRole('heading', { name: 'Webhooks' })
|
|
100
|
+
).toBeInTheDocument();
|
|
101
|
+
expect(await screen.findByRole('grid')).toBeInTheDocument();
|
|
102
|
+
expect(screen.getByRole('columnheader', { name: 'Name' })).toBeInTheDocument();
|
|
103
|
+
expect(
|
|
104
|
+
screen.getByRole('columnheader', { name: 'Target URL' })
|
|
105
|
+
).toBeInTheDocument();
|
|
106
|
+
expect(await screen.findByText('my-webhook')).toBeInTheDocument();
|
|
107
|
+
expect(screen.getByText('your-webhook')).toBeInTheDocument();
|
|
108
|
+
expect(API.get).toHaveBeenCalledWith(
|
|
109
|
+
expect.stringContaining(WEBHOOKS_API_PLAIN_PATH),
|
|
110
|
+
expect.anything(),
|
|
111
|
+
expect.anything()
|
|
27
112
|
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('opens the create webhook modal from the toolbar', async () => {
|
|
116
|
+
renderPage();
|
|
117
|
+
|
|
118
|
+
await screen.findByText('my-webhook');
|
|
119
|
+
|
|
120
|
+
expect(
|
|
121
|
+
screen.queryByRole('dialog', { name: 'Create Webhook' })
|
|
122
|
+
).not.toBeInTheDocument();
|
|
28
123
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<ConnectedWebhooksIndexPage history={history} />
|
|
32
|
-
</Router>
|
|
124
|
+
await userEvent.click(
|
|
125
|
+
await screen.findByRole('button', { name: 'Create new' })
|
|
33
126
|
);
|
|
34
127
|
|
|
35
|
-
expect(
|
|
36
|
-
|
|
128
|
+
expect(
|
|
129
|
+
screen.getByRole('dialog', { name: 'Create Webhook' })
|
|
130
|
+
).toBeInTheDocument();
|
|
37
131
|
});
|
|
38
132
|
});
|