foreman_webhooks 6.0.0 → 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/db/seeds.d/62_shellhooks_proxy_feature.rb +1 -1
- 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 +2 -10
- data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/integration.test.js +125 -31
- data/webpack/ForemanWebhooks/Routes/Webhooks/__tests__/WebhooksPageSelectors.test.js +121 -16
- metadata +2 -3
- data/webpack/ForemanWebhooks/Routes/Webhooks/__tests__/__snapshots__/WebhooksPageSelectors.test.js.snap +0 -50
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
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
proxy_feature = Feature.where(name: 'Shellhooks').first_or_create
|
|
4
4
|
return unless proxy_feature.nil? || proxy_feature.errors.any?
|
|
5
5
|
|
|
6
|
-
raise "Unable to create proxy feature: #{format_errors
|
|
6
|
+
raise "Unable to create proxy feature: #{SeedHelper.format_errors(proxy_feature)}"
|
|
@@ -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
|
);
|
|
@@ -38,9 +38,10 @@ export const queryParams = {
|
|
|
38
38
|
...querySort,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
export const stateFactory = state => ({
|
|
41
|
+
export const stateFactory = (state = {}, { status } = {}) => ({
|
|
42
42
|
API: {
|
|
43
43
|
[WEBHOOKS_API_REQUEST_KEY]: {
|
|
44
|
+
...(status !== undefined && { status }),
|
|
44
45
|
response: {
|
|
45
46
|
...stateParams,
|
|
46
47
|
...state,
|
|
@@ -99,12 +100,3 @@ export const spySelector = selectors => {
|
|
|
99
100
|
selectors.selectMessage.mockImplementation(() => ({}));
|
|
100
101
|
};
|
|
101
102
|
|
|
102
|
-
export const spyEditSelector = selectors => {
|
|
103
|
-
jest.spyOn(selectors, 'selectIsLoading');
|
|
104
|
-
jest.spyOn(selectors, 'selectWebhookValues');
|
|
105
|
-
jest.spyOn(selectors, 'selectWebhookTemplateId');
|
|
106
|
-
|
|
107
|
-
selectors.selectIsLoading.mockImplementation(() => false);
|
|
108
|
-
selectors.selectWebhookValues.mockImplementation(() => ({}));
|
|
109
|
-
selectors.selectWebhookTemplateId.mockImplementation(() => 1);
|
|
110
|
-
};
|
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
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { STATUS } from 'foremanReact/constants';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
selectWebhooks,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
selectIsLoading,
|
|
12
12
|
selectSubtotal,
|
|
13
13
|
selectMessage,
|
|
14
|
+
selectCanCreate,
|
|
14
15
|
} from '../WebhooksPageSelectors';
|
|
15
16
|
|
|
16
17
|
import {
|
|
@@ -18,28 +19,132 @@ import {
|
|
|
18
19
|
webhooks,
|
|
19
20
|
} from '../WebhooksIndexPage/__tests__/WebhooksIndexPage.fixtures';
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
+
const populatedState = stateFactory({
|
|
22
23
|
results: webhooks,
|
|
23
24
|
sort: { by: 'name', order: 'DESC' },
|
|
24
25
|
page: 1,
|
|
25
26
|
perPage: 1,
|
|
26
27
|
search: 'name ~ foo',
|
|
27
28
|
subtotal: 42,
|
|
28
|
-
|
|
29
|
+
canCreate: true,
|
|
30
|
+
message: { type: 'info', text: 'Saved successfully' },
|
|
29
31
|
});
|
|
30
32
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
const resolvedState = stateFactory(
|
|
34
|
+
{ results: webhooks, subtotal: webhooks.length },
|
|
35
|
+
{ status: STATUS.RESOLVED }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const pendingState = stateFactory({ results: [] }, { status: STATUS.PENDING });
|
|
39
|
+
|
|
40
|
+
const errorState = {
|
|
41
|
+
API: {
|
|
42
|
+
webhooks: {
|
|
43
|
+
status: STATUS.ERROR,
|
|
44
|
+
response: {
|
|
45
|
+
message: 'Request failed with status code 500',
|
|
46
|
+
response: {
|
|
47
|
+
data: { error: { message: 'Unable to load webhooks' } },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
42
52
|
};
|
|
43
53
|
|
|
44
|
-
describe('WebhooksPage selectors', () =>
|
|
45
|
-
|
|
54
|
+
describe('WebhooksPage selectors', () => {
|
|
55
|
+
it('returns webhooks from the API response', () => {
|
|
56
|
+
expect(selectWebhooks(populatedState)).toEqual(webhooks);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('returns page from the API response', () => {
|
|
60
|
+
expect(selectPage(populatedState)).toBe(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('returns perPage from the API response', () => {
|
|
64
|
+
expect(selectPerPage(populatedState)).toBe(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('returns search from the API response', () => {
|
|
68
|
+
expect(selectSearch(populatedState)).toBe('name ~ foo');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('returns sort with camelCased column name', () => {
|
|
72
|
+
expect(selectSort(populatedState)).toEqual({ by: 'name', order: 'DESC' });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('camelCases snake_case sort column names', () => {
|
|
76
|
+
const state = stateFactory({
|
|
77
|
+
sort: { by: 'target_url', order: 'ASC' },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(selectSort(state)).toEqual({ by: 'targetUrl', order: 'ASC' });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('returns hasData as false when the API request is not resolved', () => {
|
|
84
|
+
expect(selectHasData(populatedState)).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns hasData as true when the API request is resolved with results', () => {
|
|
88
|
+
expect(selectHasData(resolvedState)).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('returns hasError as false for a successful API response', () => {
|
|
92
|
+
expect(selectHasError(populatedState)).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('returns hasError as true when the API request failed', () => {
|
|
96
|
+
expect(selectHasError(errorState)).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('returns isLoading as true when the API status is missing or pending', () => {
|
|
100
|
+
expect(selectIsLoading(populatedState)).toBe(true);
|
|
101
|
+
expect(selectIsLoading(pendingState)).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('returns isLoading as false when the API request is resolved', () => {
|
|
105
|
+
expect(selectIsLoading(resolvedState)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('returns subtotal from the API response', () => {
|
|
109
|
+
expect(selectSubtotal(populatedState)).toBe(42);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('returns message from the API response when there is no error', () => {
|
|
113
|
+
expect(selectMessage(populatedState)).toEqual({
|
|
114
|
+
type: 'info',
|
|
115
|
+
text: 'Saved successfully',
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('returns an error message from the API when the request failed', () => {
|
|
120
|
+
expect(selectMessage(errorState)).toEqual({
|
|
121
|
+
type: 'error',
|
|
122
|
+
text: 'Unable to load webhooks',
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('returns an empty webhook list when the API request failed', () => {
|
|
127
|
+
expect(selectWebhooks(errorState)).toEqual([]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('returns canCreate from the API response', () => {
|
|
131
|
+
expect(selectCanCreate(populatedState)).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('returns default pagination values when the API response is empty', () => {
|
|
135
|
+
const emptyState = {
|
|
136
|
+
API: {
|
|
137
|
+
webhooks: {
|
|
138
|
+
status: STATUS.RESOLVED,
|
|
139
|
+
response: {},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
expect(selectPage(emptyState)).toBe(1);
|
|
145
|
+
expect(selectPerPage(emptyState)).toBe(20);
|
|
146
|
+
expect(selectWebhooks(emptyState)).toEqual([]);
|
|
147
|
+
expect(selectSubtotal(emptyState)).toBe(0);
|
|
148
|
+
expect(selectCanCreate(emptyState)).toBe(false);
|
|
149
|
+
});
|
|
150
|
+
});
|
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:
|
|
4
|
+
version: 7.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Timo Goebel
|
|
@@ -168,7 +168,6 @@ files:
|
|
|
168
168
|
- webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageSelectors.js
|
|
169
169
|
- webpack/ForemanWebhooks/Routes/Webhooks/__tests__/WebhooksPageHelpers.test.js
|
|
170
170
|
- webpack/ForemanWebhooks/Routes/Webhooks/__tests__/WebhooksPageSelectors.test.js
|
|
171
|
-
- webpack/ForemanWebhooks/Routes/Webhooks/__tests__/__snapshots__/WebhooksPageSelectors.test.js.snap
|
|
172
171
|
- webpack/ForemanWebhooks/Routes/Webhooks/constants.js
|
|
173
172
|
- webpack/index.js
|
|
174
173
|
- webpack/routes_index.js
|
|
@@ -195,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
195
194
|
- !ruby/object:Gem::Version
|
|
196
195
|
version: '0'
|
|
197
196
|
requirements: []
|
|
198
|
-
rubygems_version: 4.0.
|
|
197
|
+
rubygems_version: 4.0.20
|
|
199
198
|
specification_version: 4
|
|
200
199
|
summary: Configure webhooks for Foreman.
|
|
201
200
|
test_files:
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`WebhooksPage selectors should return hasData 1`] = `false`;
|
|
4
|
-
|
|
5
|
-
exports[`WebhooksPage selectors should return hasError 1`] = `false`;
|
|
6
|
-
|
|
7
|
-
exports[`WebhooksPage selectors should return isLoading 1`] = `true`;
|
|
8
|
-
|
|
9
|
-
exports[`WebhooksPage selectors should return message 1`] = `
|
|
10
|
-
Object {
|
|
11
|
-
"text": "This is error",
|
|
12
|
-
"type": "error",
|
|
13
|
-
}
|
|
14
|
-
`;
|
|
15
|
-
|
|
16
|
-
exports[`WebhooksPage selectors should return page 1`] = `1`;
|
|
17
|
-
|
|
18
|
-
exports[`WebhooksPage selectors should return perPage 1`] = `1`;
|
|
19
|
-
|
|
20
|
-
exports[`WebhooksPage selectors should return search 1`] = `"name ~ foo"`;
|
|
21
|
-
|
|
22
|
-
exports[`WebhooksPage selectors should return sort 1`] = `
|
|
23
|
-
Object {
|
|
24
|
-
"by": "name",
|
|
25
|
-
"order": "DESC",
|
|
26
|
-
}
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
exports[`WebhooksPage selectors should return subtotal 1`] = `42`;
|
|
30
|
-
|
|
31
|
-
exports[`WebhooksPage selectors should return webhooks 1`] = `
|
|
32
|
-
Array [
|
|
33
|
-
Object {
|
|
34
|
-
"canDelete": true,
|
|
35
|
-
"canEdit": true,
|
|
36
|
-
"enabled": true,
|
|
37
|
-
"id": 1,
|
|
38
|
-
"name": "my-webhook",
|
|
39
|
-
"targetUrl": "https://my-machine.example.com",
|
|
40
|
-
},
|
|
41
|
-
Object {
|
|
42
|
-
"canDelete": false,
|
|
43
|
-
"canEdit": false,
|
|
44
|
-
"enabled": false,
|
|
45
|
-
"id": 2,
|
|
46
|
-
"name": "your-webhook",
|
|
47
|
-
"targetUrl": "https://your-machine.example.com",
|
|
48
|
-
},
|
|
49
|
-
]
|
|
50
|
-
`;
|