• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.71
/src/js/actions/monitorActions.js
1
// Copyright 2021 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import Api, { apiUrl, headerNames } from '../api/general-api';
15
import * as DeviceConstants from '../constants/deviceConstants';
16
import * as MonitorConstants from '../constants/monitorConstants';
17
import { commonErrorFallback, commonErrorHandler, setSnackbar } from './appActions';
18
import { convertDeviceListStateToFilters, getSearchEndpoint } from './deviceActions';
19

20
export const monitorApiUrlv1 = `${apiUrl.v1}/devicemonitor`;
190✔
21

22
const { page: defaultPage, perPage: defaultPerPage } = DeviceConstants.DEVICE_LIST_DEFAULTS;
190✔
23

24
const cutoffLength = 75;
190✔
25
const ellipsis = '...';
190✔
26

27
const longTextTrimmer = text => (text.length >= cutoffLength + ellipsis.length ? `${text.substring(0, cutoffLength + ellipsis.length)}${ellipsis}` : text);
190!
28

29
const sanitizeDeviceAlerts = alerts => alerts.map(alert => ({ ...alert, fullName: alert.name, name: longTextTrimmer(alert.name) }));
190✔
30

31
export const setAlertListState = selectionState => (dispatch, getState) =>
190✔
32
  Promise.resolve(
1✔
33
    dispatch({
34
      type: MonitorConstants.SET_ALERT_LIST_STATE,
35
      value: { ...getState().monitor.alerts.alertList, ...selectionState }
36
    })
37
  );
38

39
export const getDeviceAlerts =
40
  (id, config = {}) =>
190✔
41
  dispatch => {
2✔
42
    const { page = defaultPage, perPage = defaultPerPage, issuedBefore, issuedAfter, sortAscending = false } = config;
2✔
43
    const issued_after = issuedAfter ? `&issued_after=${issuedAfter}` : '';
2!
44
    const issued_before = issuedBefore ? `&issued_before=${issuedBefore}` : '';
2!
45
    return Api.get(`${monitorApiUrlv1}/devices/${id}/alerts?page=${page}&per_page=${perPage}${issued_after}${issued_before}&sort_ascending=${sortAscending}`)
2✔
46
      .catch(err => commonErrorHandler(err, `Retrieving device alerts for device ${id} failed:`, dispatch))
×
47
      .then(res =>
48
        Promise.all([
1✔
49
          dispatch({
50
            type: MonitorConstants.RECEIVE_DEVICE_ALERTS,
51
            deviceId: id,
52
            alerts: sanitizeDeviceAlerts(res.data)
53
          }),
54
          dispatch(setAlertListState({ total: Number(res.headers[headerNames.total]) }))
55
        ])
56
      );
57
  };
58

59
export const getLatestDeviceAlerts =
60
  (id, config = {}) =>
190✔
61
  dispatch => {
2✔
62
    const { page = defaultPage, perPage = 10 } = config;
2✔
63
    return Api.get(`${monitorApiUrlv1}/devices/${id}/alerts/latest?page=${page}&per_page=${perPage}`)
2✔
64
      .catch(err => commonErrorHandler(err, `Retrieving device alerts for device ${id} failed:`, dispatch))
×
65
      .then(res =>
66
        Promise.resolve(
1✔
67
          dispatch({
68
            type: MonitorConstants.RECEIVE_LATEST_DEVICE_ALERTS,
69
            deviceId: id,
70
            alerts: sanitizeDeviceAlerts(res.data)
71
          })
72
        )
73
      );
74
  };
75

76
export const getIssueCountsByType =
77
  (type, options = {}) =>
190✔
78
  (dispatch, getState) => {
1✔
79
    const state = getState();
1✔
80
    const { filters = state.devices.filters, group, status, ...remainder } = options;
1✔
81
    const { applicableFilters: nonMonitorFilters, filterTerms } = convertDeviceListStateToFilters({
1✔
82
      ...remainder,
83
      filters,
84
      group,
85
      offlineThreshold: getState().app.offlineThreshold,
86
      selectedIssues: [type],
87
      status
88
    });
89
    return Api.post(getSearchEndpoint(state.app.features.hasReporting), {
1✔
90
      page: 1,
91
      per_page: 1,
92
      filters: filterTerms,
93
      attributes: [{ scope: 'identity', attribute: 'status' }]
94
    })
95
      .catch(err => commonErrorHandler(err, `Retrieving issue counts failed:`, dispatch, commonErrorFallback))
×
96
      .then(res => {
97
        const total = nonMonitorFilters.length ? state.monitor.issueCounts.byType[type].total : Number(res.headers[headerNames.total]);
1!
98
        const filtered = nonMonitorFilters.length ? Number(res.headers[headerNames.total]) : total;
1!
99
        if (total === state.monitor.issueCounts.byType[type].total && filtered === state.monitor.issueCounts.byType[type].filtered) {
1!
100
          return Promise.resolve();
×
101
        }
102
        return Promise.resolve(
1✔
103
          dispatch({
104
            counts: { filtered, total },
105
            issueType: type,
106
            type: MonitorConstants.RECEIVE_DEVICE_ISSUE_COUNTS
107
          })
108
        );
109
      });
110
  };
111

112
export const getDeviceMonitorConfig = id => dispatch =>
190✔
113
  Api.get(`${monitorApiUrlv1}/devices/${id}/config`)
2✔
114
    .catch(err => commonErrorHandler(err, `Retrieving device monitor config for device ${id} failed:`, dispatch))
×
115
    .then(({ data }) => {
116
      let tasks = [
1✔
117
        dispatch({
118
          type: MonitorConstants.RECEIVE_DEVICE_MONITOR_CONFIG,
119
          device: { id, monitors: data }
120
        })
121
      ];
122
      tasks.push(Promise.resolve(data));
1✔
123
      return Promise.all(tasks);
1✔
124
    });
125

126
export const changeNotificationSetting =
127
  (enabled, channel = MonitorConstants.alertChannels.email) =>
190✔
128
  dispatch => {
1✔
129
    return Api.put(`${monitorApiUrlv1}/settings/global/channel/alerts/${channel}/status`, { enabled })
1✔
130
      .catch(err => commonErrorHandler(err, `${enabled ? 'En' : 'Dis'}abling  ${channel} alerts failed:`, dispatch))
×
131
      .then(() =>
132
        Promise.all([
1✔
133
          dispatch({
134
            type: MonitorConstants.CHANGE_ALERT_CHANNEL,
135
            channel,
136
            enabled
137
          }),
138
          dispatch(setSnackbar(`Successfully ${enabled ? 'en' : 'dis'}abled ${channel} alerts`, 5000))
1!
139
        ])
140
      );
141
  };
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc