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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2504e406a10a1be7d18fe058224497d23d5888a67c73c3a37a79a3c60d14b91d
4
- data.tar.gz: f558a5e1d7f670ba489dea28d371c7ddd71a604131ffe0b50206286899794e5c
3
+ metadata.gz: 3736b6b94dcf1e4b0b6fc6740f2013ae6db9844283b552bc6ac377207a4a1710
4
+ data.tar.gz: 893d4a5c19140ba592fd133775cf8a5d50aa6788f97710f9d13b955486b82835
5
5
  SHA512:
6
- metadata.gz: 3c31f081144dad2899b5b54f9eb6dd7fc04a8314ba684b82925856771d80449872c859e399015c5daaa542d0a743cbe44741d11251b8d1318f1fbed034140453
7
- data.tar.gz: a18a91b96ddf51b0989c85fe74a9285c0e4a341253bcdc88ea152bbef3e8cce500dfc5c00f62d8b3fe9765f3e4e4464d59339b939df183d78d7ca418f355485f
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.0'
17
+ requires_foreman '>= 5.1'
18
18
  register_gettext
19
19
 
20
20
  apipie_documented_controllers ["#{ForemanWebhooks::Engine.root}/app/controllers/api/v2/*.rb"]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanWebhooks
4
- VERSION = '6.0.1'
4
+ VERSION = '7.0.0'
5
5
  end
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('wraps the action control in cellFormatter when rowData is present and the row is editable', () => {
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 falsy content through cellFormatter when rowData is present but the row is not editable', () => {
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(screen.getByTestId('cell-formatter-mock')).toBeInTheDocument();
71
+ expect(container).toBeEmptyDOMElement();
85
72
  expect(screen.queryByTestId('action-button')).not.toBeInTheDocument();
86
73
  });
87
74
 
88
- it('returns the action control without cellFormatter when rowData is omitted', () => {
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 extra?.rowData != null ? cellFormatter(content) : content;
19
+ return content;
21
20
  };
22
21
 
23
22
  export default actionCellFormatter;
@@ -46,9 +46,7 @@ const WebhookCreateModal = ({ onSuccess, onCancel, isOpen }) => {
46
46
  onSuccess();
47
47
  },
48
48
  handleError: () => setIsSubmitting(false),
49
- errorToast: ({ response }) =>
50
- // eslint-disable-next-line camelcase
51
- response?.data?.error?.full_messages?.[0] || response,
49
+ errorToast: true,
52
50
  })
53
51
  );
54
52
  };
@@ -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: response =>
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();
@@ -73,9 +73,7 @@ const WebhookEditModal = ({ toEdit, onSuccess, modalState }) => {
73
73
  onSuccess();
74
74
  },
75
75
  handleError: () => setIsSubmitting(false),
76
- errorToast: ({ response }) =>
77
- // eslint-disable-next-line camelcase
78
- response?.data?.error?.full_messages?.[0] || response,
76
+ errorToast: true,
79
77
  })
80
78
  );
81
79
  };
@@ -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: error => errorToast(error),
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
- };
@@ -1,38 +1,132 @@
1
1
  import React from 'react';
2
- import { IntegrationTestHelper } from '@theforeman/test';
3
- import { Router } from 'react-router-dom';
4
- import { createMemoryHistory } from 'history';
5
- import {
6
- reducers as foremanApiReducers,
7
- APIMiddleware,
8
- } from 'foremanReact/redux/API';
9
-
10
- import ConnectedWebhooksIndexPage from '../WebhooksIndexPage';
11
-
12
- import * as selectors from '../../WebhooksPageSelectors';
13
- import * as editSelectors from '../Components/WebhookEditModalSelectors';
14
- import { spySelector, spyEditSelector } from './WebhooksIndexPage.fixtures';
15
-
16
- spySelector(selectors);
17
- spyEditSelector(editSelectors);
18
-
19
- describe('WebhooksIndexPage - Integration Test', () => {
20
- it('should flow', () => {
21
- const history = createMemoryHistory();
22
- history.push({ pathname: '/webhooks', search: '' });
23
-
24
- const integrationTestHelper = new IntegrationTestHelper(
25
- foremanApiReducers,
26
- [APIMiddleware]
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
- const component = integrationTestHelper.mount(
30
- <Router history={history}>
31
- <ConnectedWebhooksIndexPage history={history} />
32
- </Router>
124
+ await userEvent.click(
125
+ await screen.findByRole('button', { name: 'Create new' })
33
126
  );
34
127
 
35
- expect(component.find('table[role="grid"]').exists()).toEqual(true);
36
- expect(component.exists('WebhookCreateModal')).toEqual(true);
128
+ expect(
129
+ screen.getByRole('dialog', { name: 'Create Webhook' })
130
+ ).toBeInTheDocument();
37
131
  });
38
132
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timo Goebel